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

Change the name of your Ubuntu machine

In order to rename your Ubuntu box, replace all occurences of the the old name in the following two files:

  • /etc/hostname
  • /etc/hosts

After a reboot your hostname is changed. If you don't want to reboot your Ubuntu box you have to execute hostname your.hostname.

Linux: Refer to all arguments of a script call

In shell scripts you can use $1 to refer to the first argument, $2 for the second, etc. If you want to refer to all arguments (e.g. when writing a bash script that takes an arbitrary amount of arguments and passes them on to another call), you may not want to do a “$1 $2 $3 $4 ...”.

Use $@ instead, like in this script:
$ cat welcome
#!/bin/bash
echo Hello to $@

When called, the above would produce this:
$ ./welcome the world and universe
Hello to the world and universe

Note that $@ works for both sh and `ba...

mysqltuner.pl

This Perl script will run diagnostics on your MySQL database and recommend changes to your MySQL configuration.

Hack of the day: A reverse for Rails' &:

Ever wondered if there is a reverse for Rails' .each(&:to_s) idiom? Turns out there is...

You probably already know, that you can abbreviate code like

dogs.each { |dog| dog.bark! }

with

dogs.each(&:bark!)

Now suppose it is the other way round and you have

bones.each { |bone| dog.eat!(bone) }

Good old Ruby already has a solution:

bones.each(&dog.method(:eat!))

Change the timestamp of a file in Ruby

This is somewhat similar to the touch command of Linux:

FileUtils.touch 'example.txt', :mtime => Time.now - 2.hours

If you omit the :mtime the modification timestamp will be set to the current time:

FileUtils.touch 'example.txt'

You may also pass an array of filenames:

FileUtils.touch %w[ foo bar baz ], :mtime => Time.now - 2.hours

Non-existent files will be created.

See which Rails applications are being served by your Passenger

To obtain a list of Passenger processes with their application directories and memory usages, you can say

sudo passenger-memory-stats

This will output a list like this:

----- Passenger processes -----
PID    VMSize    Private  Name
-------------------------------
671    112.9 MB  95.5 MB  Rails: /opt/www/project1/current
707    79.4 MB   60.5 MB  Rails: /opt/www/project2/current
1094   88.1 MB   69.3 MB  Rails: /opt/www/project3/current
1260   81.6 MB   62.6 MB  Rails: /opt/www/project4/current
1269   7...

Force Google Chrome to run in English on Linux

If you need Google Chrome to run in English, and your system locale is a non-English one, you have two options:

  • Switch your system to an English locale
  • Head over to /opt/google/chrome/locales/ and remove any .pak files except those starting with “en”. They reappear when Chrome gets updated.

This may help you running your Selenium tests using the Chrome driver on applications that choose the language from what the browser sends as preferred language (which Chrome guesses from your system locale).

What to do when Google only syncs some of your contacts

When some of your Google contacts are no longer synchronized with your e-mail client or mobile phone, those contacts are not in a group "My Contacts". Google only syncs contacts in that group.

In order to fix this:

  • Open Google Contacts
  • Select all contacts (there's a link)
  • Press "Move to My Contacts"

Note that when you are using Mozilla Thunderbird with the Google Contacts add-on, Thunderbird won't add new contacts into the "My Co...

How to fix: undefined method `specifications' (caused by RubyGems 1.8)

Sometimes, when running a rake task, RubyGems 1.8.5 raises an error:

rake aborted!
undefined method `specifications' for "/usr/lib/ruby/gems/1.8":String

This has been fixed since May 31 but is still not available as a new RubyGems version.

Either wait for a new version to eventually come out, downgrade to some really old version (1.6.2 works for some) or apply the fix manually:

  • Find your rubygems.rb -- mine was located at `/usr/local/lib/sit...

Sanitize filename with user input

If you have to build a filename (e.g. for use in downloads) that contains user input, keep in mind that malicious input might come from users and could lead to security problems.

Instead of blacklisting characters such as / , . \ ´ etc. better go for a stricter approach and use a whitelist such as:

def sanitize_filename(filename)
  filename.gsub(/[^0-9A-z.\-]/, '_')
end

If you need to have German Umlauts you can use /[^\w\-]/. This, however, will only work if the locale is set to German.
You might also want to translitera...

RubyMine crashes Ubuntu 11.04 window decorator on exit

My RubyMine (and it seems like many other Java GUI applications) crashes the Compiz window decorator almost every time on exit. This also seems to happen for the Unity decorator.

Update: The commited fix from below seems to have made it into the stable Ubuntu repository.

Easy mode

You can restore window decorations by executing this command:

gtk-window-decorator --replace &

This is only a temporary fix.

Hard mode

Also, there is a committed fix that is n...

How to use helper methods inside a model

Simple

If you want to use a helper_method my_helper_method inside a model, you can write

