Prevent SSH from timing out

SSH sessions can drop when idle or behind network devices. Keepalives such as ServerAliveInterval and ServerAliveCountMax help prevent disconnects.

Using the full power of have_css

Capybara has_css? can assert selector counts and text content, including substring matches; exact text requires finding the element and comparing it directly.

apotonick's hooks at master - GitHub

Hooks lets you define hooks declaratively in your ruby class. You can add callbacks to your hook, which will be run as soon as you run the hook.

Even with bundler your gem order can be significant

Gem loading order in a Gemfile can still matter with Bundler when gems require application classes or each other during load, and Rails may fail to boot.

An obscure kernel feature to get more info about dying processes

This post will describe how I stumbled upon a code path in the Linux kernel which allows external programs to be launched when a core dump is about to happen. I provide a link to a short and ugly Ruby script which captures a faulting process, runs gdb to get a backtrace (and other information), captures the core dump, and then generates a notification email.

Inline if-then-else in MySQL queries

It can be useful to have a Ruby expression like condition ? positive_case : negative_case in MySQL queries:

UPDATE users SET monthly_debit = IF(subscriber, 19, 0)

Precedence of Ruby operators

Ruby operator precedence determines how expressions bind, affecting arithmetic, comparisons, assignments, and logical conditions when parentheses are omitted.

Generate a strong secret from the shell

Strong secrets for sessions and secret_key_base can be generated from the shell with apg or bin/rails secret.

Taking advantage of RSpec's "let" in before blocks

before :each blocks can use let values declared later, enabling per-context setup without predeclaring variables; local variables inside it blocks do not work.

jsmestad's pivotal-tracker at master - GitHub

Ruby gem that provides an AR-style interface for the Pivotal Tracker API.

Install the Paperclip gem on Ubuntu servers

Paperclip gem builds on Ubuntu only after ImageMagick and RMagick Ruby packages are installed.

Pay attention to the order of your submit buttons

If you have several submit elements (inputs or buttons with type="submit") that each cause different things to happen (e.g. you might have a button that sends an extra attribute) you might run into trouble when submitting the form by pressing the return key in a field.

When nothing fancy like a tabindex is defined it seems as if the first submit element inside a form is chosen (and has its attributes submitted) when pressing return.\
So, if possible, put your "default" (aka least harmful) submit element before others.

NB: If you s...

Using state_machine events within a resource_controller

If you need to call a state_machine event and do not want to re-define resource_controller's create method, try this:

create.before do
  object.state_event = :launch_spaceship
end

Kill a dead SSH shell

If a SSH shell dies (from timeout for example), you cannot kill it with the usual CTRL-C or CTRL-Z. Instead, press
[ENTER]~.
(That is ENTER TILDE PERIOD).

Sun Java JVM/JRE on Ubuntu Linux

Install Oracle or Sun Java on Ubuntu, remove OpenJDK for better RubyMine performance, and switch the default java version when multiple JVMs are installed.

Reload the page in your Cucumber features

Reloading a GET page in Cucumber can preserve query parameters during feature tests. Capybara and Webrat variants use the current request data to revisit the same URL.

Replace substrings in Cucumber step argument transforms

Substring transforms in Cucumber must return the full matched string, or surrounding characters get lost and steps may match incorrectly.

The WordCount Simulation

So this is the simulation that I use in my Agile Testing class, as well as in other contexts where I want to teach lessons about increasing Agility. The mechanics of the simulation itself are very general: the simulation models the organization of a software company. It just happens to work really well for making Agile concepts very visible, and visceral.

RSpec's context method is broken

RSpec's context name can collide with application methods and trigger missing description errors. Renaming the method or using describe avoids the conflict.

Places where cron jobs can hide

Cron tasks may be stored in system files or in each user's personal schedule, so hidden automation can be hard to spot when investigating background activity.

Delete from joined MySQL tables

MySQL deletion with joined tables requires naming the target table explicitly, such as deleting posts via a join to authors.

Fixing Web Fonts, A Case Study

Some web fonts with bad hinting can be fixed by applying auto-hinting with Font Squirrel.

Save ActiveRecord models without callbacks or validations (in Rails 2 and Rails 3)

Persist ActiveRecord records directly when callbacks and validations are unnecessary; Rails 2 has create_without_callbacks and update_without_callbacks, while Rails 3 needs sneaky-save.

Fix permissions of temporary RTeX files (which are group and world-readable)

We use RTeX for PDF exports.
While converting LaTeX to PDF, RTeX opens a temporary file which has problematic permissions: Both group and world can read those files.

Although the temp files should go away they sometimes live longer than one would expect.
We patched RTeX to fix this (and have more secure permissions). Place the code below into config/initializers/rtex.rb