Detect if a Javascript is running under Selenium WebDriver (with Rails)

Doing this by the book is super-painful.

You might be better of checking against the name of the current Rails environment. To do this, store the environment name in a data-environment of your <body>. E.g., in your application layout:

%body{'data-environment' => Rails.env}

Now you can say in a piece of Javascript:

if ($('body').attr('data-environment') == 'test') {
  // Code that should happen for Se...

AngularJS directive to format a text with paragraphs and new lines

If you are using Angular and want something like Rails' simple_format which HTML-formats a plain-text input into paragraphs and line breaks, this directive is for you.

Any HTML fragments inside that text will still be escaped properly.

Use it like this, where your text attribute specifies something available in your current scope:

<simple-format text="email.message"></simple-format>

This is the directive, in CoffeeScript syntax:

@app.directive 'simpleFor...

Do not pass an empty array to ActiveRecord.where when using NOT IN

Be careful with the Active Record where method. When you accidentally pass an empty array to the where method using NOT IN, you probably will not get what you expected:

User.where("id NOT IN (?)", [])

Even though you might expect this to return all records, this actually results in this query:

SELECT `users`.* FROM `users` WHERE (id NOT IN (NULL)) 

This will not return anything.

Ruby: How to camelize a string with a lower-case first letter

If you want to do JavaScript-style camelization, ActiveSupport's String#camelize method can actually help you out. Simply pass a :lower argument to it.

>> 'foo_bar_baz'.camelize
=> "FooBarBaz"
>> 'foo_bar_baz'.camelize(:lower)
=> "fooBarBaz"

Where is that rake task defined?


rake -W [substring_of_task]
External content

Heartbleed test

Enter the hostname of a server to test it for CVE-2014-0160.


Javascript: Compare two arrays for equality

Don't Google this, you will lose all will to live. Instead use Object#isEqual from Underscore.js:

_.isEqual([1, 2], [2, 3]) // => false

assignable_values 0.9.0 supports virtual attributes

Now you can say:

class Song < ActiveRecord::Base

  attr_accessor :virtual_attribute
  assignable_values_for :virtual_attribute do
    %w[air fluff]


How to stub class constants in RSpec

Hint: There's another card with this helper for Cucumber features.

Sometimes you feel like you need to stub some CONSTANT you have defined in an other class. Since actually constants are called constants because they're constant, there's no way to easily stub a constant.

Here are three solutions for you.

Easiest solution

Rethink! Do you really need CONSTANT = %w[foo bar] to be constant? In many cases, setting it as a sim…

Auto-destruct in 50 days

Spreewald 0.9.6 has been released

  • The "I wait for the page to load" step now no longer uses wait_until which had been removed since Capybara 2.0.
  • You can now also rake all:rubies using rbenv.

Listening to bubbling events in Prototype is easy

If you come across an (older) application that is using Prototype instead of jQuery, you may often see events bound to single elements only, like this:

$('foo').observe('change', updateThings);
$('bar').observe('change', updateThings);
$('baz').observe('change', updateThings);

If you are calling only one method in each case, this is unnecessarily ugly. Also, when your page contents have been replaced via AJAX (like sections of a form after choosing something), those event hooks will no longer wo…

External content

The Heartbleed Bug

The Heartbleed Bug is a serious vulnerability in the popular OpenSSL cryptographic software library. This weakness allows stealing the information protected, under normal conditions, by the SSL/TLS encryption used to secure the Internet.

External content

Customize and download · Bootstrap

List of variables used in Bootstrap. Overwrite to customize your bootstrap application.

When you are using bootstrap-sass, simply replace @ by $.

Linux: How to print PDF files from the command line

Sometimes you may want to print files from the command line, especially when you have lots of them.

It's actually pretty simple:


Your printer's name is then one you defined on your system. You can check with your CUPS configuration by visiting http://localhost:631/printers.

So, for example:

lp -d Brother-MFC-9840CDW *.pdf

It should work with other file formats than PDF, too, but I have not tried that yet.


AppArmor in Linux

This note is to remember that there is something called AppArmor that could cause weird errors ("File not found", "Can't open file or directory", …) after configuration changes, e.g. when changing MySQL's data directory.

Remember to have a look at AppArmor's daemon configuration (usually at /etc/apparmor.d/) if you change daemon configuration and run into errors such as the one above.

External contentRepeats

Github Cheat Sheet

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

Test whether Perfect Forward Secrecy (PFS) is enabled on a server (using OpenSSL)

Use the following command to test if a server (in this example: on port 443) uses Perfect Forward Secrecy (PFS):

openssl s_client -connect -cipher ECDHE-RSA-RC4-SHA

You should see something like the following:

~ > openssl s_client -connect -cipher ECDHE-RSA-RC4-SHA
depth=1 O = AlphaSSL, CN = AlphaSSL CA - G2
verify error:num=20:unable to get local issuer certificate
verify return:0
Certificate chain
 0 s:/C=DE/OU=Domain Control Va...

How to overwrite and reset constants within Cucumber features

In order to save the original value of a constant, set the new value and restore the old value after a scenario was completed, you can use the following helper. It takes care of saving the old constant value, setting the new one without throwing warnings and resets the value with an After hook.

This module also enables you to introduce new global constants. Since these newly defined constants do not have any value to be reset to, they simply are deleted (remove_const) once the respective Cucumber step finishes.

You can copy the file at…

2392 cards