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"

Capybara can match elements outside of <body>

Capybara will match elements outside of a page’s <body> tag.

For example, the step definitions below match <link> nodes in a page’s <head>:

Then /^my browser should auto-discover the "([^"]*)" feed$/ do |slug|
  page.should have_css(
    'head link' +
    '[rel="alternate"]' +
    "[href='{slug}/feed.rss']" +
    '[title="RSS feed (all cards)"]' +

Then /^my browser should not auto-discover any RSS feeds$/ do

How to update a MySQL column with ascending numbers

Given the problem you have a new column postion and that column should be updated for all existing rows with ascending numbers. Furthermore these numbers should be generated by a special order. In order to achieve that you could do the following:

execute "SET @pos := 0;"
update " UPDATE pages SET position = ( SELECT @pos := @pos + 1 ) ORDER BY updated_at DESC;"

Disable Flash player in Google Chrome

Typing about:plugins in the URL bar will give you a menu where can disable and enable individual plugins.

Git: Change author of a commit

Using git rebase can be painful but luckily you can resort to cheating with git reset and committing anew.\
Now what if you wanted to rebase commits of other people and still wish them to be the authors of their code? Easy: make them the author of a commit you made.

When you have freshly staged changes that are ready to be committed, just use the --author switch:
git commit -m “Hello Universe” –author=”Philip J Fry

If you alr…

Open a MySQL shell using credentials from database.yml

In order to open a MySQL shell without the need to enter user and password, you can say the following in any Rails 2 project:

script/dbconsole -p

In Rails 3 you can say:

rails dbconsole -p

If you’d like to enter a database for an environment other than development you can say:

script/dbconsole -p staging

Use SSL for Amazon RDS / MySQL (and your Rails app)

In case you have sensitive data within your RDS instance, you want to use encrypted connections between your application and RDS instances. If you’re using MySQL on RDS, here’s what to do:

  1. Download the AWS CA file and copy it to the machine you want to connect from:
    As far as I could find out, you (currently) cannot access further details of the SSL configuration (such as public key).
  2. Try to connect using MySQL client

    `% mysql -uyour_username -p -h rds_hostname_from_…

Mute a skype chat

If you want to stop getting notified about new messages in a Skype chat (but not leave it altogether), you can type


into the chat. This will only affect this one chat.

To only be notified when certain keywords appear in the conversation, use

/alertson KEYWORD

Note that multiple keywords must be defined with one call, as each call will overwrite previous keywords. Separate them by spaces:


Keywords are case-insensitive.

To revert to standard behaviour, use simply

/alertson    ...

How to change the order of nested forms being rendered (especially blank forms)

Generally for nested forms, a blank form is placed below all other existing object forms. If you would like to change the position of the blank form(s) you can reorder the object’s one-to-many association. For example you can put the blank form on top with the following snippet:

actors = movie.actors
actors.build_for_form(1, 1)

Because build_for_form creates new objects and appends them to the one…

How to grep recursively on Solaris

grep -r doesn’t work on Solaris. You can only grep on files in the current directory.

A workaround is to use grep with find:

find ./ -type f -exec grep "foo" {} +

Properly adding fields with default values to a model

When adding a new field to your model’s database table, don’t set any defaults in the database.

It makes people wonder why they get such values when reading attributes.\
Why? Because nobody looks at the database layout since such things are part of your application’s logic – and thus they belong into the corresponding model.

How to

Do it like this:

  • In your migration, after adding the field, update all fields to your desired default:
    update “UPDATE users SET locked = #{quoted_false};”
  • In your model, set a default value…

Install the Oniguruma gem

Oniguruma is an advanced regular expression engine for Ruby.

Install Oniguruma with binary dependencies like this:

sudo apt-get install libonig2 libonig-dev
sudo gem install oniguruma

On the Mac do:

brew install oniguruma
sudo gem install oniguruma

Send and receive encrypted file attachments with Thunderbird / Enigmail / OpenPGP

Sending and receiving file attachments using Thunderbird and the Enigmail addon is not as straightforward as it could be:

  • When sending file attachments, Enigmail will ask you for the encryption method. Choose Encrypt/sign each attachment separately.
  • When receiving an encrypted mail with file attachments, decrypting the message will not decrypt the attachment. Instead you need to right-click on the attachment and choose Decrypt and save as….

Mailcatcher: An alternative to inaction_mailer

Looks simpler than inaction_mailer:

sudo gem install mailcatcher

Setup Rails to send mails to Usually you want the following config in config/environments/development.rb and maybe in test.rb or cucumber.rb.

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
  :address => 'localhost',
  :port => 1025

Now you can see sent mails in your browser when opening

Note: In order t…

Defining to_json and avoiding errors

Defining a custom to_json method for your classes can be useful. Do it properly or you will “randomly” get errors like these:

wrong number of arguments (1 for 0) (ArgumentError)
wrong number of arguments (0 for 1) (ArgumentError)

Take a look at how Object#to_json is defined:

def to_json(options = nil)

Make sure you at least take the options argument – or, if you don’t need to look at it, just grab and (if you need to) pass on any arguments you receive like this…

Start Rails console or server with debugger

When you require the Ruby debugger to be available from your Rails console (e.g. you want to inspect a method’s magic), you need to enable it explicitly:
script/console –debugger

If you cannot access local variables etc, see this card.


For WEBrick, enable it similarly:
script/server –debugger

External content

Single step and slow motion for cucumber scenarios using @javascript selenium

Single step and slow motion for Cucuber scenarios can come in handy, especially in @javascript scenarios.

# features/support/examiners.rb
AfterStep('@slow_motion') do
  sleep 2

AfterStep('@single_step') do
  print "Single Stepping. Hit enter to continue"

If you’re using spreewald, these tags are available as @slow-motion and @single-step (with dashes instead of underscores).

Note: You can also [prevent the selenium webbrowser windo…

How to use CSS3 gradients in Opera

Since version 11.10 Opera provides support for linear gradients using -o-linear-gradient.

The syntax is pretty similar to Mozilla’s -moz-linear-gradient. This will create a vertical gradient from yellow to red:

background-image: -o-linear-gradient(top, #ff0, #f00);

The first parameter defines where the gradient starts and which direction it will go. \
You can use top/left/bottom/right (and combinations of those) but also set any angle you like (0° being the left side, going counter-clock-wise):

background-image: -o-l...
External content

Making the rails 3.1. asset pipeline and asset precompiling work in production mode

Recently, we had an interesting lunch-break with the rails 3.1. asset-pipeline in production mode. Daniel Zahn made a blogpost about our journey, precompiling assets, fingerprinting, Haml, Sass & Compass and what he calls “the dark heinous hutch”.

2810 cards