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"

Show and change MySQL default character set

To show the MySQL default character set you have to login to the MySQL console and execute SHOW VARIABLES LIKE 'char%';

mysql> SHOW VARIABLES LIKE  'char%';
| Variable_name            | Value                      |
| character_set_client     | latin1                     |
| character_set_connection | latin1                     |
| character_set_database   | latin1                     |
| chara...
External content

Ruby 2.0 Implementation Work Begins: What is Ruby 2.0 and What’s New?

While 2.0 will include a number of syntax changes, new features and general improvements, mentioned below, it is anticipated to remain backward compatible with code written for 1.9.3 and Matz has stated that the changes are less significant than those made in the 1.8 to 1.9 jump.

Fix multiple CKEditor instances using jQuery adapter - fixed since 4.2

Using the jQuery adapter breaks the built-in save function of CKEditor.

Phenomenon: The page is submitted correctly, but the original values of the form fields were posted instead of what was typed in the editors.

Work around: Basicly instead of initiating the editor using the above example I ended up using the following:

$( 'textarea.editor').each( function() {

    CKEDITOR.replace( $(this).attr('id') );


Note: This assumes that each field using the editor has its own unique ID.

Paste X selections into your terminal with your keyboard

The buffer where text is put into when you double-click on text within X is called X selection.

You can paste this buffer (at least into a terminal window) by pressing Shift + Insert.

Rails logs are not flushed automatically (in Rake tasks)

The Rails logger will store its content in a buffer and write it into the file system every 1000 lines. This will come back to bite you when using to write log output during Rake tasks or on a production console.

You often won’t notice this because for the development and test environments auto_flushing is set to write after each line. On production environments the Rails logger writes only every 1000 lines – and not upon shell or script ter…

Don't call gsub on safe strings

Calling #gsub on a string that was previously marked as #html_safe will lead to unexpected behavior. E. g. backreferences to captured groups ($1, $2) will be nil even if the group was matched.

There is no universal workaround available since you can’t expect #html_safe strings to still be safe after using gsub on them.

You can, however, fix the $1 gsub behavior on html_safe strings.

Git: How to create and apply patches

You can convert git commits into patch files. Those can be used to apply to a different repository [1] or by someone else (e.g. sent when sent to them via e-mail).

Creating a patch

  1. Make your changes and commit them.
  2. Run git format-patch COMMIT_REFERENCE to convert all commits since the referenced commit (not including it) into patch files.

For example, let’s say you prepared 2 commits. Run:

git format-patch HEAD~~ 

This will create 2 files, one for each commit since HEAD~~, like these:


Run multiple local webricks at the same time using different ports

If you specify different ports, you can run multiple local webricks with rails server --port=300X at the same time.

Parse & sort unique hits in logfiles

If you want to know the exact hits on your website (or whatever logfile you want) for a specific date without duplicates, here’s how. “Unique” means you don’t want to count hits to an URL originating from the same IP twice.

You can use the attached script to do so:

# ./log_parser.rb 2011-10-04

27 hits on /rss.xml
36 hits on /stylesheets/fonts/slkscr-webfont.woff
37 hits on /stylesheets/fonts/slkscrb-webfont.woff
37 hits on /images/bullet.png
38 hits on /images/download.png
38 hits on /images/play.png

Monitor a Rake task with God

In order to monitor a Rake task using God your Rake file must write a file with its process ID (PID) to a path determined by God. This way God can check whether the Rake process is still alive.

Here is how to do this: In your God config, call the Rake task with an environment variable PIDFILE. This variable should equal the PID file path desired by God: do |w|
  w.dir = "#{rails_root}" = "my_task"
  w.interval = 10.seconds
  w.pid_file = "#{rails_root}/tmp/pids/#{}...

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

Stub a request's IP address in a Cucumber scenario

The solution in this card is based on a stack overflow post by Leventix.

If you need to make request come from a fixed IP address for the duration of a Cucumber scenario, the code below lets you write this:

Given my IP address is

Rails 3

Given /^my IP address is "(.*?)"$/ do |ip|

Rails 2 —–…

Using :dependent => :destroy – Issues with 'code arrangement' or 'cached objects'

First keep in mind that :dependent => :destroy hooks into before_destroy.
So when you use other before_destroy callbacks the sequential arrangement of your code may be important.

For example:

class Container < ActiveRecord::Base
  before_destroy :a_callback
  has_many :items, :dependent => :destroy

results in

# => a_callback
# => container.items.destroy_all


class Container < ActiveRecord::Base
  has_many :items, :dependent => :destroy

How to install a debian/ubuntu package without dependencies

Please note that you can break your system with this! This is not recommended.

Sometimes the package repository has errors. If you can’t install a package because you can’t install the dependencies with the package manager you can try this:

(You have to download the deb first e.g. from here or here)

dpkg -x bad-package.deb common
dpkg --control bad-package.deb

Then you have to edit DEBIAN/control with an editor. You can delete the broken dependencies t…

Javascript equivalent of Ruby's array.collect(&:method)

The most common use case for Ruby’s #collect is to call a method on each list element and collect the return values in a new array:

['hello', 'world', 'this', 'is', 'nice'].collect(&:length)
# => [5, 5, 4, 2, 4]

Although there is no equivalent to this idiom in naked Javascript, there is a way to collect object properties (but not method results) if you are using common Javascript libraries.

If you are using jQuery with the Underscore.js utility library, you can use [pluck](htt…

You can use any RSpec matcher to match arguments of method calls

RSpec lets you define the arguments with which you expect a method to be invoked:


Sometimes you don’t care about the exact arguments. For such cases RSpec comes with argument constraints like anything or hash_including:

subject.should_receive(:update_attributes).with(hash_including(:message => 'hi world'))

You can go even further and use any RSpec matcher to match arguments:


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    ...
2825 cards