Under Construction

I probably don’t have many readers to this blog, but for the faithful few you will notice that the theme has changed. This is entirely thanks to the excellent Octopress blog theme and software. Octopress was created by Brandon Mathis and is based on the programmer friendly Jekyll blog tool. Thanks to Octopress and Jekyll I can have a nice looking blog and use my text editor and git to maintain it.

Also I’m working on converting the content over from my old wordpress blog. The old posts will be available in the near future. I’m also hoping to import comments into disqus.

RUBYOPT - How it works

The RUBYOPT environment variable is a handy way to specify the options that will be pased to ruby without having to type them in all the time.

According to the ruby source code you can customize your ruby interpreter by specifying any of the following arguments in RUBYOPT: I, d, v, w, W, r, or K

For example to always require rubygems when you run ruby simply add the following to your .profile or .bashrc.

export RUBYOPT="-r rubygems" 

But wait there’s more! According to the rubygems documentation you can simply say

RUBYOPT='rubygems' 

How does that work?

Well this trick depends on a couple of things. First RUBYOPT does not actually require you to put a dash in front of your arguments. This kind of makes sense when you think about it since you have already declared the value of RUBYOPT to be options to the ruby interpreter by virtue of the fact that they are in a special environment variable. However, on the command line dashes are required to distinguish between arguments and files to run. So what does not requiring dashes leave us? Well you could expand

RUBYOPT='rubygems' 

into

RUBYOPT='-r ubygems' 

This brings us to the second part of the trick. Rubygems ships with a file named ubygems.rb that has this line require 'rubygems'.

All of this adds up to some ‘command line syntactic sugar’ allowing you to simply specify RUBYOPT='rubygems' to require rubygems by default in all ruby programs.


This post was inspired by an error I received yesterday; here it is for the benefit of those googling:

no such file to load -- ubygem (LoadError). 

The problem is that RUBYOPT was set to ‘rubygem’ when it should have been set to ‘rubygems’, or ‘-r rubygems’, or, ‘rrubygems’, or ‘-r ubygems’… you get the idea.

Restrict an ssh user to scp only access

Today I did a bit of research on how to restrict an ssh user to only have scp access. Basically all you have to do is add command="/usr/lib/openssh/sftp-server" to the beginning of the user’s key in ~/.ssh/authorized_keys like so:

command="/usr/lib/openssh/sftp-server" ssh-rsa thekeygoeshere== user@user.local

For more information on how to customize your authorized_keys file check out this helpful site.

Sake task for mod_rails (aka phusion passenger)

So phusion passenger for local development is the bomb! Sake bomb is also fairly cool in it’s own right. I got tired of manually updating httpd.conf and /etc/hosts to add new phusion passenger virtual hosts so I wrote a little sake script to do the work for me. Want it?

gem install sake && \
sake -i http://pastie.caboo.se/216294.txt

Update: I am now using the passenger preference pane instead of my sake script.

In the beginning there was chaos

Before Shelf

afterwards there was a shelf and slightly less chaos.

After Shelf

As you can see I still have some cleaning up to do, but I think the shelf is a huge improvement. According to the time-stamps of the before and after photos it took me approximately 7 hours to complete this project.

Yummy Breakfast :-)

Monday Emily fixed me a very yummy breakfast. Redi-whip+pancake+strawberries == good!

Yummy Breakfast

In 2040…

The other day I started thinking (shocking I know) about how old my child will be and how old I will be. I wrote down the following on the front of an envelope:

Year 2008 2010 2015 2020 2030 2040
Me 28 30 35 40 50 60
Baby 0 2 7 12 22 32

Use aptitude not apt-get and friends

From Aaron Toponce’s blog

Aptitude is just superior to apt-get in every way, shape, and form. Better dependency handling. Better curses application. Better options. ONE tool. Better stdout formatting. The list goes on and on. I see constantly, on forums, IRC and email, the use of apt-get. We need to better educate our brethren and sisters about the proper use of tools, and show them the enlightened way of aptitude. I’ve been using aptitude since I first learned about it, a[n]d will continue to do so the remainder of my Debian/Ubuntu days.

How to ban evil robots

I saw a tip on how to automate banning of evil robots posted by ironclad here.

It got me thinking about how to automate detecting and banning of robots for rails. It seems like all that is required is a combination of a DISALLOW /email_addresses/ line in robots.txt and something to send all requests for /email_addresses to the bit bucket.

This should be easy enough to do in apache with a rewrite rule:

RewriteRule ^/email_addresses - [F,L]

And I imagine nginx can do something very similar.

However this only takes care of robots that expressly do what they should not. In order to ban abusive robots by user agent or ip address you could use something like the following:

RewriteCond %{REMOTE_ADDR} ^63\.148\.99\.2(2[4-9]|[3-4][0-9]|5[0-5])$ [OR] # Cyveillance spybot
RewriteCond %{HTTP_USER_AGENT} EmailSiphon [NC] 
RewriteRule .* - [F,L]

Keep monit running on ubuntu > 6.10

Who is monitoring monit? Well normally init is (or could be), but newer versions of ubuntu (read feisty) don’t really use init, they use upstart. If you want to keep monit running with upstart try my monit upstart job.