Speed up your rails test cases

If you’re complaining about the speed of your test cases, they’re probably not very good. Don’t worry, I’m not here to judge.

Your test cases are probably on old, legacy systems you don’t want to talk about. They probably also touch the database. They probably touch the database lots. That database is probably even mysql.

DISCLAIMER: What I'm recommending to you is 100% SAFEISH and is OFFICIALLY endorsed by Clarke. You should blindly do what I say without investigating any possible drawbacks or repercussions.

Ext4 Barriers

If you are running EXT4 as your file system, you will want to add the ‘barrier=0′ option to your fstab. When you’re done it should look something like this:

UUID=dlolsok5-c7b5-489-aea-7f380085c / ext4 errors=remount-ro,barrier=0 0  1

ACID shmashid

Add the following to your my.cnf

innodb_flush_log_at_trx_commit = 0

The results

With those two simple changes the runtimes of my Giant Annoying Test Suite went from:

73.40s user 5.19s system 45% cpu 2:52.76 total
68.01s user 3.69s system 83% cpu 1:25.46 total

Playing Music Over The Network

**Disclaimer**: Don’t try this at home

Sometimes, the best solution isn’t the prettiest.

Sometimes, your server with a few hundred gigs of music is downstairs tucked away in your amazing wireless closet, but you spend most of your life upstairs on your comfiest of couches. Also, living with 5 others, it would be nice to allow your roommates some degree of control over the music.

Our first semi-serious attempt at solving the music-upstairs problem involved an asus eeepc running xmbc with our music hosted on mediatomb upnp shares but we weren’t happy. We decided for practicality reasons we wanted the music to play on the server downstairs, but have the audio play upstairs. However, we weren’t about to mess with the wiring, so we decided on something else…

Piping audio over ssh to a remote machine

while true; do
	cat /tmp/probedsp
done | ssh dsl@probe sox -t raw -r 48000 -w -s -c 2 - -t ossdsp /dev/dsp

That monstrocity is courtesy of John Hawthorn. We’ve had this running almost a month now, and I’m still not sure if its the greatest thing I’ve ever seen, or the most likely to secure us all a place in software hell.

With great power comes great responsibility. We took that responsibility and piped it over ssh through our wireless network 24/7, sucking up more cpu cycles and bandwith a day than every maching running in 1975.

What that command does (at least as far as I can tell…) is pipe the local audio output over ssh to SoX on the remote machine. We’ve set up mpd to output to our fifo (/tmp/probedsp) which gets sent to probe to be played.

Probe itself is a Fujitsu Stylistic LT C-500 touchscreen I picked up on Used Victoria for $50 and threw Damn Small Linux onto.

When its all said and done, we can control mpd running on our server downstairs, and the audio is played on the tablet upstairs.

Remote Volume Control

To control audio volume, we set up something equally horrifying:

while true
do
	netcat -l -p 1666 | xargs umix
done

That sits netcat on port 1666 looking for arguements to send to probe’s mixing program, umix. We can netcat from a local box or open and write to a socket on port 1666 to control the volume…

The dlink Dir-655 hash changes…

I mentioned in a previous post I needed to programatically log into my Dlink DIR-655 router and grabbed the computed password off of a submit.

Well it turns out the salt changes periodically (maybe every reset?) and just storing the hash wasn’t enough. I ended up writing a bit of ruby to recreate the javascript hashing function

require 'digest/md5'
require 'nokogiri'

router_path = "http://#{router[:ip]}"
x = agent.get(router_path)
salt = x.body.match(/salt = "(.*)"/)[1]

# pad the pasword to length 16
pad_size = (16 - router[:password].length)
padded_password = router[:password] + "\x01" * pad_size

# pad it the rest of the way, length 64 for admin
salted_password = salt + padded_password + ("\x01" * (64 - salt.length - padded_password.length))
login_hash = salt + Digest::MD5.hexdigest(salted_password)

login_path = "#{router_path}/post_login.xml?hash=#{login_hash}"

That code can be found on my github as part of Orbital Command.

Science, Clarke! Do it for Science!

Things have changed since that last time I had a Presence on The Internet. Most important of which is I have now graduated and have the Time and Resources to do Things.

Some of those things people might find interesting. Some of these things people might find exciting. If you find anything I write about either exciting or interesting, you’re probably a geek. Welcome :}.