Import a gemset without bundler

Here’s the scenario…

I’m trying to get a Rails 2.1.1 application up-and-running on my Mac (Lion). The application uses Ruby 1.8.7-p334. Bundler is not used so there’s no chance of doing a bundle install… drat!

I have a gemset export from another developer’s machine, which was created by doing this:

rvm gemset export my_app

That gives me a file which looks like this (truncated for brevity)…

# my_app.gems generated gem export file. Note…
actionmailer -v2.1.1
actionpack -v2.1.1
activerecord -v2.1.1
activeresource -v2.1.1
activesupport -v2.1.1

So, in theory it should be as easy as pie to import this gemset like this:

rvm gemset import my_app


The main problem arises when you install these gems, because the dependencies are not managed properly (this is what bundler was created for). So you end up with multiple versions of gems installed.


The trick now is I need to be able to do a diff between my currently installed list of gems and the desired list given to me by the other developer. You could do this manually, but I’m far too lazy for that…

So, I created a little ruby script which will accept two files to be used for the diff operation, together with a third optional argument depending on whether I want to install or remove the gems.

Here’s the script…

#!/usr/bin/env ruby

unless ARGV.count >= 2
  puts "Please provide two files to perform diff..."

def load_file file
  arr = File.readlines(file).map(&:chomp).compact
  arr.shift if arr.first =~ /^#/

f1, f2 = load_file(ARGV[0]), load_file(ARGV[1])
command = ARGV[2] || 'install'

((f1 - f2) + (f2 - f1)).uniq.each do |gem|
  puts "gem #{command} #{gem}"

Save this into a file called file_diff.rb and make the file executable:

chmod +x file_diff.rb

Now, it’s easy to get the exact gems installed by following these simple steps…

./file_diff.rb file1 file2 uninstall >
chmod x+

And that’s it! You should now have the same gems in your gemset that your friend has in his gemset, as per his exported list.

Install Ruby 1.8.7 on OSX Lion using RVM

I’ve got a brand spanking new MacBook Pro which is running OS X Lion. I use RVM to manage my Ruby versions. So should you…probably.

Anyway, I needed to install Ruby 1.8.7 for a work application, and although doing this using rvm seems to work, it doesn’t. Although rvm will tell you it’s installed Ruby 1.8.7 cleanly, as soon as you try to install a gem it will blow up in your face with a segmentation fault…

/Users/m/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/timeout.rb:60: [BUG] Segmentation fault


So after pulling my hair out for the best part of, oh… about 27 minutes, I came across the solution on stackoverflow. Thought I’d just post it here for my own blogging pleasure. Credit to Matt Sanders for the answer:

As per Matt’s solution, after you’ve installed Xcode from the App Store, downloaded and installed the OSX gcc installer, run the following to get Ruby 1.8.7 installed cleanly using rvm (adjust the patch level to your own needs):

rvm remove 1.8.7-p334
CC=/usr/bin/gcc-4.2 rvm install 1.8.7-p334 --force

I’m happy now.

Enable tethering and Wi-Fi hotspot on your HTC Desire

I’ve just bought a new Samsung Galaxy 10.1 Tablet, which is a beautiful piece of kit. It’s Wi-Fi only – not 3G enabled, but I was assured that I could easily share my phone’s 3G connection with my tablet should I need data access on the move. However, while it turned out to be a rather simple solution, it’s not exactly made easy by Orange.

Before I show you what I did, here is my setup:

  • Samsung Galaxy 10.1 Tablet running Android 3.1. This is standard (NOT rooted).
  • HTC Desire running Android 2.2. This is standard (NOT rooted).
  • Orange is my network provider.

I have no idea if my solution will work given any other setup, but this is what worked for me.

On your HTC Desire…

…we will change the details of an Access Point Name, which can be found here:

Wireless & Networks > Mobile networks > Access Point Names

You should then see the following 3 Access Point Names:

  • Orange Internet
  • Consumer Broadband
  • Orange MMS

Select the Consumer Broadband option, and then make the following changes (case-sensitive!):

  1. Set APN to orangeinternet
  2. Set Username to Orange
  3. Set Password to Multimedia
  4. Set Authentication type to CHAP

Press the Menu button and then press Save.

Then just turn on your Portable Wi-Fi hotspot.

On your Galaxy Tablet…

