Move your Ubuntu system to another computer in 3 simple steps

You just got a brand new machine but you won’t like to spend hours tuning it to get the same configuration as the one you have used for years?

Let’s transfer your Ubuntu configuration and applications to your new computer in three simple steps.

This method is cross-architecture. I moved successfully my configuration and applications from an Ubuntu 9.04 32bit to a 64bit one.

Prerequisites:

The same version of Ubuntu is installed on both machines. The architecture (32/64 bit) can be different.

Step 1: Store the list of installed packages

Run the following command on the source machine to store the installed packages names in ~/pkglist:
sudo dpkg --get-selections | sed "s/.*deinstall//" | sed "s/install$//g" > ~/pkglist

Step 2: Transfer your config

Use scp or rsync or even a flash drive to transfer your home directory (~/*, ~/.*), the source list (/etc/apt/sources.list) and any other files you customized or installed (like apache config under /etc or softwares on /opt) from the source machine to the target one.

Step 3: Install packages

On the target machine run the following command in a failsafe terminal session to install your packages:

sudo aptitude update && sudo aptitude install `xargs ~/pkglist`

That’s all folks!

Log into your new machine and keep working as if you were using the previous one.

A freshly transfered Ubuntu install

Leave a comment

Jabber-SH — SH console via XMPP/Jabber (GTalk)

Screenshot-Jabber-SH on GTalk

I’ve just posted the code of Jabber-SH on GitHub. Jabber-SH is a ruby hack that allows you to administrate a remote computer via a command line through a Jabber client. It’s like SSH via GoogleTalk! :)

I coded it nine month ago then I planned to add some specs, to store the configuration in a yaml file, to make a gem out of it but… I didn’t and I won’t get a chance to do that. So here are the 25 lines of code… hackish eh?!

1 Comment

Top-down and Bottom-up programming illustrated by Mac OS X and Windows

Bottom-up programming starts by developing the data model before designing the user interface. Windows Start/Programs menu illustrates this approach. Since programs shortcuts are stored in the directory Programs the menu displays the content of this directory.

Windows XP Start menu

Top-down programming starts by designing the user interface before developing the data model. Mac OS X dock illustrates this approach. As it should be easy for a user to launch an application the dock displays big icons accessible in one click.

Mac OS X Dock

1 Comment

Back to VIM for Ruby and Rails

I learned to use VIM at the university to administrate linux systems and to develop C++ apps. Then I moved to Java and I enjoyed using an IDE like Netbeans. When I started to play with Ruby and Rails I kept using Netbeans as my editor of choice as it plays very well with them.

As I was bored with “Up arrow key, End key, Enter key” instead of “O” to insert a new line above my cursor and I wanted to play again with this so old but still alive editor, I installed the plugins: rails.vim (just great), haml syntax highlight (I ♡ haml) and irblack color scheme (more Textmate like).

With rails.vim, you get just great shortcuts to browse your rails source file. Type :Rmodel your_model_name to edit your model source file — :Rcontroller, :Rview, :Rmigration, :Rjavascript, :Rstylesheet… work too! It also includes :A (jump to alternate file) and :R (jump to relative file) commands. :A switches between source code and corresponding spec file, :R jumps from model to migration file. The most amazing combo: :AV to open up the alternative file (your spec file usually) in a vertical split window.

I finish up with the two commands I learned to use and love.1) Type ma to “mark” your cursor position as ‘a’ then type 'a to get back to this position. 2) Use qa to record a macro in ‘a’, press q again to stop recording. Then @a to replay it. Using commands to jump to next word / end of line / next something character it can be much faster than making a substitution using regexp or so.

3 Comments

How-to make the front mic working on Ubuntu 9.10 (Dell laptop: Intel Hda soundcard)

Ubuntu 9.10 comes with alsa 1.0.20 allowing the front mic to work on a Dell XPS M1530. From the Sound Preferences, select Microphone 2 then fire up a terminal, launch alsamixer -V capture and set the following options and enjoy!

Screenshot-AlsaMixer

Leave a comment

Ruby 1.9 faster than Ruby 1.8?

Today I ran the following script with Ruby 1.8 & Ruby 1.9 to compare their performances:

def bench
  start = Time.now
  1000000.times do
    yield
  end
  puts Time.now - start
end

puts "Test 1: do things"
bench {
  "yeho!12".next
  rand(100)
  i ||= 1
  i = i + 1
}

puts "Test 2: \"stuff\""
bench {
  "stuff"
}

puts "Test 3: 'stuff'"
bench {
  'stuff'
}

puts "Test 4: :stuff"
bench {
  :stuff
}

Ruby 1.9 performances are promising:

Test

Ruby 1.8 (sec)

Ruby 1.9 (sec)

Perf Increase
Test 1: do things

1.76

0.54

324.40%
Test 2: "stuff"

0.76

0.21

364.53%
Test 3: 'stuff'

0.80

0.21

388.91%
Test 4: :stuff

0.70

0.13

525.98%

So Ruby 1.9 is 3 to 5 times faster than Ruby 1.8 to run simple operations. I then checked with a small Rails app.

Once I got rubygem installed for Ruby 1.9, the gems I needed installed for Ruby 1.9, the plug-ins I use patched for Ruby 1.9, and my ruby code patched for Ruby 1.9, – yes, it was painful! – I fired: time spec spec

Ruby 1.8

$> time spec spec
............................................

Finished in 0.594813 seconds

44 examples, 0 failures
spec spec  2.49s user 0.79s system 93% cpu 3.522 total

Ruby 1.9

$> time spec spec
............................................

Finished in 0.625589223 seconds

44 examples, 0 failures
spec spec  8.74s user 0.32s system 93% cpu 9.648 total

Grrrr. Ruby 1.8 & 1.9 both pass the specs in ~0.60 second but Ruby 1.9 takes 8.74 seconds in total vs 2.49 seconds for Ruby 1.8. The same behavior occurs when running a Webrick server via script/server: Ruby 1.9 is 2 times slower than Ruby 1.8 to boot up the server and it handles the requests just as fast as Ruby 1.8.

Any Ruby guru to explain such deceiving results?

1 Comment

How-to fix low volume on Ubuntu (Dell laptop: Intel Hda soundcard)

It took me a while to find a way to fix it as all the alsa-mixers where set at 100%. The solution: run alsamixer -D hw:0 to display a new mixer called “Front” set at 70% by default – shift it to 100% and you can now listen to music or watch a film at a comfortable level!
Ps: If anyone knows how to increase the internal mic input volume and/or make the front mic work on an Dell XPS M1530: I’m definitely interested!

2 Comments

New rails plugin to find unused translations

A small while ago, I released with @lboix a simple rails plug-in that displays translations stored in your locale file but not called from your source code. It is called unused_translations and it is available on GitHub. I hope you’ll enjoy it!

Leave a comment

Make acts_as_versioned create new version on demand

I use acts_as_versioned to manage versions of Rails models. As I don’t want to create a new version of my document everytime I save it (to fix a typo for instance), I added a virtual attribute called save_with_revision to my model and put it into the definition of version_condition_met?.

attr_accessor :save_with_revision

def version_condition_met?
  @save_with_revision.to_s[/true|1/] != nil
end

Cool… except that it does not save intermediate updates into the **_versions table. Let say you create document version 1.0, then update it without creating a new version (from v1.1 to v1.4) and finally save a new version (v2.0); v1 will still be v1.0 and not v1.4.

To save intermediate updates into the **_versions table, just add to your model:

def after_update
  if !version_condition_met? && changed?
    versions.find(:last).update_attributes(self.attributes)
  end
end

Hope it helps. :)
Anyone with a better solution?

1 Comment

File versioning in Ruby on Rails with Paperclip & acts_as_versioned

This short tutorial shows you how to manage file versioning in Ruby on Rails by making Paperclip falling in love with acts_as_versioned. Paperclip & acts_as_versioned are plug-ins for Ruby on Rails: Paperclip manages file upload, acts_as_versioned enables models versioning.

Patch Paperclip

I patched Paperclip to keep old files when a new revision is saved. A fork of Paperclip adding the option keep_old_files to make Paperclip working with acts_as_versioned is available here: http://github.com/pcreux/paperclip/tree/master. You can install it running:

script/plugin install pcreux_paperclip

Update your Paperclip + acts_as_versioned model

Just three things to do:

  1. update the url & path to store your files by ‘version’
  2. set the option keep_old_files to true when a new version get saved
  3. add the interpolation of :version
class Document < ActiveRecord::Base
  has_attached_file :attachment,
                    :url => "/system/attachments/:id/:version/:style/:basename.:extension",
                    :path => ":rails_root/public/system/attachments/:id/:version/:style/:basename.:extension",
                    :keep_old_files => :version_condition_met?

  acts_as_versioned

  Paperclip.interpolates :version do |attachement, style|
    attachement.instance.version.to_s
  end
end

I hope it helps. :)

9 Comments
  • Hi, my name is Philippe Creux.

    I am a software engineer specializing in Agile methods, Behavior Driven Development and Ruby on Rails. I live in Vancouver, Canada where I work for Versapay as a Ruby on Rails programmer & BDD guy. This blog is about Agile project management, Ruby programming and other cool things.