Shizzle

My little notebook

Installing Ruby 1.9.3 on Ubuntu 12.04 Precise Pengolin (without RVM)

May 2, 2012

The new Ubuntu release has just rolled around and with it a slew of new packages. Personally, I’m tracking the development of Ruby quite closely but the default Ruby on Ubuntu ist still the 1.8 series which I can’t recommend. Ruby 1.9 has some performance improvements and 1.9.3 in particular a lot of them compared to 1.9.2.

However, as I have elaborated out in a previous post getting the Ruby 1.9 series on Ubuntu without using RVM instead of 1.8 isn’t all that easy. Please read the post if you are interested in the details.

The short version is: You can get Ruby 1.9.3-p0 by installing the ruby-1.9.1 package. (The package is called 1.9.1 because that is the ABI version.)

If you want to make Ruby 1.9 the default do the following:

sudo apt-get update
 
sudo apt-get install ruby1.9.1 ruby1.9.1-dev \
  rubygems1.9.1 irb1.9.1 ri1.9.1 rdoc1.9.1 \
  build-essential libopenssl-ruby1.9.1 libssl-dev zlib1g-dev
 
sudo update-alternatives --install /usr/bin/ruby ruby /usr/bin/ruby1.9.1 400 \
         --slave   /usr/share/man/man1/ruby.1.gz ruby.1.gz \
                        /usr/share/man/man1/ruby1.9.1.1.gz \
        --slave   /usr/bin/ri ri /usr/bin/ri1.9.1 \
        --slave   /usr/bin/irb irb /usr/bin/irb1.9.1 \
        --slave   /usr/bin/rdoc rdoc /usr/bin/rdoc1.9.1
 
# choose your interpreter
# changes symlinks for /usr/bin/ruby , /usr/bin/gem
# /usr/bin/irb, /usr/bin/ri and man (1) ruby
sudo update-alternatives --config ruby
sudo update-alternatives --config gem
 
# now try
ruby --version

If you want to make this your exclusive Ruby and get rid of Ruby 1.8 follow the uninstallation instructions.

Edit: I found out today that there also is a package called ruby1.9.3 however that is just a proxy package that doesn’t have any files itself and only depends on ruby1.9.1. Aptitude confirms this:

