Blog

Musings on programming, design, and business.


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...

Read More...

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...

Read More...

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
"zyx"
iex(4)> v(-3)
"abc"

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...

Read More...

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:100.64.26.11:3307 adam@100.64.26.11

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.

development:
  adapter: mysql2
  database: myapp_production
  host: 127.0.0.1
  port: 3307
  username: root
  password

Read More...

Rails presence method

I use Rails’ present? method constantly, but recently I stumbled across the presence method.

In the past, I have often found myself doing the following because params[:foo] could be nil or a blank string.

foo = params[:foo].present? ? params[:foo] : "something else"

I hate that i have to write params[:foo] twice. But the presence method is handy for this case. It returns nil if the item is nil or a blank string, but otherwise returns the value.

foo = params[:foo].presence || "something-else"

VSCode + ElixirLS = 👍👍

I’ve played around with VSCode here and there, but as a fairly picky Vim user who doesn’t do TypeScript, I never quite understood the hype.

Today I started up a new Elixir / Phoenix project (more on that to come) and tried out the Elixir Language Server Extension and the integration is very impression. Code completion, debugger support, automatic inference of Dialyzer Typespecs, documentation on hover, and more….

I don’t expect to be using VSCode as my standard editor (again, picky Vim user1), but I think I’ll stick with it on Elixir projects.


Read More...

Netlify Analytics First Impressions

My new website is hosted on Netlify, which is an awesome service for hosting static websites. Recently, they launched an Analytics Platform as an alternative to Google Analytics. My impressions of this new tool isn’t quite as enthusiastic as their service in general, but it does have some nice features.

Netlify Analytics Screenshot

Pros:

Server Side
  • Can’t be blocked by Ad-Blockers
  • Tracks requests of non-web-page assets like RSS feeds, images, etc
  • No impact on your client side performance since there’s no Javascript library
Privacy Centric
  • Isn’t connected to an ad network...

Read More...

Page 1 of 3 Next page ⟶