ActiveRecord's establish_connection

If you’ve ever wondered how your Rails ActiveRecord models end up magically translating some connection details (probably you have these in config/database.yml) into data you can interact with, establish_connection is a pretty significant part of that magic. In this post, I’m going to be laying out the different arguments this method accepts to determine how to connect to a database....

Certbot renewals with Route53

This is a bit of documentation for the next time I run into this problem, however you might find it useful. The certbot and certbot-auto commands support plugins, but do not come with many out of the box. The installation method for plugins (certbot being written in Python), is pip, however certbot may or may not pick up plugins installed...

Internationalised views with Rails

Rails has great built in support for internationalisation. Generally, many people, including myself, end up focussing their efforts on internatising strings - for example, changing form labels, errors, and maybe some minor copy like headings, using I18n.t (an alias for translate), which looks up which string to return for the current locale (determined from I18n.locale, which can be set from...

Running a command on a server directly from SSH

The SSH command accepts a very useful argument that I think is underused by many devops folks looking to run a quick command and get on with their day. The output of the synopsis of the SSH command man page (man ssh) ends with: [[email protected]]hostname [command] This [command] is the useful bit - you can pop any command you like...

Extracting XML data with curl and xmllint

(I start off talking about why I was doing this. You can jump to the tip if you want.) I use HomeAssistant heavily at home for converging a range of smart home data from sensors around my house, as well as from a range of open data sources. HomeAssistant has a REST sensor which is good for a known data...

Migrate on push with Heroku releases

I use Heroku for most of my hosting, and also use it a lot in my work at Rabid Technologies. Something I frequently run into is a migration not being run after a git push heroku master, often causing an embarrasing application error page until someone can get to running heroku run rake db:migrate. Fortunately, Heroku supports release commands. These...

Simple Ruby API clients with HTTParty

I frequently write code that interacts with a third-party HTTP API. When I create this code, I find the best approach is to create a very thin abstraction layer over the API that can easily be stubbed out under test. If the data returned from the API is complex or requires further processing, I occasionally provide additional abstraction layers on...

Git commit message templates

Writing high-quality git commit messages is one of the most responsible things you can do as a developer who cares to write considerate code that is well thought-out and easy to maintain. There’s a great template for git commit messages that’s floating around in a number of places. It’s referred to the “Contributing to a Project” chapter of the Git...

URI.regexp in Ruby

Recognizing or validating URIs in a string or strings of text is a fairly common problem. Unfortunately, just as common is the range of regular expressions that exist to validate URIs (or, generally, URLs). There are many, many StackOverflow answers and blog posts that lay out a massive variant of expressions in function and quality, and it’s not the easist...

TIL: Begin/rescue/end assignment in Ruby

Today, while working on consuming a third-party API, I discovered that the result of a begin/rescue/end block in Ruby can assign to a variable, just like an if statement can. This isn’t a technique I’d recommend for every single situation where it could be used, but it is convenient for operations where a particular error scenario can result in a...

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