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"
External content

Convert Virtualbox .ova Image to .ovf

The .ova file format is a tar file with a .ovf file inside.
tar xvf virtualboximage.ova

Run your own code before specific RSpec examples

You probably know about the possibility to tag scenarios in Cucumber to run your own piece of code before the actual scenario is run which looks like that:

Scenario: Do something

and you place the following snippet into support/env.rb:

Before('@foo') do
  puts "This is run every time a @foo tagged scenario is hit"

You can tag RSpec examples like this:

it 'does something', :foo => true do

What you need is the following within the RSpec.configure do |config| block wit…

RestClient sends XML Accept header by default

REST Client is a nice, simple HTTP client library for Ruby.

When you do a simple GET request like that:

RestClient.get ''

it will result in this request beeing sent to

GET / HTTP/1.1
Accept: */*; q=0.5, application/xml
Accept-Encoding: gzip, deflate

The application/xml accept header might lead to unexpected results on your server. You can force REST Client to ask the server for default text/html that way:


High-level Javascript frameworks: Backbone vs. Ember vs. Knockout

This is a very general introduction to MV* Javascript frameworks. This card won't tell you anything new if you are already familiar with the products mentioned in the title.

As web applications move farther into the client, Javascript frameworks have sprung up that operate on a higher level of abstraction than DOM manipulation frameworks like jQuery and Prototype. Such high-level frameworks typically offer support for client-side view rendering, routing, data bindings, etc. This is useful, and when you write a moderately complex Javascript …

New cards feature: Github-style code blocks

You can now add code blocks without indentation, by using triple-backticks:

Code block goes here.

Fix ActionController::Session::CookieStore::CookieOverflow

This error simply means you've overloaded a cookie. Hints for fixing:

Check if you're putting too much (e.g. @some_object.inspect) into

  • the session
  • the flash, as it is stored in the session

Nicer alternatives to def_delegator or def_delegators

Delegating methods to other objects is often helpful but the syntax of both def_delegators and def_delegator is a complete mess that makes your code hard to read.

Consider these classes:

class Topic < ActiveRecord::Base
  def title
    "A title"
  def category
    "Topic category"

class Post < ActiveRecord::Base
  belongs_to :topic

Fix YAML::Syck::DefaultKey:0x1083b59f8

When your gems complain about invalid gemspecs and illformed requirements, it is most probably an error resulting from the transition from Syck to psych. To fix this:

  1. go to your gemspec directory (e.g. /Library/Ruby/Gems/1.8/specifications/)
  2. change #<Syck::DefaultKey:0x00000100e779e8> to = (equals sign) in each file that's complaining

Letter Opener

Preview email in the browser instead of sending it.

Ruby: Indent a string

Copy the attached file to config/initializers/indent_string.rb and you can say

"foo".indent(4) # "    foo"

Note you will find many simpler implementations of this method on the Interweb. They probably won't do what you want in edge cases, fuck up trailing whitespace, etc. The implementation in this card has the following behavior:

describe '#indent' do

  it 'should indent the string by the given number of spaces' do
    "foo".indent(2).should == "  foo"

  it 'should indent multiple lines line by line' do ...

Make Capistrano use SSH Key Forwarding

When deploying code with Capistrano (depending on your configuration) at some point Capistrano tries to check out code from your repository. In order to do so, Capistrano connects to your repository server from the application server you're deploying to with SSH. For this connection you can use two SSH keys:

  • the user's ~/.ssh/id_rsa [default]
  • the very same key you used for connecting to the application server - forwarded automatically to the git repository.

If you prefer the second way, add this to deploy.rb:


Use the "retry" keyword to process a piece of Ruby code again.

Imagine you have a piece of code that tries to send a request to a remote server. Now the server is temporarily not available and raises an exception. In order to re-send the request you could use the following snippet:

def remote_request
    response = RestClient.get my_request_url
  rescue RestClient::ResourceNotFound => error
    @retries ||= 0
    if @retries < @max_retries
      @retries += 1
      raise error

This sni…

External content

Moment.js - A lightweight javascript date library

A lightweight javascript date library for parsing, manipulating, and formatting dates.

CSS: Change text selection color

You can change the color for text selection via CSS, using the ::selection and ::-moz-selection pseudo-elements.

Adding this to your Sass will make all text selections use a red background:

  background-color: #f00

  background-color: #f00

Unfortunately, those can't be combined into "::selection, ::-moz-selection". Doing so will have no effect.

Auto-generate Cucumber navigation paths

Don't you just hate to write Cucumber path helpers to be able to say this?

When I go to the user form for "" # goes to edit_user_path(User.find_by_anything!(''))
When I go to the form for the user "" # goes to edit_user_path(User.find_by_anything!(''))
When I go to the form for the user above" # goes to edit_user_path(User.last)
When I go to the project page for "World Domination" # goes to project_path(Project.find_by_anything!('World Domination') …

New cards feature: Cite other cards

We've made it easier to link other cards:

  • You can now find a button Cite other card above the main text area
  • Clicking this button lets you search for another card
  • Clicking on a search result will paste a Markdown link into the text area

Git: Retrieve a file from a different branch or commit

To access files from another branch or past commit without doing a complete checkout, you can either use

git show branch:file
git show commit:file

to display, or check out the file into your working directory with

git checkout branch -- file
git checkout commit -- file

Cucumber step to test that a tooltip text exists in the HTML

Tooltips that are delivered through HTML attributes are encoded. Decode entities before checking for their presence.


Then /^there should( not)? be a(n encoded)? tooltip "([^"]*)"$/ do |negate, encoded, tooltip|
  tooltip = if encoded
  Then "I should#{negate} see \"#{tooltip}\" in the HTML"


This step uses the htmlentities gem described in another card.


2920 cards