Bash/Zsh shell expansion

Shell expansion is an incredibly handy shortcut. Previously to today, I’ve only ever used glob (*), which will expand to include all directories and files within the glob scope (e.g. * would list all files and directories in the current directory, test/* would list all files and directories in test/). There are more though! Today I’m covering { range }...

Paste mode in VIM

A VIM mode I did not know about for quite some time during my VIM usage is “paste” mode. This mode doesn’t do much, but is invaluable if you are moving code around, copy and pasting between files outside vim. Paste mode can be activated using set :paste and deactivated with set :nopaste. This mode by default simply deactivates autoindentation,...

Splitting large CSV files with awk

I recently learned of a useful technique when processing large text files that have a consistent separator using awk. awk is a text processing programming language dating all the way back from 1977. While the format string passed to awk technically represents a full programming language, it is most typically used directly from the command line or from shell scripts....

Relatively elegant ActiveRecord create callbacks

ActiveRecord callbacks are pretty popular in the Rails community, but they do have pitfalls. Probably the most significant one is that the responsibilities of a model can creep quite a lot once callbacks begin getting defined. Callbacks can also be hard to test, since they are triggered under a range of conditions, and have multiple phases per condition (before/around/after initialize,...

Javascript based file downloads in IE9

Getting feature parity on Internet Explorer is never very fun, or easy. I recently worked on a project where we needed to support inline downloads - specifically, a generated CSV string, as a file in all greenfields browsers as well as IE9-11. Fortunately, IE 10 and 11 support the Blob API, which make downloads pretty simple using the ‘msSaveBlob` non-standard...

Trip Report: East Holdsworth Loop

This trip report covers a fantastic day loop that I found to be a little under-documented when researching - especially the East Holdsworth track, which has become one of my favourite Tararua tracks. Started: 9:15am from Holdsworth Carpark Finished: 4:50pm at Holdsworth Carpark Times: 1hr up Atiwhakatu Track 2.75hrs up East Holdsworth Track 20min to Mount Holdsworth Summit 30min from...

Internationalised ActionMailer Subjects

I’m a big fan of keeping strings out of my application code. It’s a pattern I first came across with Android string resources, and since then I’ve been using tools just like the i18n gem to abstract content away from code. Something mentioned directly in the Rails I18n guides that I really like to see used myself is the built-in...

My understanding of CSS units

I was listening to Episode #107 of the Syntax Podcast this afternoon, which covered CSS units, and was inspired to actually stop and think about how I use units when writing CSS. I felt pretty reassured that generally my approach is in line with what Wes and Scott were discussing. Let’s go! rem I use rem by default for most...

Biking from Akatawara to Renata Hut (Attempt #2)

After my failed 2017 attempt to reach Renata Hut, I finally mustered up the spare time and inclination to have another shot. The TL;DR of the last attempt is that due to significant tree fall on the track, it took me too long to make it up to the Hut - I reached my cutoff and turned around. After that...

List filenames only with grep

Just a quick one - I use grep all the time to find matches for text in files. Sometimes I’m not really interested in exactly what matched, I just need a list of files that matched SOMEWHERE. This morning I found that the -l option with this (or --files-with-matches). From the man page: -l, --files-with-matches Suppress normal output; instead print...

I'm Josh McArthur, a web developer specializing in Ruby on Rails and Phoenix. I contribute code on GitHub and write blog posts about technology and hiking here.