Griffin Smith’s Blog

Programmer, musician, and maker of things based in Brooklyn, NY

about me

I’m a full-stack developer currently based in Brooklyn, NY. In my free time I like to cook, bike, play guitar, piano, and drums, and pet the myriad stray cats that pass through the back yard of my apartment. Here I write about coding and entrepeneurship.

my current open-source projects

The Magic of :global

One of my non-technical coworkers recently came by my desk with a problem - she had this list of zip codes in Long Island, and needed me to write a SQL query to fetch a list of users who had zip codes in that list.

written in vim Read more →

A Vim Oneliner for Converting Ruby Hash Syntax

As of ruby 1.9, hashes that previously looked like:

:one => '1',
:two => '2'

can now use the following syntax:

one: '1',
two: '2'

I like this syntax a lot; it’s cleaner, more concise, and more consistent with other languages (javascript, python…). However, many code generators (Rails generators et al.) will still generate code that uses the old syntax. I came upon such an occasion today and wrote the following one-liner in Vim to convert between the two:

%s/:(\S{-})(\s{-})=> /\1:\2/

We can further convert this into a command that we can use with a custom range with the following line:

command! -range ConvertHashSyntax <line1>,<line2>s/:(\S{-})(\s{-})=> /\1:\2/

This will preserve spacing and ignore cases where hash keys aren’t symbols. For more fun with the vim :substitute command, check out my post that contains an introduction and another sample use case here.

written in vim,ruby

Seamless Vim SQL Workflow With Vim-pipe

In case it’s not obvious at this point, I really, really like vim. I like it so much, in fact, that any time I’m editing text and I can’t use vim I end up spending about half my time pulling my hair out and cursing loudly at the computer. To get around this, I’ve managed to inject it into about everything I do. I use i3 as my window manager, configured so that I can move, resize, and switch between all my windows using Vim cursor keys. I use pentadactyl in firefox, which revamps the whole user interface so that everything can be done using Vim commands and shortcuts. And I set -o vi in my shell so that I can edit command line commands using Vim keys.

Another thing I do to make it so I never have to use anything that isn’t vim is edit all temporary SQL commands in vim, and run them all from there. This allows me to run SQL statements directly from code, and also to use the output to help me write the code itself (see my post about the vim substitute command for an example). To accomplish this, I use the vim-pipe plugin by krisajenkins. Here’s how to get that set up, and also some tips and tricks on how to use it best.

written in vim Read more →

How I Switch Between Dark and Light Terminals With I3 and St

I’m pretty happy with my current Linux desktop environment - I’m running Arch Linux, which is a barebones, simplicity-first do-it-all-yourself distribution. I’m using the absolutely amazing i3 tiling window manager, and I just recently switched to a fairly hacked-on version of the st terminal emulator, which is basically as stripped-down and simple as terminal emulators get.

I’ve got two versions of st compiled and sitting in /usr/bin - one with the dark version of the Solarized color scheme, and one with the light version. I’ve got a couple of scripts that I wrote to easily switch between those two, which I do based on the whims of my corneas.

written in linux Read more →

An Introduction to the Vim :substitute Command

I know a lot of people who use Vim as a sort of glorified console-mode notepad. They write a bunch of things twice, have a tendency to mash backspace when they made a typo earlier on the line, and perform a lot of very repetitive actions to modify code. Even if you’re being a “good vim user” and using hjkl instead of cursor keys, if you frequently find yourself doing the same thing twice then you’re really not taking advantage of the full power that Vim has to offer.

The :substitute command is an awesome way to get rid of a lot of that repetition. Though it may seem like just a find and replace command it packs a full regex engine, which with references to numbered groups means you can rearrange and reorganize lines of code to your liking. Let’s take a look at an example of a use case I just encountered the other day.

written in vim Read more →