Puppet 3.x: Convert a float to an integer

There is no built in possibility to convert a float to an integer. You have to use an inline_template

inline_template('<%= @someFloat.to_i %>')

Hints for debugging MySQL InnoDB deadlocks

Deadlocks only occur if two transactions in separate threads compete for the same rows in the database. They usually (but not necessarily) only happen when trying to update or otherwise lock several rows in different order.

Solving deadlocks is potentially complicated, so here are a few pointers:

  • MySQL should always detect the deadlock right when it happens, and will throw an error to one of the offending threads. This error states the SQL statement that this thread was currently waiting for, and that tried to acquire one of the competin…

Rails: How to get PostgreSQL version being used

To check the currently running PG version from your Rails application (e.g. Rails console on your production server), simply do this:

ActiveRecord::Base.connection.select_value('SELECT version()')
External contentRepeats

7 Rules for Creating Gorgeous UI

A great two-part article about various hacks you can use to create great-looking screen designers when you're not a designer.

Part 1 contains:

  • Light comes from the sky
  • Black and white first
  • Double your whitespace

Part 2 contains:

  • Learn the methods of overlaying text on images
  • Make text pop— and un-pop
  • Only use good fonts
  • Steal like an artist

Redis Sentinel manual failover

  1. Connect to your sentinel instance:

    redis-cli -p <SENTINEL-PORT>
  2. Have a look at the current master and the available slaves

    SENTINEL masters
    SENTINEL slaves <master name>
  3. Force a failover

    SENTINEL failover <master name> 
  4. After some seconds you can have a second look at the current master:

    SENTINEL masters

    The IP should have changed.

FactoryGirl: Passing attributes to associated records using transient attributes

FactoryGirl.define do

factory :parent do
transient do
child_name nil
child_allowed_to_drive false

child do
  create(:child, name: child_name, allowed_to_drive: child_allowed_to_drive)
end   end

factory :child do
name 'Child'
allowed_to_drive false



daughter = FactoryGirl.create(:parent, child_name: 'Lisa').child # => 'Lisa'
daughter.allowed_to_drive? # => false

son = FactoryGirl.create(:parent, child_name: 'Benedikt', child_allowed_to_drive: true…

Browsers have built-in pretty printing for JSON

This pretty-prints a JSON object, with two spaces of indentation:

JSON.stringify(object, null, 2)

Popular mistakes when using nested forms

Here are some popular mistakes when using nested forms:

  • You are using fields_for instead of form.fields_for.
  • You forgot to use accepts_nested_attributes in the containing model. Rails won't complain, but nothing will work. In particular, nested_form.object will be nil.
  • The :reject_if option lambda in your accepts_nested_attributes call is defined incorrectly. Raise the attributes hash given to your :reject_if lambda to see if it looks like you expect.
  • If you are nesting forms into nested forms, each model involved ne…

Your browser might silently change setTimeout(f, 0) to setTimeout(f, 5)

When you're nesting setTimeout(f, 0) calls, your browser will silently increase the delay to 5 milliseconds after the fourth level of nesting. This is called "timeout clamping".

Deeply nested setTimeout can happen when you're using a non-native Promise polyfill with long chains of then calls.
The native Promise implementation (Can I use link) uses microtasks and is thus not subject to timeout cla…


Imagemagick: Batch resize images

Trick: Do not use convert but mogrify:

mogrify -resize 50% *

This overwrites the original image file.

In contrast, convert writes to a different image file. Here is an example if you need this:

cd /path/to/image/directory
for i in `ls -1 *jpg`; do convert -resize 50% $i "thumb_$i"; done

Middleman does not fingerprint asset paths by default

We're using Middleman for some static sites like our blog.

Despite being very similar to Rails, Middleman does not add a fingerprint hash to its asset paths by default. This means that when you write this:

<%= javascript_include_tag 'all.js' %>

… you always get the same path, regardless of the contents of all.js:

<script src='/javascripts/all.js'>

Because browsers tend to cache assets for a while, this means that users might not get your changes until their cac…


What edge_rider gives you

edge_rider is Power tools for ActiveRecord relations (scopes). Please note that some of the functions edge_rider provides have native implementations in newer rails versions.


Edge Rider gives your relations a method #traverse_association which returns a new relation by "pivoting" around a named association. You can traverse multiple associations in a single call. E.g. to turn a relation of posts into a relation of all posts of their authors:



Detect the language of a string

You can use the whatlanguage gem to detect the language of a Ruby string.
Note that it also has not been updated in quite a while and that there might be alternatives. However, it still works.

It has problems with short strings, but works quite well on longer texts.

Use it like this:

>>'Half the price of a hotel for twice the space')
=> :english

There is also a convenience method on Strings (you may need to require 'whatlanguage/string').

>> 'Wir ent...

Ruby: __FILE__, __dir__ and symlinks

Ruby's __FILE__ keyword returns the path to the current file. On popular for this are Ruby binaries:

#!/usr/bin/env ruby
$LOAD_PATH << File.expand_path(__FILE__, '../../lib')
require 'my_cli'!

However, if you create a symlink to this file, this will no longer work. __FILE__ will resolve to the path of the symlink, not to its target.

One solution is to use File.realpath(__FILE__).

In Ruby 2+ you can also use this:

$LOAD_PATH << File.expand_path(__dir__, '../lib')

__dir__ is simply a shortcut for `Fi…


Angular: Understanding how parent and child scope meet on a directive declaration

This cards needs to be rewritten.

Say you have the following markup:

{{ someParentVariable = 42 }}

<child var="{{ someParentVariable }}" ng-click="foo()">
  {{ var }}

Any angular expression on the child element will be evaluated
before child is initialized. Hence, {{ }} is always evaluated in the
parent scope. will be "42" inside the child directive
(as a string, because HTML attributes are always strings).

scope: true

If the child directive sets scope:true, a new …

External contentAuto-destruct in 47 days

Unpoly 0.29.0 released


Compatible changes

  • up.popup.attach now has a { html } option. This allows you to extract popup contents from a HTML string without making a network request.
  • Fix a bug on Firefox where the page width would jump by the scrollbar width when opening a modal.
  • Fix a bug where modals would close when following a link to a cached destination.

Breaking changes

  • Events handled by Unpoly selectors will no longer bubble up the DOM.


Compatible changes

  • [`up.t…
External contentRepeats

How Googlebot Crawls Javascript

Google seems to have made some progress with indexing Javascript-heavy sites.

Note that we haven't verified any of this. Also there are other important search engines than Google, especially outside of Germany/Europe.

External contentAuto-destruct in 47 days

Unpoly 0.28.0 released


Compatible changes

  • The error notification is now easier to read and can be closed.
  • When a target selector was not found in the response, the error notification now offers a link to re-request the response for inspection.
  • Compilers can now return an array of functions that will all be called when the element is destroyed.
  • up.observe now works on checkboxes and radio buttons.
  • up.observe can now be called with multiple form fields, or any container that contains f…
3162 cards