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"

Request a gzipped response from a web server using Wget

To reduce download time, application servers usually serve content using gzip compression, if the browser supports it.

When using a tool like Wget to explicitly download an application's response, the server responds with the uncompressed version:


If you are curious about the compressed file's size, pass the corresponding HTTP header:

wget --header="accept-encoding: gzip"

How to fix "unknown role" errors in Capistrano recipes

When you have a complex recipe setup with multistage deployment you may run into this error:

`role_list_from': unknown role `something' (ArgumentError)

Consider this task definition:

namespace :foo do
  task :bar, :roles => :something do
    # do crazy stuff

Whenever we call in our recipe, Capistrano will fail if you deploy to a stage where none of the servers has the role the error complains about, "something" in this case.

However, you can [hack around it](…

External content

Scenario outlines in Cucumber

Scenario outlines allow us to more concisely express repetitive examples through the use of a template with placeholders.

Graticule computes NULL distance for some records (and how to fix that)

The SQL code generated by Graticule's spherical distance computation is insufficient and can lead to NULL distances in edge cases.

The reason for this is that MySQL is performing several sine and cosine computations which can result in slight rounding errors – which is usually okay. Rarely, though, for the exact center of the given circle, it is then asked to compute the arc cosine of a result like 1.0000000001.

Since this i…

Bulk-change multiple table rows in a migration

Using rename_column, remove_column, etc. more than once in a migration makes that migration run slower than it should. Use change_table instead.

Consider this migration:
add_column :users, :name, :string
remove_column :users, :first_name
remove_column :users, :last_name
rename_column :users, :cool, :awesome

Migrating in this case means that all those commands are processed step by step, causing 4 SQL statements to change the table. In turn, your database needs to modify the table structure 4 times. When working on hug…

Ubuntu 11.10: Playing sound over front and back panel (or headphones and speakers) at once

I have a pair of headphones connected to my desktop's back panel and a headset connected to the front panel. I used to play sound over both outputs, but this suddenly stopped working this week.

Apparently, (perhaps through some update) "jack sensing" got turned on, which disables the back panel as soon as you connect something to your front panel audio jack.

To disable this feature, I used alsamixer (use the arrow keys to navigate right to "auto mute", and disable with the up key). For some reason the corresponding checkbox in the `gnome…

Embed Google Analytics code for some environments only

When you use google analytics to track your visitors interactions, you should ensure that it runs on your production site only. Otherwise it will spoil your statistics. To prevent this, test for the right environment and place the JS-code afterwards:

- if Rails.env.production?
    var _gaq = _gaq || [];
    _gaq.push(['_setAccount', 'UA-XXXXXXXX-X']);

Pick a random element from an array in Ruby

# => e.g. 4

If you'd like to cheat and give different weights to each element in the array, you can use the attached initializer to say:

# => probably 4

ERB templates and comments

When you use one line Ruby comments in ERB templates you should never do this (notice the whitespace in front of #):

<% # my comment %>

<div>my html</div>

This leads to strange html output. To avoid long debugging sessions, you should never have a whitespace before the # character (but newline is allowed)

<%# this works as expected %>
    # this works, too
    # foo bar baz
External content

Sequel: The Database Toolkit for Ruby

Seems like a useful gem for cases where ActiveRecord is overkill but you don't want to do everything by hand either.


User friendly form design

There are two types of forms: User forms, e.g. for sign up, and Administration forms, to maintain data. They are quite different in purpose: The former must be simple and quick to fill in, whereas the latter should organize a lot of data in a reasonable way.


  • Simple is win.
  • Align forms vertically, one element below the other.
  • Never explain your form. If it is too complicated, redesign.
  • Skimp on lines and boxes. If you need them, something is wrong with your form.

A form element needs

  • Label. Above the field i…

ActsAsTaggableOn: Cache tag lists

For performance improvements (and to remove the need for eager loading), the ActsAsTaggableOn gem supports caching your tag lists directly in your model. To enable this, simply add a cached_tag_list column to your table.


class Company < ActiveRecord::Base
  acts_as_taggable_on :categories

The cache column has to be named cached_category_list.

Existing data

If you already have existing data, you have to save all records with tags once, after you've added the co…

External content

davetron5000/methadone - GitHub

Framework to write command-line apps in Ruby. Comes with a nice way of processing parameter options, some utility classes and Cucumber steps for testing your CLI app.

Caching may break relative paths in your merged stylesheet

If you turn on stylesheet caching, it might happen that stylesheets from different locations with different relative pathes will be put together to one big stylesheet.

This stylesheet then resides in /stylesheets but still holds the old pathes, which aren't valid anymore. This leads to the effect that images are displayed on your local development machine (where caching is turned off automatically) but not on the server.

To fix this, either:

  • Move all stylesheets to the same folder
  • or have one cache per folder

Git instaweb

Git has a built-in repository viewer for your web browser. a bit similar (but less awesome) than github.

If you have apache installed, simply go to your repository, and enter
git instaweb –httpd apache2
otherwise, simply install lighttpd and just run
git instaweb

This should open a brower automatically pointing to your repository. If not, try to connect to localhost:1234.

You can stop the server with
git instaweb –stop

External content

DataMapper Retrospective

I introduced DataMapper on my last two major projects. As those projects matured after I had left, they both migrated to a different ORM. That deserves a retrospective, I think.

External content

Rails ERD – Entity-Relationship Diagrams for Rails

Gem to generate entity relationship diagrams from your Rails 3 ActiveRecord models. The diagram style is pretty and configurable.

How to ignore new files or changed files in git

How to ignore new files

Add the path(s) to your file(s) which you would like to ignore to your .gitignore file (and commit them). These file entries will also apply to others checking out the repo.
Add the path(s) to your file(s) which you would like to ignore to your .git/info/exclude file. These file entries will only apply to your local working copy.

How to ignore changed files (temporarily)

In order to ignore changed files to being listed as …

2878 cards