…just connect to your phone, which will be recognized as just another Wi-Fi network. Provide the necessary credentials and you’re good to go.

These steps are really simple and hardly worth documenting, so I won’t. But this process is worth documenting because it’s hardly something that the average non-technical user would be able to find. Thanks Orange.

We now have a working Wi-Fi hotspot and an internet-enabled non-3G tablet.


Custom bash auto-completion using Ruby

Using what I showed you in the how to run Ruby code from within a bash script post, I will follow that up with an easy way to create a custom bash auto-completion function.

The Scenario…

I like to keep all my code and projects in my ~/Development directory. I typically create an alias which takes me to this path, and depending what projects I’m working on, I’ll add/remove aliases accordingly to get to the relevant projects quickly. But this is quite manual and cumbersome, and it requires constant maintenance. What I’d like is an auto-complete function that dynamically picks up any new directory I create in the ~/Development directory.

All the functions detailed below should either go into your .bashrc file, or a file that is sourced from your .bashrc file.

Get rid of that alias

The first thing to do is change my alias to a function. So, instead of this…

alias d="cd ~/Development"

…we want this:

function d { cd ~/Development/$1; }

Create the list of choices

Next, we need a function which returns a list of all the directories in the ~/Development directory, which will serve as our auto-completion choices. We can use Ruby here to make things nice and clean…

#!/usr/bin/env sh

/usr/bin/env ruby <<-EORUBY

class ProjectCompletion
  def initialize(command)
    @command = command
  def matches do |task|
      task[0, typed.length] == typed
  def typed
    @command[/\s(.+?)$/, 1] || ''
  def projects
    %x[ls ~/Development].split



Bootstrap it!

Finally, all we need is to tell bash to use this script. We do that with this command (your own paths may vary of course):

complete -C ~/.dotfiles/completion_scripts/project_completion -o default d

Reload your shell and voila! You now have bash auto-completion for all your coding projects. This is very easily customised too, so you can create auto-complete scripts for all kinds of other things, locations, tasks etc.

You can now easily reach your coding projects using auto-complete, without the need for aliases. For example, if you had a directory structure like this…


…you could easily see a list of projects doing this:

d proj<tab>

For more information see my dotfiles project.

Hope this helps.

Setting up Ubuntu 11.10 for Rails development… Just Right!

Further to my previous post on how to setup Ubuntu 11.10 for Rails development, I have now created a bash installer script to automate the whole laborious process for your pleasure… well it’s for my own pleasure really, but I like to share!

There are two installer scripts:

  1. Ubuntu user will setup your Ubuntu 11.10 environment will all the usual goodies you normally should install after a clean install / upgrade.
  2. Rails developer will setup your Ruby environment using RVM, along with all the supporting things that you will need to get up and running in no time.

The installers are updated regularly so check the git pages for full details, but some of the key things that are installed are…

The Ubuntu user installer will hook you up with these (among others)…

  • Medibuntu repositories
  • Ubuntu Restricted Extras
  • Configuration Editor (dconf-tools)
  • Compiz Config Settings Manager
  • Synaptic
  • Terminator
  • GNOME Tweak Tool
  • VLC
  • Jupiter
  • Caffeine
  • Web apps and Sushi file previewer
  • Simple LightDM Manager
  • Sysmonitor App Indicator
  • Dropbox
  • OpenJDK (Java 7) – optional

Some of the things the Rails developer installer will setup are…

  • SSH key – optional
  • Essential Ubuntu libraries
  • Ruby 1.8.7 from Ubuntu repostories with additional libraries
  • Git and Git Gui
  • MySQL 5.1 with admin GUI tools
  • MongoDB 2.0.1 – optional
  • ack
  • ImageMagick
  • RVM (Ruby Version Manager) with these rubies: 1.8.7 stable and 1.9.2 stable

Head over to the git repository for instructions on how to run the installers and also for more details about what it actually installs:


Nice & clean config using dotfiles

Clean up your shell environment by using my dotfiles project.

It’s as easy as running a simple rake task… then you have a clean, customizable shell environment all set up and ready to go!

Please see the git repository for more details on what is does and how to install.

You can find it all here:

As mentioned before, you will have to have Rake installed before you run the automated installer, but it will set things up nicely. Just right in fact.

Hope you like it.


Get every new post delivered to your Inbox.