CSS has a well-supported :empty selector

All browsers + IE9 know the CSS :empty selector. It lets you hide an element when it has no content.

For instance, you have a badge displaying the number of unread messages in a red bubble with white text:

.unread-messages-bubble {
  background-color: red;
  border-radius: 10px;
  padding: 10px;
  color: white;

To hide that bubble entirely when there are no new messages:

.unread-messages-bubble:empty {
  display: none;

Note that the element must be completely empty for `:empt…

Cucumber: How to speed up your test suite

In most projects I know, Cucumber test suite speed is not an issue. Of course, running 350 features takes its time, but still each test for itself is reasonably fast. There is nothing you can do to fundamentally speed up such a test (of course, you should be using parallel_tests).

However, in projects that go beyond clicking around in a web GUI and checking results, there might be various measures to speed up things. Katapult tests, for example, could be sped up more than 4 times by …


RSpec: Tagging examples and example groups

In RSpec you can tag examples or example groups with any tags you like simply by saying

describe ReportCreator, slow: true do
  # ..

describe ReportCreator do
  it 'generates reports', slow: true do
    # ...

You can then only run examples with these tags.

rspec --tag slow
rspec -t slow

# Using the parallel_tests gem
rake "parallel:spec[,,--tag slow]"

Or you can run all examples except the ones with a certain tag:

rspec –tag ~slow # note the ~
rspec -t ~slow

Using the parallel_tests gem

rake "par…


Advisory: Excel converts CSV entries to formulas

If your application exports CSV, be advised that Excel and other spreadsheet applications treat certain cells (those starting with =, +, - or @ as formulas.

This is an issue if you output user input. Not only is it probably not what you want, it also poses a security risk. See the link for attack vectors.

Note that current Excel versions will warn the user when opening the file. At least for the code execution vulnerability, this warning seems adequate to me.


If possible, always **try to avoid CSV and output XLS(X) f…

Auto-destruct in 50 days

Updated: When overriding #method_missing, remember to override #respond_to_missing? as well

You should override #respond_to_missing? instead of #respond_to? so your instances work with #method. Also see Marc's post.

Using Rails with Webpack: First steps

Webpack opens the world of npm to Rails developers. It does not collide with the asset pipeline—however, it's kind of a parallel world and you'll probably be better off going for either Webpack or asset pipeline.


  1. Install a recent Node.js

    curl -sL | sudo -E bash -
    sudo apt-get install -y nodejs
  2. Install Yarn

    curl -sS

Preloaded associations are filtered by conditions on the same table

When you eagerly load an association list using the :include option, and at the same time have a :condition on an included table, two things happen:

  1. Rails tries to load all involved records in a huge single query spanning multiple database tables.
  2. The preloaded association list is filtered by the :condition, even though you only wanted to use the :condition to filter the containing model.

The second case's behavior is mostly unexpected, because pre-loaded associations usually don't care about the circumstances under which the…

Turning off VCR when stubbing with Webmock

Sometimes when working with VCR you still want to use webmock. Since VCR hooks into webmock and fails when an unknown request is happening, you have to turn it off in order to use webmock like you are used to. Here is how to do this in rspec.

RSpec.configure do |config|
  config.around do | example |
    if example.metadata[:turn_off_vcr]
External contentRepeats

Sidekiq: Problems and Troubleshooting

When using Sidekiq in your application, you must write thread-safe code.

This wiki page also lists gems that are known to be unsafe on threaded applications.
When adding a gem that will also be used by a Sidekiq worker, make sure to confirm it's thread-safe.

Webservice to test and inspect requests is a webservice that gives you a temporary URL you can use to test request. The page will automatically record and display the latest web request made to it.

How to install packages from newer Ubuntu releases

We're usually running Ubuntu LTS versions. Sometimes newer hardware requires packages from more recent Ubuntu releases that only come with 6 months of support. If there is really no other way, it's possible to install packages from later Ubuntu releases

Caution: Pay really close attention to what you're doing. Depending on the package, this process may require upgrading a lot of dependencies, possibly breaking the system! You really should not do this unless you've carefully calculated the impact on your system



Auto-destruct in 45 days

Updated: Chrome 34+, Firefox 38+, IE11+ ignore autocomplete=off

Added new method with autocomplete="new-password".


Valuable Chrome DevTools Shortcuts

In the DevTools settings, there's a "Shortcuts" section. Found these keyboard shortcuts there:


Toggle drawer
STRG + ~/`
Show console


Change number by 10
Change number by 100


Toggle "visibility:hidden!important" (useful when debugging page repaint times).
CTRL + hover above element in the DOM list
Don't show the yellow dimensions tooltip (useful when the tooltip covers just the area you need to see).
Drag & Drop
You can actually drag …

Rails + Sidekiq::Web: Configuration for wildcard session cookies

When you're using Sidekiq::Web to monitor the Sidekiq status AND have your session cookie configured to a wildcard domain like, you need to take an additional step to keep your cookies valid.


Sidekiq::Web is mounted into your Rails application and will use the Rails session cookie for protection from CSRF attacs. While it somehow figures out the cookie name, it does NOT respect cookie configuration like a custo…


Reading an element's attributes with Capybara

capybara_element['attribute_name'] allows accessing an element's attributes in Capybara.

A few examples:

# => "first-class second-class"

# => "My placeholder value"

# => ""

# => nil

Fix for: "can't convert nil to String" when running "gem update --system"

When attempting to update RubyGems, depending on updates your previously performed, you might run into an error

ERROR:  While executing gem ... (TypeError)
can't convert nil into String

Fix this by running

gem uninstall rubygems-update -a -x

Don't require files in random order

A common pattern in Ruby is to to require all files in a specific diretory, using something like

Dir.glob(Rails.root.join('lib/ext/**/*.rb')).each do |filename|
  require filename

However, this causes files to be required in an order determined by the file system. Since load order can be important, this may lead to different behavior on different machines which are hard to debug.

Simply add a .sort:

Dir.glob(Rails.root.join('lib/ext/**/*.rb')).sort.each do |filename|
  require filename
Auto-destruct in 50 days

Updated: Git: How to configure git to push only your current branch

Added info about a small footgun with the current setting most of us are using. It's still the best option all around.

For most of us, current is the safest push behavior. However, it has a small side effect: When a branch with your local name does not exist on your remote, it automatically creates it on the remote.

While that is usually what you want, it does not setup tracking between your local and remote branches. That means git pull won't work, and Git won't notify you when your local and remote …

3390 cards