ApplicationController.helpers.my_helper_method

When using multiple helpers

delegate :helpers, to: ApplicationController
helpers.my_helper_method
helpers.my_other_helper-method

More flexible

If you need a bit more flexibility, for example if you also need to override some methods, you can do this:

class HelperProxy < ActionView::Base
  include ApplicationController.master_helper_modu...

Unsafe string methods in Rails

When you encouter an unsafe string that you actually made html_safe before, perhaps you called one of the following methods on it:

"capitalize", "chomp", "chop", "delete", "downcase", "gsub", "lstrip", "next", "reverse", "rstrip", "slice", "squeeze", "strip", "sub", "succ", "swapcase", "tr", "tr_s", "upcase"

All these methods are possibly unsafe, so they will return an unsafe String even if called on a SafeBuffer. If used for in-place replacements (e.g. sub! instead of sub), a TypeError is raised.

This is to prevent tric...

markbates/coffeebeans

When CoffeeScript was added to Rails 3.1 they forgot one very important part, the ability to use it when responding to JavaScript (JS) requests!

In Rails 3.1 it’s incredibly easy to build your application’s JavaScript using CoffeeScript, however if you fire off an AJAX request to your application you can only write your response using regular JavaScript and not CoffeeScript, at least until CoffeeBeans came along.

How to use Git on Windows with PuTTY

  1. Get "PuTTY Link" and "Pageant" (an SSH key agent) from the PuTTY download page.

  2. Run pageant.exe, find its icon inside your system tray and add your SSH key.

  3. Open up a cmd and put the full path to PuTTY's plink.exe into the GIT_SSH environment variable, e.g.:

    set GIT_SSH=D:\PuTTY\plink.exe
    

You can then use Git like you would on any sane operating system. Just go ahead and git clone, git pull, etc.

Also, you may want to add the environment vari...

Using RSpec's late resolving of "let" variables for cleaner specs

Consider the following:

describe '#something' do
  context 'with lots of required arguments' do
    it 'should work' do
      subject.something(:foo => 'foo', :bar => 'bar', :baz => 'baz').should == 'Hello world'
    end

    it 'should work again' do
      subject.stub :target => 'universe'
      subject.something(:foo => 'foo', :bar => 'bar', :baz => 'baz').should == 'Hello universe'
    end

    it 'should work yet again' do
      subject.stub :target => 'multiverse'
      subject.something...

How to upgrade RubyMine

This card explains how to upgrade an existing RubyMine installation to a newer version. If you're installing RubyMine for the first time, see install RubyMine under Ubuntu. You might also consider installing RubyMine with snap, so it can receive automatic updates (also described in the install card).


This procedure ensures that an update does not totally break your IDE, as it allows you to keep both the previous and the new version of RubyMine:

  1. [Download the newest version](http://www.jetbrains.com/ruby...

Read your mail in networks that forbid e-mail traffic

If you are connected with a network that forbids e-mail traffic but allows SSH, you can tunnel your e-mail connection through a trusted, intermediary server:

 sudo ssh -i /home/local-user/.ssh/local-user.key -L 143:mail-server.tld:143 remote-user@trusted-server.tld

Explanation for the command above:

| sudo | Secure ports may only be forwarded by root |
| ssh -i /home/local-user/.ssh/local-user.key | Private half of your SSH key for the trusted server |
| -L 143:mail-server.tld:143 | Forward connections to port 143 on your mail s...

Move a Gnome panel to another monitor in Ubuntu

In older Ubuntu releases you could ALT+drag any panel bar to another position and/or monitor. In Ubuntu 11.04 Natty you need to perform the steps from the attached article instead:

  1. Right-click on the panel to access the panel properties
  2. Uncheck "Expand"
  3. Move the panel by dragging the grip areas that now appear on the panel edges
  4. Check "Expand" again in the panel properties

Opening Rubymine projects from the command line

To activate the shell command, go to Tools > Create Command-line Launcher and confirm.

Now you have mine as bash command. Run this to open a project in RubyMine:

mine path/to/my_project

Booting Rubymine

The mine script will attach the opened project to a current Rubymine instance. If there is none, it will run Rubymine right there on your command line.

To move Rubymine to the background and suppress log messages you can create your own shell script (vim ~/bin/rubymine):

#!/bin/sh
( mine "$@" & ) > /dev/null ...

Lessons learned from implementing Highrise's custom fields feature

We recently added custom fields to Highrise which allow you to keep track of extra details beyond standard contact information like phone, email, address, etc. After the launch, we had a “looking back” conversation to see what lessons could be learned from the process.

Better is better: improving productivity through programming languages

All you need to know about the rise and fall of programming languages. Not really related to the worse is better essay linked here earlier.

The Rise of "Worse is Better"

An ancient essay on software design that, after 20 years, should still guide you for every line of code you write.