Ruby uses two parallel versioning schemes: the `Ruby library compatibility version’ (1.9.1 for this package), which is similar to a library SONAME, and the ‘Ruby version’ (1.9.3 for this package). Ruby packages in Debian are named using the Ruby library compatibility version, which is sometimes confusing for users who do not follow Ruby development closely. This package depends on the ruby1.9.1 package, and provides compatibility symbolic links from 1.9.3 executables and manual pages to their 1.9.1 counterparts.

There doesn’t seem to be a rubygems1.9.3.

 

7 Comments

Backing up your Gmail account with on a Synology NAS using getmail

April 10, 2012

Recently, I had a bit of a data loss scare where I couldn’t access my Google Account for a few hours. In the end it turned out to be a well-meaning Google protection mechanism that kicked in because I tried to access my account while on holiday on the Canary Islands. I have heard horror stories of people loosing their email histories stored in Gmail and this little incident got me scared enough to investigate backing up my email history outside of Gmail.

I use a Synology NAS at home which has plenty of storage left to keep my roughly 2GB of email many times over. It has a variant of Linux installed and besides a nice web-based UI it has also the very handy ability to ssh into the box and install additional software through a package manager called ipkg.

The setup

Login to your NAS as root and install getmail with these commands:

ipkg update
ipkg install python
ipkg install py25-getmail

Now that your have the software in place pick a place where the email should be stored. I chose /volume1/Gmail but any folder that is accessible to your ordinary user will do. Still logged in as root issue these commands:

mkdir /volume1/Gmail
cd /volume1/Gmail
mkdir cur new tmp

The last one is necessary for the storage format (Maildir) and getmail doesn’t create these folders itself. Maildir stores each email in a separate file on the disk. If you want another storage format, read the getmail documentation.

Then create a file called /volume1/Gmail/getmailrc with the following content, using your own username and password:

[retriever]
type = SimpleIMAPSSLRetriever
server = imap.gmail.com
mailboxes = ("[Gmail]/All Mail",)
# if you have a German account, use [Google Mail] like this
# mailboxes = ("[Google Mail]/All Mail",)
username = USERNAME@gmail.com
password = USERPASS
 
[destination]
# save each email in a separate file
type = Maildir
path = /volume1/Gmail/
 
[options]
verbose = 2
message_log = /volume1/Gmail/log
 
# retrieve only new messages
# if set to true it will re-download ALL messages every time!
read_all = false
 
# do not alter messages
delivered_to = false
received = false

Now everything is in place for getmail to do its work. Do a test run with the following command to test if it will run into any problems.

getmail --getmaildir=/volume1/Gmail

This will start downloading your messages but depending on the size of your email history will take up to a few hours. There is the distinct probability that your ssh connection will time out and drop due to your inactivity. That’s why I ran the first go with nohup so that me logging out wouldn’t stop the process.

nohup getmail -q --getmaildir=/volume1/Gmail & > /volume1/Gmail/nohup.out

Cron

Lastly, we obviously want to run getmail periodically and fetch the newest message so open up /etc/crontab with a text editor like vim (you probably need to install it with ipgk first) and add the following line:

0       3       *       *       3       root    /bin/su -c "/opt/bin/getmail -q --getmaildir=/volume1/Gmail" admin

(It is important so separate the individual parts of the crontab with a tab not a space as otherwise the Synology will delete your entry when you reboot.)

This will run getmail every Wednesday at 3AM when you’re sound asleep. The /bin/su complication is necessary because it appears that the Synology cron can’t run jobs as non-root.

Also, on my Synology you have to restart the cron daemon for it to pick up the changes with a

synoservice --restart crond

7 Comments

Git releases RSS feed

March 13, 2012

I’ve been following the git releases quite closely lately but I haven’t been able to find a RSS feed for the release notes. To scratch this itch I have written a little Ruby script that scrapes the git homepage and puts the release notes in an RSS feed ready for consumption.

If you want to subscribe to the feed add this URL to your feed reader: http://lenni.info/git-releases.rss.xml

The feed is updated every 8 hours.

No Comments

Experiment: Does Googlebot index dynamic content from a JS app?

March 5, 2012

I’ve started a new job and we are evaluating whether we would still like to use a server-side framework for HTML generation or whether we should go for a client-side DOM manipulation/JS-templates-only-approach where the browser calls into the API directly.

One of the drawbacks of the latter is that the conventional wisdom not so long ago was that Googlebot would not execute any JavaScript and hence the content would be invisible to it. However, some people started to notice that Facebook comments, which are created dynamically on the fly by a JS widget, are being indexed by Google. This was confirmed by Matt Cutts in a tweet. There is also an official blog post by Google about this topic but both are pretty sparse on any details. There is a certain amount of speculation floating around that Googlebot could in reality be some modified version of Chrome.

The experiment

Therefore I have decided to put up a small Backbone demo page with the opening lines of  Richard III. – this is sure to be a pretty unique string that won’t show up anywhere else on my website. The actual content is being pulled in by an Ajax call and then inserted into the DOM. Using jQuery, underscore and Backbone is of course overkill for such a small site but I wanted to simulate realistic conditions.

I’m going to wait a few days and then update this blog post. In the meanwhile you can keep checking the unique search query for the dynamic content and see if something shows up over the next few days.

The page has some content already present in the HTML (the Macbeth part) which will help comparing the Google results. You should be able to find that part on Google with a another specially crafted search query.

Edit 15/03/12: The results

Well, that was a bit of an anti-climax. I’ve been waiting for 10 days now and Google didn’t index the dynamic content at all! The static content is in their index so that means that it managed to crawl the page successfully.

This obviously has repercussions for people wanting to write indexable JavaScript apps. To be honest I’m a little deflated that this didn’t work. I didn’t expect Google to randomly click on buttons in the app but I thought they would at least run the initial JavaScript and then add the content of the DOM into their index.

Does anybody know more?

1 Comment

My first iPhone app

January 19, 2012

In the recent months or so I have written my first iPhone app and Apple has approved it last night!

It works only in Germany and will find the nearest cash point for Cash Group, which is an association of Deutsche Bank, Commerzbank, Postbank and a few others. As someone not living in Germany you may ask Why? Well, if you use a cash point from another bank you will have to pay fees for withdrawing cash, sometimes as high as €6.

So, without further ado:

Screenshot

App Store links

 

2 Comments

Installing Ruby 1.9.2 on Ubuntu 11.10 Oneiric Ocelot without using RVM

December 18, 2011

It seems installing Ruby 1.9 on Ubuntu without the use of RVM isn’t all that trivial. I had to poke around the system for quite a while before I got it running.

Why not RVM?

Well, I tried RVM but compiling Ruby took 3 hours on my EC2 micro instance and was eating all my CPU so that my webserver was basically not available anymore. To me that isn’t acceptable. Besides, I think it is highly wasteful to compile packages from source when there are precompiled versions available. I admit that apt is too slow to keep up with the rapidly moving gems ecosystem but for the Ruby interpreter itself I strongly prefer the OS to handle the installation.

Besides I don’t really want to use different versions of Ruby at the same time. I just want something that isn’t Ubuntu’s default 1.8.7, which in Ruby years is ancient.

The steps

The good news is that as of writing this, Ruby 1.9.2 is available without any PPAs straight from the official Canonical package repos. The bad news is that information about how to get it is thin on the ground.

For starters the package for Ruby 1.9.2 is called ruby1.9.1 and Googling around, it wasn’t immediately obvious that any version of Ruby 1.9 is even possible on Ubuntu.

Anyway, here it goes:

sudo apt-get update
 
sudo apt-get install ruby1.9.1 ruby1.9.1-dev \
  rubygems1.9.1 irb1.9.1 ri1.9.1 rdoc1.9.1 \
  build-essential libopenssl-ruby1.9.1 libssl-dev zlib1g-dev
 
sudo update-alternatives --install /usr/bin/ruby ruby /usr/bin/ruby1.9.1 400 \
         --slave   /usr/share/man/man1/ruby.1.gz ruby.1.gz \
                        /usr/share/man/man1/ruby1.9.1.1.gz \
        --slave   /usr/bin/ri ri /usr/bin/ri1.9.1 \
        --slave   /usr/bin/irb irb /usr/bin/irb1.9.1 \
        --slave   /usr/bin/rdoc rdoc /usr/bin/rdoc1.9.1
 
# choose your interpreter
# changes symlinks for /usr/bin/ruby , /usr/bin/gem
# /usr/bin/irb, /usr/bin/ri and man (1) ruby
sudo update-alternatives --config ruby
sudo update-alternatives --config gem
 
# now try
ruby --version

This installs Ruby 1.9.2 and sets that to be the default ruby on your system. Crucially, it also installs rubygems for that interpreter and sets that to be the default. (Thanks for the initial snippet to Michał Frąckowiak. His version got me most of the way there.)

Uninstalling Ruby 1.8

If you, like me, ran a Rails app on 1.8 you probably have a bit of stuff hanging around the file system. Lets clean that up.

First uninstall all gems from the 1.8 installation with:

gem1.8 list | cut -d" " -f1 | xargs sudo gem1.8 uninstall -aIx

Secondly, remove the ruby packages with apt.

sudo apt-get remove libruby1.8 ruby1.8 ruby1.8-dev rubygems1.8

After you have done that you may want to check if there is anything else hanging around with a quick:

dpkg --get-selections |grep ruby

6 Comments

How to find out if you are running Apache mpm-prefork or mpm-worker

December 7, 2011

I struggled with this today whilst trying to figure out Apache’s config options.

On Ubuntu you can do the following:

$ dpkg --get-selections |grep apache
apache2						install
apache2-mpm-prefork				install
apache2-prefork-dev				install
apache2-utils					install
apache2.2-bin					install
apache2.2-common				install
libapache2-mod-php5				install
libapache2-mod-wsgi				install

This tells me that I have mpm-prefork.

No Comments

Editing LESS and CSS3 with Vim

October 3, 2011

A thought or two about CSS precompilers

I had heared of Sass repeatedly for a while now but so far I had always mentally filed CSS precompilers under “Interesting concept, but probably not all that useful for me”. I thought that CSS is fine as it is and after all it’s just a bunch of style definitions, right?

On the other hand I grew to actively dislike handling CSS files. I didn’t quite understand at the time that this had mostly to do with their great redundancy and repetition.  When you’ve been used to something’s mediocrity for so long you don’t really noticed those weaknesses anymore.

When a coworker suggested using a CSS precompiler to help our CSS explosion, I was pretty sceptical. But I like learning new things so we went ahead and introduced LESS in our current project.

What a difference! I may end up sounding like a used-car salesman but it really is a difference like day and night. I’d love to tell you lots of reasons why these precompilers are great, but unfortunately Jason Z. from 37 signals has done a much better job.

Wasn’t this post suppossed to be about Vim?

Lets talk business then. I’m using Vim to edit LESS and it looks like this:

Vim with vim-less, vim-css3-syntax, vim-css-colors

Vim with vim-less, vim-css3-syntax, vim-css-colors

I can recommend a trio of plugins for LESS and general CSS3 editing:

vim-less

This plugin’s syntax highlighting was fairly feature-rich to begin with but I have added a few extra features including indenting and autocompletion and the original author has merged them back to his branch. The plugin’s compatibility has led me to check out vim-css-colors.

vim-css-colors

This great plugin visualises a color expressed in hex, RGBa or HSLa and paints the background underneath it in the corresponding color. If you’re not sure what I mean, here’s screenshot:

This may look like a toy to some, but LESS lets you have a file with just the colour palette of your app/website and seeing them all visualised is very nice. It also helps you to reuse the same variable name for each colour rather than re-introducing new ones.

vim-css3-syntax

This has a very complete syntax file for CSS3 and I have  added support for this plugin in vim-less. That works pretty well and those fancy new CSS3 properties are then also displayed with correct syntax highlighting applied.

Improvements for the future

The current autocomplete (hit Ctr-X, Ctrl-O if you’ve never used it) that ships with standard Vim is pretty complete for CSS2. However there is no autocomplete script for CSS3. Looking at the CSS2 version, it shouldn’t actually be too hard to parse the syntax highlight files and add the new properties to the existing script.

I’d also like to implement a syntax checker but looking the the source of lessc, LESS’ command line compiler, there doesn’t seem to be a validating phase that I could use.

I also saw that some web-based CSS prettifyiers can order CSS properties alphabetically. Wouldn’t that be a neat feature for Vim?

No Comments

Sharing a single gitconfig between your work and home computers and taking care of user.email

June 24, 2011

I just started a new job where git is being used and since I had accumulated some stuff in mit .gitconfig, I wanted it to be on my work computer too. I use a git repository for all my dotfiles, which I then clone on the machine and symlink files like .gitconfig or .vimrc to the home directory. This means if I add something to those files at work and want to use the configuration at home too I just need to commit, push and pull the changes at home.

Well, this works pretty good until you realise that there are some config entries you want to be different in the two environments. Git’s user.email is obviously such a case.

The solution

Git does not allow you to to include other configuration files in your .gitconfig but you can use the environment variable $EMAIL in order to overwrite user.email.

What I have done is to add the following to my .bashrc (which is also in the dotfiles repo):

if [ -f .host-specific.sh ]
then
    source .host-specific.sh
fi

This loads a host-specific bash file (if it exists). In this file you’ll stick your email address like this:

export EMAIL=lenni@work.com

(Obviously this file needs to be recreated on each host and can’t be shared across computers through the dotfile repository.)

Now you can safely share your .gitconfig between the two computers without having to worry about the email settings.

No Comments