Never use SET GLOBAL sql_slave_skip_counter with a value higher than 1

If you have a replication error with MySQL and you know the "error" is okay (e.g. you've executed the same statement at the same time on 2 masters which sync each other), you can skip this error and continue with the replication without having to set up the slave from the ground up.

stop slave;
set global sql_slave_skip_counter = 1;
start slave;

But what if you have multiple errors which you want to skip? (e.g. you've executed multiple statement at the same time on 2 masters which sync each other)
Still do not use a value highe…

Error "undefined method last_comment"

This error message may occur when rspec gets loaded by rake, e.g. when you migrate the test database.

NoMethodError: undefined method 'last_comment' for #<Rake::Application:0x0055a617d37ad0>

Rake 11 removes a method that rspec-core < 3.4.4 depends on. To fix, lock Rake to < 11 in your Gemfile:

  gem 'rake', '< 11', # Removes a method that rspec-core < 3.4 depends on

Ruby: Natural sort strings with Umlauts and other funny characters

Why string sorting sucks in vanilla Ruby

Ruby's sort method doesn't work as expected with German umlauts:

["Schwertner", "Schöler"].sort
=> ["Schwertner", "Schöler"] # you probably expected ["Schöler", "Schwertner"]

Also numbers in strings will be sorted character by character which you probably don't want:

["1", "2", "11"].sort
# => ["1", "11", "2"] # you probably expected ["1", "2", "11"]

Also the sorting is case sensitive:

["a", "B"].sort
# => ["B", "a"] # yo...
Auto-destruct in 5 days

Updated: Git stash: Working with old Entries

Partial stash pop

Sometimes you only want to pop parts of the stash. Do this the way vice versa:

git stash pop
git stash -p # Now move all the unnecessary parts back into the stash

eventmachine 1.0.3 failing to install native extensions

Try updating to 1.0.4 right in the Gemfile.lock.


Google Analytics: Change the tracked URL path

By default, Google Analytics tracks the current URL for every request. Sometimes you will want to track another URL instead, for example:

  • When an application URL contains a secret (e.g. an access token)
  • When you want to track multiple URLs under the same bucket
  • When you want to track interactions that don't have a corresponding URL + request (e.g. a Javascript button or a PDF download)

Luckily the Analytics code snippet allows you to freely choose what path is being tracked. Simple change this:

ga('send', 'pageview');

… to th…


Changing versions of Rubygems and Bundler on the server

When you are changing the version of Rubygems or Bundler on a system where you've bundled into a specific directory (which is mostly the case on an application server), remember to wipe that bundle directory in addition to the user and system gems. This is required because deploying again will not overwrite the shared cached gems.

Reason is, the binaries included in your gems are turned into binstubs by Rubygems and thus implicitly rely on a certain Rubygems version. Especially when downgrading Rubygems, this may lead to issues.



Rails index route for resources named after uncountable substantives

Using uncountable resources is not recommended as it breaks Rails' magic, e.g. when using form_for. You'll always be better off using simple pluralizable resources.

Rails automatically creates path names for routes defined via the resource method. When you put resource 'user' into config/routes.rb, you can call users_path and get the path to the index action in the UsersController: /users.

However, if you have an uncountable resource like Sheep, you cannot access the index action via sheep_path, because it will…

External contentAuto-destruct in 10 days

New site for Unpoly: The unobtrusive JavaScript framework for server-side applications

Unpoly has a new website!

Aside from a shiny new frontpage, we now have a tutorial for new users. API docs have been restructured and are easier to navigate.

How to install guard-livereload 2.5.2 on Ruby < 2.2.5

There are some inconvenient Gem dependencies. Resolve them by adding/modifying these lines in your Gemfile:

  gem 'guard-livereload', '>= 2.5.2', require: false # Fixes a security issue
  gem 'listen', '< 3.1' # 3.1 requires Ruby 2.2.5

It is not possible to install guard-livereload 2.5.2 on Ruby 1.8.7 because it depends on guard 2.8, which requires Ruby 1.9.

Auto-destruct in 5 days

Updated: Micro clearfix mixin for Sass

Updated the recommended clearfix.

We should clear with display: block instead of display: table. This will enable collapsing margins for non-floating children of the clearing container.


Micro clearfix mixin for Sass

Clearfix is a hack to clear floating elements without additional HTML markup.

If you only need to support IE8 and above, a great clearfix with few side effects is:

    content: ""
    display: block
    clear: both

This is a Sass mixin.

Issues clearing with display: table

You will find many clearfix solutions that clear with display: table instead:

    content: ""
    display: table
    clear: both

The problem with th…

Ruby 1.8.7: Bundler crashes with "deadlock" and core dump


deadlock 0x7f8a4160a360: sleep:- (main) - /home/me/.rbenv/versions/1.8.7-p375/lib/ruby/gems/1.8/gems/bundler-1.14.3/lib/bundler/worker.rb:43
deadlock 0x7f8a38c03b08: sleep:-  - /home/me/.rbenv/versions/1.8.7-p375/lib/ruby/gems/1.8/gems/bundler-1.14.3/lib/bundler/worker.rb:56
*** longjmp causes uninitialized stack frame ***: /home/me/.rbenv/versions/1.8.7-p375/bin/ruby terminated

… followed by a backtrace, memory map and more.


The culprit seems to be Bundler 1.14 when used with Ruby 1.8.7. [Downgrade to the maximu…

RSpec matcher to check if two numbers are the same

You can usually just use the eq matched to compare two numbers:

expect( eq(120)

If the actual value is a BigDecimal, you might have issues when you match it against a Float:

expect(deal.total_price).to eq(1200.99)

In these cases, try matching it against another BigDecimal:

expect(deal.total_price).to eq BigDecimal(1200.99)

If you don't like the syntax, our rspec_candy gem has a matcher that will compare Fixnums (integers), Floats and `BigDecima…

External contentAuto-destruct in 7 days

Unpoly 0.33 and 0.34 released


Compatible changes

  • When a fragment updates cannot find the requested element, you can now define a fallback selector to use instead.

    A { fallback } option has been added to all Javascript functions that update fragments, like up.replace().

    Also an [up-fallback] attribute has been added to all CSS selectors that update fragments, like for a[up-target].

    You can also define fallbacks globally using the [up.dom.config](…


Geordi hints

Reminder of what you can do with Geordi.

Note: If you alias Geordi to something short like g, running commands gets much faster!
Note: You only need to type the first letters of a command to run it, e.g. geordi dep will run the deploy command.

geordi deploy
Guided deployment, including push, merge, switch branches. Does nothing without confirmation.
geordi capistrano
Run something for all Capistrano environments, e.g. geordi cap deploy
geordi setup -t -l staging
When you just cloned a n…

JSONP for Rails

The rack-contrib gem brings a JSONP middleware that just works™. Whenever a JSON request has a callback parameter, it will wrap the application's JSON response appropriately.

The project is a bit dated, but the JSONP middleware is ok.


Coffeescript: Caveat when cloning objects with fat-arrow methods

Coffeescript allows you to create classes whose methods are automatically bound to the correct this. You can do this by using a fat arrow:

class Person

  constructor: (name) ->
    @name = name

  sayHello: =>
    alert("Hello, I am #{@name}")

An important caveat is that when you clone such an object, all of its methods are still bound to the original instance:

eve = new Person("Eve")
eve.sayHello() # => "Hello, I am Eve"
bob = _.clone(eve) = "Bob"
bob.sayHello() # => "Hello, I am Eve"

I don't thin…

3267 cards