Speed up Ruby’s gem installation

You can skip the time and space consuming installations of the documentation and of the interactive reference that belong to Ruby gems. If you are sure that you don’t need these documents you can install a gem like this:

$ gem install <NAME_OF_THE_GEM> --no-ri --no-rdoc

To make this the default behavior for gem installations add this string to your gem configuration file (i.e. ~/.gemrc or /etc/gemrc):

gem: --no-ri --no-rdoc

Using the Ruby Version Manager (RVM)

Sometime you have to work with different versions of ruby (or jruby). This can be quite a pain but there is a remedy – the Ruby Version Manager (RVM). It helps you to handle many different ruby installations and their gems by installing them in a folder called .rvm in you home directory.

To install run the installation script

$ bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install

and add this string e.g. to your .bashrc

[[ -s $HOME/.rvm/scripts/rvm ]] && source $HOME/.rvm/scripts/rvm

Now you can install some versions of ruby:

$ rvm install 1.8.7
$ rvm install 1.9.1

But wait!!! After installing it this way I ran later into a problem with OpenSSL in Rails (no such file to load -- openssl (RuntimeError)). So I followed the instructions regarding packages and installed the ruby version the in following manner with OpenSSL support:

rvm package install openssl
rvm install 1.9.1 -C --with-openssl-dir=$HOME/.rvm/usr
rvm install 1.8.7 -C --with-openssl-dir=$HOME/.rvm/usr

After that it is easy to switch between ruby versions. Without any specification the system wide configured ruby version is called:

$ ruby -v
ruby 1.8.7 (2010-01-10 patchlevel 249) [i486-linux]
$ which ruby
$ which gem

Now we use rvm to switch to ruby 1.8.7

$ rvm 1.8.7
$ ruby -v
ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-linux]
$ which ruby
$ which gem

Now to ruby 1.9.1

$ ruby -v
ruby 1.9.1p378 (2010-01-10 revision 26273) [i686-linux]
$ which ruby
$ which gem 

Installing gems for a specific version if also a piece of cake:

rvm 1.8.7 gem install rspec rails metric_fu

You can set default versions for different projects by adding a .rvmrc to the folders of your projects:

echo "rvm 1.8.7" > /path/to/my/project/.rvmrc

Using Python to send messages to an OneSocialWeb server

Despite the strong hope in it diaspora is currently nothing more than a bundle of ideas that are waiting to be implemented. In contrast to that OneSocialWeb offers already basic implementation of a distributed social web. It’s based on XMPP and there are already clients available. I wanted to use a Python script to send messages to a OneSocialWeb server. Unfortunately the documentation for the pyxmpp library seems to be quite neglected IMO and I wanted a quick solution. On my search I stumbled across a ruby script that can do the wanted task by working with the raw sockets and self generated XML strings. I used that one to create my script in Python:

Set the number of stored revisions for CouchDB in Rails

CouchDB keeps a certain number (per default 1000) of revisions of every document. As describe in the CouchDB manual you can set the number of stored revisions for each database like this:

$ curl -X PUT -d "500" http://localhost:5984/my_test_db/_revs_limit

To see the currently set value do

$ curl -X GET http://localhost:5984/my_test_db/_revs_limit

I needed to set the number of revision for CouchDB of a Rails apps to a certain value. Unfortunately there seems to be no way to do this in the CouchDB configuration file currently. Instead I added the following code to the my config/environment/development.rb” file of my Rail app (sure this can be done for any other environment configuration file, too).

Now every time the Rails app is started the _revs_limit attribute of the database is set to the given value.

A script to speed up mp3 files

Have you ever tried to listen to podcasts or videos at increased speed to save time? Actually this usually works out quite well with a speed factor of 1.5 or so. You can do this using mplayer:

$ mplayer  -af scaletempo -speed 1.5 <FILENAME>

This will run the file with higher speed without increasing the pitch (so no Mickey Mouse voices 🙂 ). Use “[” or “]” to decrease or increase the speed. It is a good solution that can be used on a PC/Mac but if you have a mp3 player device with fixed firmware like me you cannot do this there. So I created a small script (gist at github) that uses mpg321, SoX and lame to generate mp3 files which I copy afterwards to the device.

Run the script with one or more mp3 files:

$ speedupmp3.sh <FILENAME(S)>


$ speedupmp3.sh test1.mp3 test2.mp3 test3.mp3
[...] # Some output
$ ls

Add an icon short cut for a shell script to the Favorites in Ubuntu netbook edition

The latest Ubuntu netbook edition (10.4) is organized in different workingspace (I am not sure what is the official expression for it) like “Favorites”, “Accessoires ” and “System”. I wanted to add an icon to the “Favorites” section to run a shell script that performs a backup. This can be done the following way:

  • Go to the “System” workspace and open “Main Menu”.
  • In there create new item e.g. in “Accessoires”.
  • Give it a proper name like “Backup” or whatever your script does.
  • Fill the “Command” field with something like “gnome-terminal -e ‘~/bin/my_backup_script.sh'”. (Please read the gnome-terminal manual if cannot guess what this does – “man gnome-terminal”)
  • If you want you can also explain the script in the command field.
  • To save and finish click “Okay”.
  • Now you have created a new short cut. So go to “Accessoires” where the new icon should be found.
  • If you hover the mouse over the icon a “+” symbol should become visible. If you click that sympbol the icon is added to your Favorites.
  • Done