Show the status of a running dd copy

When you do a bitwise copy using the dd tool you will not see any output until it completes or an error occurs.
However, you can send a command signal to the process to have it show its progress so far.

From another terminal, simply call (be root or use sudo):

pkill -USR1 dd

This makes dd write something like this into the terminal it is running in:

388+0 records in
387+0 records out
396288000 bytes (396 MB) copied, 24.9862s, 15.9 MB/s

Disable Thumbs.db on Windows 7

Every time you open a directory containing images, Windows creates those pesky Thumbs.db files for a minor speed-up and lots of cluttering your zip files etc.

You do want to disable them. Here is how on Windows 7:

  1. Start → Run (or press Meta+R)
  2. gpedit.msc
  3. User Configuration → Administrative Templates → Windows Components → Windows Explorer
  4. Locate "Turn off the caching of thumbnails in hidden thumbs.db files" (should be one of the top list entries)
  5. Set it to "Enabled". Yes, seriously -- you enable the disabling of thumbs.d...

Check gem dependencies before installation

With gem dependency it is possible to check the dependencies for your gem before you install it.

Here is an example output for Nokogiri:

Gem nokogiri-1.4.4
  hoe (>= 2.6.2, development)
  minitest (>= 1.6.0, development)
  racc (>= 0, development)
  rake-compiler (>= 0, development)
  rexical (>= 0, development)
  rubyforge (>= 2.0.4, development)

Use look-behind assertions in regular expressions with Ruby 1.8

Regular expressions can have something called "zero-width look-behind assertions". This means that you want a pattern to be preceded by another pattern, but not include the preceding pattern in your match or search cursor. E.g. (?<=x)y matches y in xyz but not in syz. There are also negative look-behind assertions, e.g. (?<!x)y matches y in syz but not in xyz.

Unfortunately look-behind assertions are only available in Ruby 1.9. With Ruby 1.8 you need to use an alternative regular expression library called [Oniguruma](http://...

Installing Rails on a fresh system

  1. Install Ruby from the Ubuntu repository: sudo apt-get install ruby ruby-dev \
    ruby is the meta package. If you want to explicitly install 1.8 or 1.9, install ruby1.8 or ruby1.9 instead (the same applies for ruby-dev).
  2. Do not install RubyGems from the repository but install the version from the webpage instead.
  3. Get Bundler: sudo gem install bundler

Rails and other gems for a project should now be installed via bundle install from the...

Disable Dell U2410 beeping sound

The first thing to do with any new U2410 should be to disable the incredibly annoying beep when pressing any monitor button. Here is the fastest way to achieve that:

  • OSD button (above the power button)
  • Menu
  • 2 × Up (You should be at “Other Settings” now)
  • Right
  • 4 × Up (“Button Sound”; the “Power Save Audio” entry is usually grayed out, so this is 1 beep less than from above.)
  • Right
  • Down
  • Tick

Do it this way or your colleagues will stand at your desk after the 12th beep, ready to smack you.

Fix slow specs using SOLR

I've recently encountered a weird problem with specs making lots of SOLR queries using the acts_as_solr plugin: After a certain number of specs, exactly one spec suddenly took over 30 seconds to finish.

It turns out that for some reason, the SOLR server seemed not to close its HTTP connections properly. After the maximum number of connections was reached, the next spec needed to wait for an old connection to time out.

I'm not exactly sure why this happened, why it only seems to be happening in specs and which part of the code is actually...

Getting non-Aero toolbars for Thunderbird 5 on Windows 7

Thunderbird 5 brings a custom chrome on Windows Vista/7 that uses translucent Aero decorations on toolbars and menubars. Here is how to restore solid backgrounds if you don't like it.

Put the following into chrome\userChrome.css in your Thunderbird profile directory:

@namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");
window {
  background-color: -moz-dialog !important;
}

(Re-)start Thunderbird afterwards.


If you need more info on where the userChrome.css is suppose...

Traverse large XML files with Nokogiri

If you need to parse a large XML file (> 20 MB or so), you should parse it in chunks, otherwise it will need lots of memory.

Nokogiri offers a reader that lets you parse your XML one node at a time.

Given an XML library.xml with this content

    <library>
      <book>
        <title>...</title>
        <author>...</author>
      </book>
      <book>
         ...
      </book>
       ...
    </library>

you can for example loop over all books with

    def each_book(filename, &block)
      File.open(filename) do |file|
      ...

Check whether an element is visible or hidden with Javascript

jQuery

You can say:

$(element).is(':visible')

and

$(element).is(':hidden')

jQuery considers an element to be visible if it consumes space in the document. For most purposes, this is exactly what you want.

Native DOM API

Emulate jQuery's implementation :

element.offsetWidth > 0 && element.offsetHeight > 0;

jQuery > 3

Query 3 slightly modifies the meaning of :visible (and therefore of :hidden).

Emulate jQuery'...

console-for opens a Rails console remotely on a Capistrano deployment target

We're adding a script console-for to open a remote Rails console with one command. Also have a look at shell-for, which this script is relying on.

Run it from any project directory like this, passing a Capistrano multistage deployment target:

console-for staging

This script is part of our geordi gem on github.

Be careful when closing expanded stories in Pivotal Tracker

When you open up a story to only have a look at it, close it by pressing the "Cancel" button (or Esc key).

Clicking the arrow in the top left is the same as pressing the "Save" button. If someone changes the story description in the meantime you will overwrite their changes with everything you see, even if you did not change anything. If you only want to take a peek, prefer to hover the speech bubble icon.

If your story gets shotgunned and you notice it, you are lucky -- and you may be able to get your changes back. Open up the his...

Install the SQLite 3 gem for Ruby under Ubuntu

sudo apt-get install sqlite3 libsqlite3-dev
sudo gem install sqlite3-ruby

Test that a string of text is (not) linked in Webrat or Capybara

The step definition below allows you to write:

Then I should see a link labeled "Foo"
But I should not see a link labeled "Bar"

Webrat

Then /^I should( not)? see a link labeled "([^"]*)"$/ do |negate, label|
  expectation = negate ? :should_not : :should
  response.send(expectation, have_selector("a", :content => label))
