Search_spinner Cross_grey Magnifier

Search syntax

  • Search for repeating cards with repeats:yes
  • Search for unfinished cards with unfinished:yes
  • Search for cards in a certain topic with topic:"name"
  • Search for phrases with "a phrase"
  • Exclude a word from search: -word
  • Exclude a phrase from search: -"a phrase"
  • Exclude a topic from search: -topic:"name"
Auto-destruct in 55 days

Updated: Asset Pipeline Basics

Highlighted that any required path must be relative to either the current directory OR a Rails asset path.

External content

RegExr: Learn, Build, & Test RegEx

RegExr is an online tool to learn, build, & test Regular Expressions (RegEx / RegExp).

Reverse-proxying web applications with Apache 2.4+

A reverse proxy is a “man in the middle” server that tunnels requests to another server. You can use for things like:

  • Expose a local service that you cannot directly reach over the internet
  • “Change” the domain or path of a web application by rewriting them on the fly
  • Instantly change servers that respond to a name or IP, without relying on DNS TTL

The following describes various Apache 2.4+ VHost directives to reverse-proxy an application that does not want to be reverse-proxied. The exam…


The many gotchas of Ruby class variables

TLDR: Ruby class variables (@@foo) are dangerous in many ways. You should avoid them at all cost.

Class variables are shared between a class hierarchy

When you declare a class variable, it is shared between this and all descending (inheriting) classes. This is rarely what you want.

Class variables are bound at compile-time

Like unqualified constants, class variables are bound to your current scope when the .rb file is being parsed.
This wi…

Show details of TLS/SSL connections of remote hosts

sslscan is a nice tool to show details about TLS/SSL connections:

~> sslscan

Testing SSL server on port 443

Supported Server Cipher(s):
Failed SSLv3 256 bits ECDHE-RSA-AES256-GCM-SHA384
Failed SSLv3 256 bits ECDHE-ECDSA-AES256-GCM-SHA384
Failed SSLv3 256 bits ECDHE-RSA-AES256-SHA384
Failed SSLv3 256 bits ECDHE-ECDSA-AES256-SHA384
Rejected SSLv3 256 bits ECDHE-RSA-AES256-SHA …

Prefered Server Cipher(s):
TLSv1 128 bits ECDHE-RSA-A…


Find an ActiveRecord by any column (useful for Cucumber steps)

The attached patch lets you find a record by a string or number in any column:


There’s also a bang variant that raises ActiveRecord::NotFound if no record matches the given value:


Boolean and binary columns are excluded from the search because that would be crazy.

I recommend copying the attachment to features/support/find_by_anything.rb, since it is most useful in Cucumber step …

Auto-destruct in 55 days

Updated: Managing vendor libraries with the Rails asset pipeline

Added a notice about how to fix libraries bringing their own (icon) fonts.

Ruby regular expression start/end line vs. start/end string

tl;dr: Most often you want to use \A and \z. Take care of using ^ and $!

^ Start of line
$ End of line

!!("image/jpeg" =~ /^image\/(jpeg|png)$/) => true
!!("image/png" =~ /^image\/(jpeg|png)$/) => true
!!("application/javascript" =~ /^image\/(jpeg|png)$/) => false

!!("application/javascript\nimage/jpeg\nfoo" =~ /^image\/(jpeg|png)$/) => true

\A Start of string
\z End of string

!!(“image/jpeg” =~ /\Aimage\/(jpeg|png)\z/) => true
!!(“image/png” =~ /\Aimage\/(jpeg|png)\z/) => true
!!(“application/javascript” =~ /\Aimage\/(…


Gatekeeping: Guide for gatekeeper

Note: This has been a private card for some time, because it is heavily tailored to our specific needs and tools. While it will certainly not apply to all (especially larger teams), we thought it might still be helpful as a starting point, and so made it public.

In order to reduce the number of rejects we get from clients, we want to review all code written before it goes to the staging server.

If you’re responsible for gatekeeping in a projects, this is what to do:

First, read the [Gatekeeping for developers](https://makandra…

Manually trigger a delegated DOM event

When you register a delegated event using on (or the deprecated delegate / live), it is somewhat hard to manually trigger these events manually, e.g. for testing.

After trying jQuery’s trigger to no avail, I had success by using native Javascript methods to create and dispatch an event. For instance, to trigger a mousedown event:

element = $(‘…’).get(0);
event = new MouseEvent(‘mousedown’, { view: window, cancelable: true, bubbles: true }…


count vs. size on ActiveRecord associations


  • When counting records in an association, you should use #size in most cases.
  • It will not work if the parent record has never been saved. Also there are finer distinctions between #size and #count. See below.


  • Always makes a COUNT(*) query if a counter cache is not set up.
  • If a counter cache is set up on the association, #count will return that cached value instead of executing a new query.

size, if the association has already been loaded

  • Counts elements in the already loaded array.
  • Does not …

Upgrading from Capistrano 2 to 3

Capistrano 3 is a major rework of the framework and requires several adjustments to your deploy configuration files. The biggest change is that they moved away from their custom DSL and use Rake instead. For connecting with and operating on the servers, they bring a new gem SSHKit which does the heavy lifting. It’s SSHKit’s DSL that is used anywhere inside the Rake tasks. See #Resources at the bottom for examples.


  • There is no :user setting any more. Set the deploy user directly as an option to the server directive. …

Beautiful and simple signatures in your browser

Signature Pad is a JavaScript library for drawing smooth signatures. It’s HTML5 canvas based and uses variable width Bézier curve interpolation based on Smoother Signatures post by Square. It works in all modern desktop and mobile browsers and doesn’t depend on any external libraries.



Test if two date ranges overlap in Ruby or Rails

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

  • A partially overlaps B
  • A surrounds B
  • B surrounds A
  • A occurs entirely after B
  • B occurs entirely after A

One trick to cover all these cases with a single expression is to see if the start date of each range is looking at the end date of the other range in the same direction.

The code below shows how to implement this in Ruby on Rails. The example is a class Interval, which has two attributes #start_date and #end_date. These dates are considere…


sessionStorage: Per-window browser storage

All major browsers (IE8+, FF3.5+, Safari 4+, any Chrome) support sessionStorage, a JavaScript storage object that

  • survives page reloads and browser restores,
  • but is different per new tab/window (in contrast to localStorage).

MDN says:

The sessionStorage object is most useful for hanging on to temporary data that should be saved and restored if the browser is accidentally refreshed


Example usage:

// Save data to the current sess…


ActiveRecord: When aggregating nested children, always exclude children marked for destruction

When your model is using a callback like before_save or before_validation to calculate an aggregated value from its children, it needs to skip those children that are #marked_for_destruction?. Otherwise you will include children that have been ticked for deletion in a nested form.

Wrong way

class Invoice
  has_many :invoice_items
  accepts_nested_attributes_for :invoice_items, :allow_destroy => true # the critical code 1/2
  before_save :calculate_and_store_amount                              # the critical code 2/...
External contentRepeats

How Googlebot Crawls Javascript

Google seems to have made some progress with indexing Javascript-heavy sites.

Note that we haven’t verified any of this. Also there are other important search engines than Google, especially outside of Germany/Europe.

2808 cards