Upgrading to RTorrent 0.8.5
Recently I went through the process of upgrading rtorrent-0.8.2 and libtorrent-0.12.2 on my Ubuntu 9.04 box to the latest versions, rtorrent-0.8.5 and libtorrent-0.12.5. Unfortunately what should be a simple process was rather complicated because the developer has not yet updated the project’s website to reflect all of the changes that have been made to the configuration options in version 0.8.4 (which was released nearly a year ago!). After dozens of Google searches I was able track down the information I needed. In addition, I have added notes on hiccups I ran into when compiling RTorrent from source and getting RTorrent to work with dtach.
Rails Rumble ’09: Grocery Tracker
Update: The Grocery Tracker website is no longer online.
This year I once again participated in the RailsRumble competition with the goal to build a Rails app in 48 hours. My amazing teammates Arya Asemanfar, Gary Tsang, and Alex Le and I worked together tirelessly to build an application for tracking grocery purchases. The result is Grocery Tracker.
Grocery Tracker
The objective of Grocery Tracker is to make it really easy to visualize how much you are spending on groceries and how your buying habits are changing. For me, it is interesting to see what percent of my grocery purchases are going towards “Snacks & Candy” as well as my historical spending in that category. Grocery Tracker allows me to quickly answer questions like “Am I spending less on snacks now than I was 3 months ago?”.
Capturing Output from PUTS in Ruby
When writing unit tests for my simplesem interpreter, one test in particular was problematic. In simplesem, the set write instruction prints output to the screen.
// place Hello World! on the 'write' buffer set write, "Hello World!"
Internally, the interpreter is just passing the second parameter, “Hello World!”, to the puts method in Ruby. This makes it difficult to use traditional test/unit assertions to check that the simplesem instruction is working.
I eventually found two solutions for this. The first, suggested by David Stevenson at Pivotal Labs, is to use mocha to check that puts was called on the object.
require 'test/unit' require 'rubygems' require 'mocha' class SimpleSemParserTest < Test::Unit::TestCase def test_set_stmt_write parser = SimpleSemParser.new parser.expects(:puts).with("Hello World!") parser.parse('set write, "Hello World!"').execute end end
This solution is fine for most situations; Mocha will throw an exception if puts is not called. However in my case, it was unsuitable because puts was not being called on the SimpleSemParser object but instead on a Treetop syntax node that I did not easily have access to within the unit test.
I knew that if I could capture the output from the puts method into a variable I would be able write the test using a standard assert_equal. After some googling I discovered that this functionality is built into the ZenTest gem. After rewriting the test looked like this.
require 'test/zentest_assertions' class SimpleSemParserTest < Test::Unit::TestCase def test_set_stmt_write out, err = util_capture do parser = SimpleSemParser.new parser.parse('set write, "Hello World!"').execute end assert_equal "Hello World!\n", out.string end end
This works great. However, should we decided that we do not want to use an external gem, with a little effort we can bypass ZenTest and implement util_capture ourselves.
Automate Updating Your Git Repositories
I have a half dozen TextMate bundles that I am grabbing the latest versions from GitHub instead of from the main TextMate subversion repository. For a long time I have been updating each of the bundles’ Git repositories by cd’ing into each directory and running git pull. Doing this over and over became silly and I was annoyed from doing all that typing.
Today, I finally wrote a basic bash script that automates updating each of the repositories. Sometimes it is surprising how simple an automated solution turns out to be.
A SIMPLESEM Interpreter
In my Programming Languages course, taught by Shannon Tauro we have been using a fake assembly language of sorts called SIMPLESEM to gain experience translating the semantics of a high level programming language, to a simple processor.
Since SIMPLESEM is a made up language that was created just for our textbook, there was no way for me to execute the SIMPLESEM programs that I was writing for the homework assignments. This was annoying because SIMPLESEM is a low level language which makes it hard to notice mistakes. Of course, it is very easy to make a mistake any time you are programming but it is even harder to catch those mistakes if you are working at close to assembly level.
As a fun exercise I implemented an interpreter for SIMPLESEM using Ruby and published it as a RubyGem. Fortunately, I choose to use Nathan Sobo’s Treetop gem to aide in the development. Using Treetop, I wrote a parsing expression grammar to parse SIMPLESEM commands. This resulted in my SIMPLESEM interpreter being a lot more flexible than I had originally anticipated. After I familiarized myself with the basics of writing Treetop grammars I found it very easy to make changes to my grammar definitions to add language features one by one.
