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"

How DECIMAL columns deal with numbers exceeding their precision or scale

When storing floating-point numbers such as prices or totals in an SQL database, always use a DECIMAL column. Never use FLOAT or kittens will die.

DECIMAL columns are parametrized with a precision and a scale. These parameters describe which numbers can be stored in that column. E.g. a decimal with a precision of 5 and a scale of 2 can store numbers from -999.99 to 999.99, but not 1000 or 1.234.

When you try to store a number in a DECIMAL field, and that number exceeds that column’s precision or scale, MySQL will store the …

Use Capybara commands inside an IFRAME

If you need to follow links, click buttons, etc. using Capybara inside an <iframe>, you can do it like this:

page.driver.within_frame('iframe-id') do
  fill_in 'E-mail', with: ''
  fill_in 'Password', with: 'secret'
  click_button 'Submit'

This is tested with the Selenium driver; I haven’t tested it with Chrome.

If you’re also using Cucumber you could make a meta-step like this:

When /^(.?) inside the (.?) frame$/ do |step_text, frame_id|
page.driver.within_frame(frame_id) do
step …


Don't name columns like counter_cache columns

ActiveRecord has a feature called counter caching where the containing record in a has_many relationship caches the number of its children. E.g. when you have House has_many :rooms, Rails can cache the number of rooms in House#rooms_count.

Mind that when a model has a column that looks to Rails like a counter-cache column, Rails will apply counter-cache logic to your model, even if you’re not using counter caches.

E.g. you have a house with 12 rooms, but `house.r…

External content

Copy & Paste & The Web | CSS-Tricks

Insanely detailled guide about controlling copy & paste behavior using web technology in 2015.

Fix: Capybara is very slow when filling out fields in large forms

In large forms (30+ controls) new Capybara version become [extremely slow] when filling out fields. It takes several seconds per input. The reason for this is that Capybara generates a huge slow XPath expression to find the field.

The attached code patches fill_in with a much faster implementation. It’s a dirty fix and probably does a lot less than Capybara’s own fill_in so don’t use it unless you are having problems with test suites that are unusable because of this problem.

To use the patch in Cucumber, co…

External content


SmartUnderline is an open-source JavaScript library which uses clever tricks to draw underlines in a more beautiful and readable way.

We’ve not yet put this into a project, but its effect is very pretty. Please update this card when you use it.

External contentRepeats

Why Using the Greedy .* in Regular Expressions Is Almost Never What You Actually Want – Marius Schulz

Explains the difference betwen .* and .*?, and why the latter can lead to faster patterns.

External contentRepeats

Github Cheat Sheet

All the hidden and not hidden features of Git and GitHub.

Faster debugging with RubyMine macros

In my RubyMine I have recorded two macros for debugging and linked them to some keyboard shortcuts. Since I believe everyone could benefit from having those I wanted to share this.

The first one simply inserts


and the second one

.tap { |object| binding.pry }

for when you do not have a reference to the object you want to inspect.

In order to record a macro you simply follow the path Edit > Macros > Start Macro Recording.

Then you simply type binding.pry or whatever you want to record and stop recor…

External contentRepeats

image-to-DataURI converter:

Small web application where you can upload an image (PNG, JPEG, GIF) and generate a base64-encoded version of it.

You can copy the result as
- HTML <img> tag with data URI,
- CSS rule with background-image and data URI,
- plain Base64-encoded data URI string.


Cancelling event propagation with jQuery

Within an event handler, there are no less than 4 methods to cancel event propagation, each with different semantics.

  • event.preventDefault()

    Only prevents the default browser behavior for the click, i.e. going to a different url or submitting a form.

  • event.stopPropagation()

    Only prevents the event from bubbling up the DOM. Note this effectively also cancels any event handlers attached through jQuery’s live method, since those depend on bubbling.

  • event.stopImmediatePropagation()

    Prevents the event from bubbling up t…


Simulate limited bandwidth with "trickle"

When testing mobile applications, it is sometimes helpful to simulate limited bandwith. There is a utility called “trickle” that allows you to do that.

Simply do
trickle -d 50 -u 20 firefox
to start a firefox with only 50 kB/s download and 20 kB/s upload bandwith.

This does not seem to work with chrome.

On ubuntu, install via
sudo apt-get install trickle

External contentRepeats

Ruby: What extend and include do

All Rubyists should be familiar with the common definitions for include and extend. You include a module to add instance methods to a class and extend to add class methods. Unfortunately, this common definition isn’t entirely accurate. It fails to explain why we use instance.extend(Module) to add methods to an instance. Shouldn’t it be instance.include(Module)? To figure this out we’re going to start by discussing where methods are stored.

Further reading

After you understood include and extend you might want to look …

ZenTest "invalid gemspec" / "Illformed requirement"

Today I ran into this:

Invalid gemspec in [/usr/local/rvm/gems/ruby-1.9.3-p194/specifications/ZenTest-4.9.3.gemspec]: Illformed requirement ["< 2.1, >= 1.8"].

You need a newer Rubygems version. Try this: gem update --system 1.8.29


Beware of "nil" values in params

Recent rails security updates have shown that people make incorrect assumptions about the possible contents of the params hash.

Just don’t make any! Treat it as what it is: potentially unsafe user input. For example:

/pages/edit?foo    --> params == {:foo => nil}
/pages/edit?foo[]  --> params == {:foo => [nil]} # at least in older rails 3 and in rails 2.x

Be especially wary about stuff like


If params[:password_reset_token] is nil, you’ll retriev…


A non-weird replacement for grouped_collection_select

Rails comes with grouped_collection_select that appears to be useful, but isn’t.

Use flat_grouped_collection_select instead:

def flat_grouped_collection_select(field, collection, group_label_method, value_method, label_method, options = {}, html_options = {})
hash = collection.group_by(&group_label_method).collect_hash do |group_label, group_entries|
list_of_pairs = group_entries.collect { |entry|

2825 cards