How to type accented characters on keyboard layouts without dead keys

Ubuntu comes with keyboard layouts like "Germany Eliminate Dead Keys", which are practical for programming.

If you need to type accented characters with such a layout, make sure to configure a Compose key. You can then look up which compose combo will produce the character you need.

E.g. you can type "á" by pressing Compose, ´, a.

Rails 3: Make "link_to :remote => true" replace HTML elements with jQuery

In Rails 2, you could use link_to_remote ... :update => 'id' to automatically replace the content of $('#id').

To do the same in Rails 3, include usual rails-ujs JavaScript, and put this into your application.js:

$(function() {
  $('[data-remote][data-replace]')
    .data('type', 'html')
    .live('ajax:success', function(event, data) {
      var $this = $(this);
      $($this.data('replace')).html(data);
      $this.trigger('ajax:replaced');...

Fix for: Your Firefox profile cannot be loaded. It may be missing or inaccessible.

If you use Selenium and Launchy to open web pages, you might run into an error saying "Your Firefox profile cannot be loaded. It may be missing or inaccessible.".

This happens because Launchy tries to use your Firefox running the web driver to open the page.

For Launchy < 0.4.x, as a workaround you can set an environment variable

export LAUNCHY_BROWSER=`which google-chrome`

For newer Launchys you also need to set:

export BROWSER=`which google-chrome`

If you want to do this in a ruby script, you can say

chrome_path ...

RSpec 2.6 supports "any_instance" now

This finally works:
User.any_instance.should_receive(...)
as does
User.any_instance.stub(...)

Note: You won't have RSpec 2.6 if you're still working on Rails 2.

Hex color codes for the CGA palette

Below you can find the hex color codes for the Color Graphics Adapter palette which used to be popular in the 1980s.

$cga_black: #000000
$cga_white: #ffffff
$cga_light_gray: #aaaaaa
$cga_dark_gray: #555555
$cga_yellow: #ffff55
$cga_brown: #aa5500
$cga_light_red: #ff5555
$cga_dark_red: #aa0000
$cga_light_green: #55ff55
$cga_dark_green: #00aa00
$cga_light_cyan: #55ffff
$cga_dark_cyan: #00aaaa
$cga_light_blue: #5555ff
$cga_dark_blue: ...

Virtual attributes for date fields

Note that this card is very old. You might want to use ActiveType for your auto-coerced virtual attributes instead.


We sometimes give our models virtual attributes for values that don't need to be stored permanently.

When such a virtual attribute should contain Date values you might get unexpected behavior with forms, because every param is a string and you don't get the magic type casting that ...

How to remap your caps lock to a second Escape key

When have you last used your caps lock key? On purpose? Right...

In Gnome

Make it an additional ESC key by going to System -> Preference -> Keyboard -> Layouts -> Options -> CapsLock key behavior and select "Make CapsLock an additional ESC".

On recent Ubuntus this option was removed so you have to resort to using dconf.

dconf write /org/gnome/desktop/input-sources/xkb-options "['caps:escape']"

Or, open Tweak advanced GNOME 3 settings and ...

url_for with added params

You cannot say this because url_for only takes one parameter:

url_for(@deal, :tab => 'general') # won't work

Just use polymorphic_url instead:

polymorphic_url(@deal, :tab => 'general')

Shell script to generate a Git commit with Pivotal Tracker story ID and title

We usually generate our commit messages from Pivotal Tracker IDs and titles, like
[#15775609] Index view for conflicts

The geordi command commit automates this. (See: Pretty Commit messages via geordi).

Just run geordi commit and it will connect to PT and let you select from a list of all started and finishes stories. Then it runs git commit with the generated message (i.e. all staged changes will be commited).

When running for the first time, Geordi will request your PT...

Fix "private method `select' called for Capybara::Node::Element

API breakage ahoy. You need to either upgrade your Capybara or downgrade your selenium-webdriver gem.

Alternatively, this could solve your trouble.

Edit your previous Skype messages

Just in case you did not know it: If you sent a Skype message containing a typo, you don't need to send a second one to correct yourself.

Instead, simply press the up key (). The message area will become yellow and contain your previously sent message. Make any changes and submit again.\
You can also right-click any other message (of the current session) to edit it.

Linux: Create file of a given size

Sometimes you need a file of some size (possibly for testing purposes). On Linux, you can use dd to create one.

Let's say you want a 23 MB file called test.file. You would then run this:

dd if=/dev/zero of=test.file bs=1048576 count=23

The block size (bs) is set to 1 MB (1024^2 bytes) here, writing 23 such chunks makes the file 23 MB big.\
Adjust to your needs.

This linux command might also come in handy in a Ruby program. It could be used like:

mb = 23
mb_string, _error_str, _status = Open3.capture3('dd if=/dev/zero...

Running the Awesome window manager within Gnome

Note: Consider using MATE instead of Gnome 3 on newer system

Awesome is a very good tiling window manager that provides neat features like automatic layouting of windows, good multi-display support with per display workspaces and more. Unfortunately, it is only a window manager, and lacks a lot of Gnome's conveniences like the network manager, application menus, automatic updates etc.

Fortunately, Gnome allows you to selectively replace only the window manager, so you get all of Gnome'...

How to enlarge a VirtualBox VDI disk file

VirtualBox does not offer anything for this task -- you need to do it yourself. It's not that hard:

Get more disk space

  1. Add an extra virtual hard disk to the machine with the disk size you want to achieve.
  2. Get a Linux live CD (like the Ubuntu live image) that offers fdisk, dd and gParted.
  3. Boot the guest from the CD, open a terminal (on the guest, not the host!) and become root: sudo su
  4. fdisk -l to see the disk information. \
    There should be one drive with some partitions and one without any....

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://...