All Posts

Page 11 of 21

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: [user@]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...

TIL how to fork a Heroku application

Tonight I had a need to create a duplicate of a running app on Heroku, and discovered heroku-fork. This is a plugin which was extracted from the core Heroku CLI some time ago, but is easily installable using the command heroku plugins:install heroku-fork. It is run via: heroku fork --from [app name] --to [app name, can be new app] The...

TIL how to italicize comments in VS Code

Continuing my transformation of my development environment to match Wes Bos’, today I discovered from a Stack Overflow answer how to change how comments in any language are rendered in VS Code. It turns out that there is a setting to control it, it’s just deeply nested. The necessary snippet for user settings is: "editor.tokenColorCustomizations": { "textMateRules": [ { "scope":...

Page: 11 of 21