View
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.

Regex

  • $~ (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
9816
echo $RANDOM
30922

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))
5
echo $(($RANDOM % 10))
9

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 = "_";

Note

  • 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.

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. Power.current.post?(Post.last). 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 }
twice.call(5) # => 10

This is equivalent to:

twice = lambda {|x| 2 * x }
twice.call(5) # => 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.

Shorter

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

S…

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.

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 self.class.new – 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 foohost23.cs2631.0001.euw1.cache.amazonaws.com 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 …
View
3409 cards