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.

Howto remove the location hash without causing the page to scroll

Set the hash to a dummy hash which doesn't hit any id at your page, for example: window.location.hash = "_";


  • If you'd set the hash to "" it causes the page to scroll to the top because the hash "#" by itself is equivalent to "_top".
  • If you'd set window.location.href = "..." to get rid of the "#", you cause the browser to reload the page what is most likely not intended.

Active Record's select method allows you to make use of the power of MySQL select statements. On the one hand it allows you to select specific fields."content")

results in the following query:

"SELECT content FROM `posts`"

This means that your models will be initialized with only the content attribute and you will not be able to access any other attribute. In fact trying so would raise an ActiveRecord::MissingAttributeError error."content").first.title # => ActiveRecord::MissingAttributeErr...

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")


How to inspect XML files in a terminal

You can use xmllint to pretty-print ugly XML files on your terminal. Just say:

xmllint --format file.xml

That will restructure containers nicely into individual sections with proper indentation.\
Note that it will automagically work on gzipped XML files!

To write pretty output to a new file, just use the -o switch (short for --output):

xmllint --format file.xml -o pretty_file.xml

See the xmllint man page for other useful switches and more information.

External content

Riding Rails: Rails 4.0: Final version released!

Rails 4.0 is finally ready after a thorough process of betas and release candidates. It's an amazing new version packed with new goodies and farewells to old features past their expiration date.

Help me, there is a zombie process!

Here is a good explanation for zombie processes.


If you have zombie processes it means those zombies have not been waited for by their parent (look at PPID displayed by ps -l). 
You have three choices: Fix the parent process (make it wait); kill the parent; or live with it.
Remember that living with it is not so hard because zombies take up little more than one extra line in the output of ps.

On a server I want to get informed if there are zombie processes and track them wi…

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 ...
External content

How I Explained REST to my Wife

A great and enjoyable introduction into the concept of the web and about what HTTP was designed for. The original post has been removed for some stupid gender discussion.

Upgrading Rails 2 from 2.3.8 through 2.3.18 to Rails LTS

This card shows how to upgrade a Rails 2 application from Rails 2.3.8 through every single patch level up to 2.3.18, and then, hopefully, Rails LTS.

2.3.8 to 2.3.9

This release has many minor changes and fixes to prepare your application for Rails 3.

Step-by-step upgrade instructions:

  1. Upgrade rails gem
  2. Change your environment.rb so it says RAILS_GEM_VERSION = '2.3.9'
  3. Change your environment.rb so all invocations …
External content

asciidisco/Backbone.Mutators · GitHub

Backbone plugin to override getters and setters with logic.

3474 cards