Logging to multiple destinations is something I seem to have to do all the time, and until now, I’ve never really been able to find an approach I’m happy with. Almost always, I’m writing some kind of developer-script, and I want to write messages to both the terminal (to let the dev know what is going on), and to a...
Fingerprinting a file isn’t something I need to do super often, but it is useful to detect duplicates of files, or verify that the file has not been changed (this can be useful for more than auditing and security - for example, it’s particulalry useful for caching, which is exactly why Rails’ asset pipeline calculates hash digests for asset files...
Note: This post is created based on this Stackoverflow Answer. Occasionally, you may have a type of record that already exists in a database which you wish to read from, but never modify. In these situations, it can be worth adding a little code to mark these types of records as read-only. This will prevent most ActiveRecord data modification methods...
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....
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...
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...
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...
(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...
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...
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...