RSS Feed

Add a Little Safety to your Elixir Structs with TypedStruct

I’m working on an Elixir app at the moment and really enjoying it, but some of my recent dabbling in the type-safe worlds of Elm and Crystal have left me desiring a bit more structure in my code. The app I’m building involves a multi-step data transformation and so I have a data structure to properly represent this process. But since Elixir is a dynamically typed language, you can’t, for example, have a non-nillable field in a struct. The Elixir/Erlang ecosystem does, however, have a type-checking syntax called Type Specs, along with a tool, Dialyzer,...


Upcoming Phoenix Authentication Solution

I’m in the middle of writing an application in Elixir and Phoenix, so when I saw a link to an article by José Valim on an upcoming authentication solution for Phoenix, my initial reaction (before reading it) was negative. José is the author of the Devise framework for Ruby-on-Rails, so I assumed it was going to be the same idea, but for Elixir and Phoenix. I’ve implemented Devise in a handful of Rails apps, and each and every time I ended up ripping it out and writing my own auth solution (often based on this Railscasts tutorial). The reason is that while...


JavaScript Sprinkles with AlpineJS

I’m a big of ReactJS, but sometimes it is way too heavy for what I need. The majority of the applications I create are server-rendered and just need some “sprinkles” of JavaScript. In the past, I’ve leaned on jQuery for this, but I’m not a fan of the imperative nature of it.

Recently, I stumbled upon AlpineJS, which is a super minimalist framework that lets you write declarative sprinkles of JavaScript without resorting to something heavier like React or Vue. It comes in at just 6.4kb (compressed), less than a quarter of the size of Vue, React, or jQuery...


Enable Spell Checking in Vim for Markdown and Git Commit Messages

I had a ridiculous typo in a Git commit message recently, so I decided to explore spell checking in Vim. As it turns out, it’s extremely easy.

I only wanted it enabled for Git commit messages and markdown, so I added the following to my vimrc / init.vim:

" Spell-check Markdown files and Git Commit Messages
autocmd FileType markdown setlocal spell
autocmd FileType gitcommit setlocal spell

By doing this, it highlights potential misspellings in red underline. You can see a list of potential corrections by moving the cursor over the word in normal mode and...


Dark Mode and other site updates

Inspired by iOS’s new dark mode (and halloween!), I decided to a dark mode to the website using the new prefers-color-scheme media query. It was surprisingly easy to do. After I’d changed the

This took care of 90% of it:

@media (prefers-color-scheme: dark) {
  html {
    background-color: #19222b;
    color: #eee;

  .page-wrapper__inner {
    background-color: #222f3b;
    color: #eee;

Using a straight black-and-white background and foreground combo looks too harsh on the eyes, so you want to find a gray-ish background. Mine is a bluish-grayish...


Get the Previous Expression Value in IEx

When using Elixir, I’ve long missed the special _ helper from irb that returns the result of the previous expression. Sometimes I actually type it out of pure habit.

Little did I know that Elixir has the same thing, except better.

IEx.Helpers has a function v(n \\ -1) that returns the value of the nth expression in the session history. So v alone returns the previous expression and v(-2) returns the one before it.

iex(1)> "abc"
iex(2)> "zyx"
iex(3)> v
iex(4)> v(-3)

Ruby Symbol and String Array Shorthand

Ruby has some handy Array shorthands, but I always forget which is which, so I thought I should write them down.

Symbol Array Shorthand:

%i{foo bar}  # => [:foo, :bar]

String Array Shorthand:

%w{foo bar}  # => ["foo", "bar"]

Both also work with square brackets %w[a b c] or parenthesis %i(a b c)

Running Elixir tests in VSCode

In Vim-land, I use the vim-test plugin for quickly executing tests from a command line shortcut1. I wanted to reproduce this behavior in Visual Studio Code, but I couldn’t find an extension that worked in multiple languages (namely, Ruby, Elixir, Javascript, and Elm). I’m mostly just using VSCode for Elixir, but I still liked the idea of finding a more general purpose solution.

So instead I used VSCode’s support for Tasks to build the functionality myself. So in my project’s tasks.json file, I have the following 3 tasks for running all tests, a single...


SSH Tunnels into Production Rails Database

Today I needed to access a production database for my Rails app directly using a GUI application on my mac, so I figured out that this can be done by creating an SSH tunnel like so:

ssh -Ng -L <local-port>:<remote-host>:<remote-port> <user>@<remote-host>
ssh -Ng -L 3307: adam@

And then, in your Rails app, update the database.yml as if you were connecting to a local database, but specify the proper database name.

  adapter: mysql2
  database: myapp_production
  port: 3307
  username: root


Page 1 of 3 Next page ⟶