Rails: Disable options of a select field

Simply give the select helper an option :disabled, passing either a single value or an array. You need to specify the option's value, not its text.

= :country, Address.countries_for_select, :include_blank => true, :disabled => ['disabled-value1', 'disabled-value-2']

Also see Cucumber: Check if a select field contains a disabled option on how to test this.

exception_notification 4.0.0+ makes it easier to ignore errors, crawlers

The new exception_notification has awesome options like :ignore_crawlers => true and :ignore_if => lambda { ... }. These options should be helpful in ensuring every notifications means something actionable (instead of a long log of failures that just scrolls by).

Note that you should not ignore crawlers by default. Ideally, cool URLs never change and always respond with a helpful redirect or similar.

Ignore Errors like this:

# config/initializers/exception_notification.rb


External content

The Chokehold of Calendars

Most people don’t schedule their work. They schedule the interruptions that prevent their work from happening.

External content

Cryptic Ruby Global Variables and Their Meanings

The linked page lists and explains global Ruby "dollar" variables, such as:

  • $: (load path)
  • $* (ARGV)
  • $? (Last exit status)
  • $$ (PID)
  • $~ (MatchData from last successful match)
  • …and many more you'll need when reading weird code.


  • $~ (last MatchData)
  • $1 $2 $3 $4 (match groups from the last pattern match)
  • $& (last matched string)
  • $+ (last match group)
  • $` (the string before the last match)
  • $' (the string after the last match

See [this extensive list of variables](http://www.tu…

Bash: How to generate a random number within given boundaries

$RANDOM on bash returns a random integer between 0 and 32767.

echo $RANDOM
echo $RANDOM

If you want to limit that to a certain maximum, you can just compare against the modulus of that maximum + 1. \
For example, the following will yield results between 0 and 9:

echo $(($RANDOM % 10))
echo $(($RANDOM % 10))

Note that this skews random numbers to the lower regions of your boundaries in most cases.

iOS 5 "position: fixed" and virtual keyboard issues

The ipad onscreen keyboard changes position:fixed style to position:static that misplaces those elements and you'll have problems on each page with a form, e.g. search field.

There are several workarounds/hacks but no straight forward fix yet. Expect additional expense.

Cucumber: Check if a select field contains a disabled option

For Capybara, use this step:

Then /^"([^"]*)" should be a disabled option for "([^"]*)"(?: within "([^\"]*)")?$/ do |value, field, selector|
  with_scope(selector) do
    field_labeled(field).find(:xpath, ".//option[text() = '#{value}'][@disabled]").should be_present

RubyMine detects syntax errors where there are none

To make this go away I had to wipe my RubyMine settings (~/.RubyMine) and configure everything again. Fun.

Consul 0.9 lets you optimize records checks

Consul 0.9 comes with many new features to optimize powers that only check access to a given record. e.g. See below for details.

Powers that only check a given object

Sometimes it is not convenient to define powers as a collection. Sometimes you only want to store a method that
checks whether a given object is accessible.

To do so, simply define a power that ends in a question mark:

class Power

  power :upd...

Short lambda syntax in Ruby 1.9

Ruby 1.9 brings a shorter way to define lambdas using the -> operator:

twice = -> (x) { 2 * x } # => 10

This is equivalent to:

twice = lambda {|x| 2 * x } # => 10

Note that the syntax is subtly different from Coffeescript where you define function parameters before the arrow: (x) -> { 2 * x }.

ActionView::Template::Error (dump format error for symbol(0x6d))

I recently encountered the error above when I was running selenium tests.

Thanks to a post on stackoverflow I found out that clearing all files in tmp/cache in my project folder made the issue go away.

Batch-process text files with ruby

Did you know you can do in-place batch processing with plain ruby?

The following script will in-place replace "foo" with "bar" in all files you feed it. Call it with ./my_script path/to/my/files/* #!ruby -i -p $_.gsub!(/foo/, "bar")

"'-i -p" means:

Ruby will run your script once for each line in each file. The line will be placed in $_. The value of $_ at the end of your script will be written back to the file.


Using the Kernel#gsub shorthand for $_.gsub!: #!ruby -i -p gsub(/foo/, "bar")


exception_notification 3.0.0+ lets you send errors as HTML e-mails

Exception notifications contain a lot of information: Backtraces, HTTP headers, etc. exception_notification tries its best to format this wall of information using ASCII art, but you can also make it send those notification as simple HTML e-mails that have some simple formatting for clarity, but no images etc. To do so, activate this option:

:email_format => :html

Those HTML notifications are still delivered with a text-only version, so if you are using a console cli…

External content

Webservice to mock HTTP responses

Sometimes in the course of development you may need to mock HTTP responses.

This is a simple service to return various HTTP responses.

External content

Maker's Schedule, Manager's Schedule

One reason programmers dislike meetings so much is that they're on a different type of schedule from other people. Meetings cost them more.

Do not try to "slice" on an ActionController::CookieJar

The cookies object in your controllers and views is a ActionController::CookieJar and even though that class inherits from Hash and often behaves like one, you can not call slice on it to select only a subset of cookies. Why? Because Hash#slice calls – which in case of a CookieJar just won't work.

Unfortunately, you can't even say cookies.to_hash and slice on that, just because CookieJar#to_hash is inherited from Hash and will just return self. Bummer.

You need to do it yourself, for example by usin…

Switch to a recently opened tab with Cucumber

Similar to closing an opened browser window, spreewald now supports the I switch to the new tab step.

You can use it to test links that were opened with a link_to(..., :target => '_blank') link or other ways that create new tabs or windows.

Note: Works only with Selenium.

List keys stored in memcached / Amazon AWS ElastiCache server

Connect to your memcached host. (AWS elasticache is memcached)

telnet 11211 

Once you're connected, find out which 'slabs' exist within the cache:

stats items
STAT items:1:number 3550
STAT items:1:age 5166393
STAT items:1:evicted 0
STAT items:1:evicted_nonzero 0
STAT items:1:evicted_time 0
STAT items:1:outofmemory 0
STAT items:1:tailrepairs 0
STAT items:1:reclaimed 0
STAT items:2:number 144886
STAT items:2:age 1375536
STAT items:2:evicted 0 ...
3447 cards