A check if two date or time ranges A and B overlap needs to cover a lot of cases:

When defining a trait using the Modularity gem, you must take extra steps to define constants to avoid caveats (like...

You cannot use Array#join on an array of strings where some strings are html_safe and others are not...

kernel.org

Git allows you to do a binary search across commits to hunt down the commit that introduced a bug.

When you need to see the content of a page (i.e. not all the HTML but the relevant text body...

When you eagerly load an association list using the .include option, and at the same time have a .where on...

When using virtual attributes, the attached trait can be useful to automatically copy errors from one attribute to another.

makandra dev

There are two distinct ways of commenting Haml markup: HTML and Ruby. HTML comments This will create an HTML comment...

To return non-HTML responses (like XLS spreadsheets), we usually use the respond_to do |format| format.xls do # send spreadsheet...

Rails 3, 4, 5, 6 config/application.rb config/environment.rb before the initialize! call (we don't usually edit this file)

Sometimes you want to fetch associations for an ActiveRecord that you already loaded, e.g. when it has deeply nested associations...

github.com

There are three ways to define your own RSpec matchers, with increasing complexibility and options: 1) Use RSpec::Matchers.define

When you need to add a event listener to hundreds of elements, this might slow down the browser. An alternative...

The Git stash does not work like a one-slot clipboard and you might shoot yourself in the foot if...

github.com

An alternative to this technique is using VCR. VCR allows you to record and replay real HTTP responses, saving you...

morris-photographics.com

Some browsers render PNG images with color profiles and other shenanigans, some don't. The cleanest way to have consistent...