External content

Tasks, microtasks, queues and schedules -

The way that Javascript schedules timeouts and promise callbacks is more complicated than you think. This can be the reason why callbacks are not executed in the order that they are queued.

Please read this article!

External content

Thunderbird add-on to manually sort accounts and folders

This extension allows you to manually sort (order) your folders in the folder pane of Thunderbird or automatically sort them, but in a better way. This extension also allows you to re-order accounts in the folder pane.


Merge two arbitrary scopes in Rails 3

Rails 3 allows you to join two scopes from arbitrary sources by calling the merge method:

scope1 = User.where(:email => '')
scope2 = User.where(:first_name => 'hans')
merged_scope = scope1.merge(scope2)

merged_scope.all will now trigger a query for the combined scope chain:

SELECT `users`.* FROM `users` WHERE `users`.`email` = '' AND `users`.`first_name` = 'hans'

If you are joining two models, you can also [merge scopes for different models](…

Lazysizes 2 is here

It claims to be even faster and brings a new plugin that polyfills object-fit and object-position. This allows for easy arrangement of e.g. images and videos inside containers.

As puts it, object-fit/object-position is a:

Method of specifying how an object (image or video) should fit inside its box. object-fit options include "contain" (fit according to aspect ratio), "fill" (stretches object to fill) and "cover" (overflows box but maintains ratio), where object-position allows the object to be repositioned like backg…

How to find disabled fields with Capybara

At least Selenium cannot find disabled fields. Unless you find them explicitly:

find_field 'This is disabled', disabled: true
External contentRepeats


Note*: Ruby 2.1 has a built-in mechanism with Exception#cause, which serves a similiar purpose as Nesty. However, any code printing your stack trace (Exception Notifier, Airbrake, Sentry, your IRB shell, etc.) needs to be aware of Exception#cause. Nesty on the other hand merges the stack trace array of the current and previous exception.

There is also a backport of Exception#cause for older Rubies.

Nested exceptions for Ruby:

When you rescue an error and then re-raise your ow…

factory_girl: Re-use partial factory definitions

Let's say you have two factories that share some attributes and traits:

FactoryGirl.define do

  factory :user do
    screen_name 'john'
    email ''
    trait :with_profile do
      age 18
      description 'lorem ipsum'
  factory :client do
    full_name 'John Doe'
    email ''
    trait :with_profile do
      age 18
      description 'lorem ipsum'

The attached patch let's you extract the shared behavior into a mixin:

FactoryGirl.define do

mixin :person do

External contentRepeats

Getting permanent links to files on Github or Gitlab

Please don't simply copy line number links from Github. The URL usually contains a branch name like master:

If someone now posts an insertion or deletion to that file into master your link points to the wrong line!

A better way is to (Github) press the Y key after clicking on a line number or (Gitlab) clicking the "Permalink" button in the top bar.

This will transform the URL to another URL that points to the particular commit:


Ruby: Converting UTF-8 codepoints to characters

Converting string characters to or from their integer value (7-bit ASCII value or UTF-8 codepoint) can be done in different ways in Ruby:

  • String#ord or String#unpack to get character values
  • Integer#chr or Array#pack to convert character values into Strings

Character values to Strings


To get the character for a 7-bit ASCII value or UTF-8 codepoint (0-127) you can use Integer#chr:

# => "t"

To get a character for values larger than 127, you need to pass the encoding. E.g. to get codepoint 25…


Organize monkey patches in Ruby on Rails projects

As your Rails project grows, you will accumulate a number of small patches. These will usually fix a bug in a gem, or add a method to core classes.

Instead of putting many files into config/initializers, I recommend to group them by gem in lib/ext:


Making jQuery throw an error when it returns an empty collection

When you are working with jQuery selectors and collections, many times you want to know if the collection actually contains the elements you wanted to select. Here's a tiny jQuery plugin that does just that.

$.fn.ensure = ->
  if (@length == 0) then throw 'Empty jQuery collection'

Use it like this:

> Console: "Uncaught Empty jQuery collection"
External contentRepeats

InfoQ: How to Design a Good API & Why it Matters

A well-written API can be a great asset to the organization that wrote it and to all that use it. Given the importance of good API design, surprisingly little has been written on the subject. In this talk (recorded at Javapolis), Java library designer Joshua Bloch teaches how to design good APIs, with many examples of what good and bad APIs look like.

Rails Env Widget

Have you ever mistaken one Rails environment for another? The attached helper will help you to never do it again.

Save the attached file to app/helpers/ and use the widget in your layout like this:

  = rails_env_widget unless Rails.env.production?

It'll render a small light gray box in the top left corner of your screen, containing the current Rails environment. On click, it'll disappear. Actually, it has the same UX as our Query Diet widget.


Traverse an ActiveRecord relation along an association

The Edge Rider gem gives your relations a method #traverse_association which
returns a new relation by "pivoting" around a named association.

Say we have a Post model and each Post belongs to an author:

class Post < ActiveRecord::Base
  belongs_to :author

To turn a relation of posts into a relation of its authors:

posts = Post.where(:archived => false)
authors = posts.traverse_association(:author)

You can traverse multiple associations in a single call.
E.g. t…

Auto-destruct in 52 days

Updated: Installing RMagick on Ubuntu

Appended a section about how to install old rmagick versions on Ubuntu 16.06. Installing 2.15 worked out of the box, but installing 2.13 had issues. See the card to fix them.

Bitmap to Vector Converter

Automatically convert bitmap images like JPEGs, GIFs and PNGs to the crisp, clean, scalable vector art of EPS, SVG, and PDF with the world's best auto-tracing software.

It's true, it does a great job.


Rails 4 introduced collection_check_boxes

Starting from Rails 4.0, you can use a special form options helper called #collection_check_boxes. It behaves similar to #collection_select, but instead of a single select field it renders a checkbox and a label for each item in the collection.

= form_for @post do |form|
  = form.collection_check_boxes :author_ids, Author.all, :id, :name_with_initial

How generated form params look like ———————————…

Dynamically uploading files to Rails with jQuery File Upload

Say we want …

  • to create a Gallery that has a name and has_many :images, which in turn have a caption
  • to offer the user a single form to create a gallery with any number of images
  • immediate uploads with a progress bar per image
  • a snappy UI

Enter jQuery File Upload. It's a mature library that can do the job frontend-wise. On the server, we'll use Carrierwave, because it's capable of caching images.

(FYI, [here's how to do the u…

3108 cards