MySQL: Disable query cache for database profiling

If you want to see how long your database queries actually take, you need to disable MySQL's query cache. This can be done globally by logging into a database console, run

SET GLOBAL query_cache_type=OFF;

and restart your rails server.

You can also disable the cache on a per query basis by saying


You also probably want to disable Rails internal (per-request) cache. For this, wrap your code with a call to ActiveRecord::Base.uncached. For example, as an around_filter:

def disable_cache  ...

Legacy docs for Font Awesome 4.7

See the attached link for a list of icons in Font Awesome 4.

Icon names work differently in Font Awesome 5, where a name is only valid in combination with a name of the icon set.


Grep through the DOM using the Capybara API

When your Cucumber feature needs to browse the page HTML, and you are not sure how to express your query as a clever CSS or XPath expression, there is another way: You can use all and find to grep through the DOM and then perform your search in plain Ruby.

Here is an example for this technique:

Then /^I should see an image with the filename...

VNC browser disappears while typing

We often use the Then console step from spreewald in combination with geordi vnc from geordi to debug tests within a real browser. Sometimes when you type in the browser it suddenly disappears. You will only see a grey screen then.

This will always happen if you press the d key. Press the d key again and the browser will appear again.


Showing a custom maintenance page while deploying

Add a custom maintenance page for each vhost (require capistrano 3.x):


Add this line to your application's Gemfile:

gem 'capistrano', '~> 3.0'
gem 'capistrano-maintenance', '~> 1.0'

Add this line to you application's Capfile:

require 'capistrano/maintenance'

Enable task

Present a maintenance page to visitors. Disables your application's web interface by writing a #{maintenance_basename}.html file to each web server. The servers must be configured to detect the presence of this file, and if it i…

Auto-destruct in 27 days

Unpoly 0.53.0 and 0.52.0 released


New module: Passive updates

Thi work-in-progress package will contain functionality to passively receive updates from the server. Currently the following functionality is implemented:

  • Elements with an [up-hungry] attribute are updated whenever there is a matching element found in a successful response. The element is replaced even when it isn't targeted directly.

    Use cases fo…

Delegating an instance method to a class method in Ruby

With ActiveSupport you can say:

class Robot
  def self.likes_humans?

  delegate :likes_humans?, to: :class

# => 'Nope.'
# => 'Nope.'
Auto-destruct in 54 days

Spreewald 1.11.0 console step starts irb in execution context

You can now e.g. run steps within the irb console.


You want to debug why your fill in step is not working. Add the console step before this step.

When I select "Rejection" from "Decision"
Then console
Then I fill in "Comment" with "Some comment"

Run the test, open the vnc with geordi and try to reproduce the error step by step:

# This is new: You can now access step, page, with_scope and others.

irb> step('Then I fill in "Comment" with "Some comment"')
irb> fill_in("Comment", :with => "Some comment") …

External contentRepeats

Installing multiple MySQL versions on the same Linux with mysql-sandbox

Ubuntu has a package mysql-sandbox that lets you install multiple MySQL versions into your user home:

sudo apt install mysql-sandbox
# Download mysql distribution .tar.gz from
# You must choose "Generic Linux" instead of "Ubuntu" so you get a .tar.gz instead of .deb
make_sandbox mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz

On older distributions, make_sandbox might be mysql_sandbox instead.

This will install this version into /~/sandboxes/msb_5_7.21. The folder includes a command to start the MySQL daemon for that …


How to run a small web server (one-liner)

Sometimes you just want to have a small web server that serves files to test something.

Serve the current directory

On Ruby 1.9.2+ you can do the following ("." for current directory).

ruby -run -ehttpd . -p8000

Python 2.x offers a similar way.

python -m SimpleHTTPServer 8000 .

This is the same way with Python 3.x

python -m http.server

In both cases your web server is single-threaded and will block when large files are being downloaded from you.

For solutions in many other languages, see the [big list of http s…

Nested Spreewald patiently blocks are now patient

In Spreewald 1.10.4+, nested patiently blocks are now patient.

Here is an example:

patiently do
  patiently do

On spreewald 1.11.2+ the inner block will wait for the full configured wait time (by default 5 seconds). The outer patiently block would now be out of time, but it will always be retried at least a second time.

In versions 1.10.4 - 1.11.1, inner blocks would keep giving the outer block additional time to finish, which solves the same issues, but as a downside can cause the wh…

Auto-destruct in 50 days

Updated: Git configuration

Added handy aliases:

  amend = commit -v --amend # Amend changes to last commit
  c = commit -v -m # Commit with message from command line, usage: git c "commit message"
  lc = show --name-status # Show last commit
  lou = log --oneline @{u}.. # List unpushed commits
  uncommit = reset HEAD~ --soft
  riu = rebase -i @{u} # Interactive rebase against upstream
  du = diff @{u} # Diff against upstream
External contentRepeats

Rails SQL Injection Examples

This page lists many query methods and options in ActiveRecord which do not sanitize raw SQL arguments and are not intended to be called with unsafe user input. Careless use of these methods can open up code to SQL Injection exploits. The examples here do not include SQL injection from known CVEs and are not vulnerabilites themselves, only potential misuses of the methods.

Please use this list as a guide of what not to do.


Advantages of using over localhost:3000

Running rails server will start a local server that you can access via http://localhost:3000.

When you are working on multiple web apps, they will likely cookies with generic names on localhost. This is annoying, since you will sign out your current user whenever you switch to another app.

A better way is to use the service. All subdomains resolve to your local IP ( That means you can use a different hostname for different apps, and you will stay logged in in each app:

```text =…

Auto-destruct in 58 daysDeprecated

Updated: Using Rails with Webpack: First steps

Caveat: If your yarn.lock changes (e.g. you checkout a previous commit or a commit from a colleague) you need to run manually yarn and restart you webpack-dev-server. Otherwise the outdated versions in your node_modules folder are used.

Not yet solved

Changing the version of a package and restarting the webpack-dev-server does not affect the test. The test still uses outdated files from public/packs-test. Removing the folder manually triggers the tests to recompile the assets.

This is the message you see, when tests recompi…

Firefox: Focus-sensitive Selenium tests do not work reliably in parallel test execution

This is a problem when using Selenium with Firefox. We recommend using ChromeDriver for your Selenium tests.

Firefox will not trigger focus/blur events when its window is not focused. While this makes sense in standard usage, it breaks in parallel test execution.

Please do not rely on focus events in your tests. The linked card has an example of how to build passing tests that deal with focus/blur events.


HTML5: disabled vs. readonly form fields

Form fields can be rendered as noneditable by setting the disabled or the readonly attribute. Be aware of the differences:

disabled fields

  • don’t post to the server
  • don’t get focus
  • are skipped while tab navigation
  • available for button, fieldset, input, select, textarea, command, keygen, optgroup, option

Browser specific behavior:

  • IE 11: text inputs that are descendants of a disabled fieldset appear disabled but the user can still interact with them
  • Firefox: selecting text in a disabled text field is no…
3447 cards