end

Capybara

Then /^I should( not)? see a link labeled "([^"]*)"$/ do |negate, label|
  expectation = negate ? :should_not : :should
  page.send(expectat...

Using Dropbox on Ubuntu

If you are exchanging files with a client via Dropbox you do not need to access the Web page every time you want to fetch files. Instead, you can fully integrate your Dropbox account(s) into nautilus (Gnome's file manager) with automatic synchronization.

  1. Get the .deb file for your system architecture (32 or 64 bit) from the Linux download page.
  2. Install the downloaded package using either the Gnome integration (double-click it) or the shell, e.g.: `dpkg -i naut...

How to build the perfect number of blank records for a nested form

When you render a nested form for a Movie which has_many :actors, you want to render the right number of blank Actor forms. The right number means:

  • A minimum number of blank forms so the user can add more Actors to an existing Movie, e.g. 2.
  • A minimum total number of forms (both blank and pre-filled) so the user sees more than just 2 blank Actor forms when she is entering Actors for the first time, e.g. 5.

For the example above, this is the desired progression of the number of blank forms:

| Number of actors | Number of ...

Force SSH client to use password authentication instead of public key

To test if you can connect to a host using password authentication and explicitly deny public key authentication:

ssh -o PreferredAuthentications=password -o PubkeyAuthentication=no user@host

This also works for Secure Copy:

scp -o PreferredAuthentications=password -o PubkeyAuthentication=no local.file user@host:/path/to/remote.file

Run Selenium tests in Chrome instead of Firefox

Here is how to switch your Selenium to Chrome:

  1. Make sure you've got a recent version of chromedriver in your $PATH

See also geordi chromedriver_update which is automatically executed before every usage of geordi cucumber.

  1. Register Driver:

Create a file features/support/capybara.rb with the following content for recent version of Capybara:

Capybara.register_driver :selenium do |app|
  Capyb...