Samuel Wong

Ramblings of a rocket scientist turned web developer

Ruby on Rails Development Platform on VirtualBox

Our dedicated development box is too loud. So I decided to take my super quiet Mac Mini and build a virtual Linux server so our Unstash dev team can work on it. This is a walkthrough installation of a Ruby on Rails development platform for a small team of 4 developers. I hope it helps someone out there looking to do something similar!

Hardware: Mac Mini mid-2011 with 8GB RAM

Goal: Run a virtualized ubuntu server and give each developer their own account.

Server for a Small Team

Working with the Unstash team of volunteers has been absolutely fantastic. But it hasn’t been without its technical challenges.

In the early days, we were having Wednesday night meetups at E’s house. We would all bring our laptops and hack code together. We hosted our site at Site5 and we fell squarely in the ‘power users’ category. A typical evening would see 3 or 4 of us all SSHing into the Site5 server. We were using the Symfony framework, which involved running the symfony generator scripts quite frequently. We would crank out code, run those PHP scripts, and ‘svn commit’ and ‘svn up’ all through the night. We had separate directories for each developer and we used checkouts of the SVN repo for our staging and production versions of the code.

In theory, this arrangement works well - each developer is totally isolated from the others. We each had our own copy of the code, our own MySQL database, and our own URL via different subdomains. In practice, it wasn’t so dandy.

Gamification

At first, I didn’t believe it would work on me. But I was wrong. I’m totally into this whole gamification thing.

What is it? Gamification is when sites encourage participation by awarding badges, points, or awards. FourSquare is a great example. To unlock badges, you need to meet a certain requirements, such as checking into a gym a certain number of times to get the “Gym” badge. My first thought was: “who cares how many badges you get?” I’m not a bragging type of person and I’m only ever competitive when I’m already near the top of a leaderboard (which is almost never). Naturally, I thought gamification would never work on me.

In general, this is very true. I play Starcraft 2 and I don’t care for unlocking the avatars, badges and achievements. I would never use FourSquare for the badges. I’m on Steam and I don’t care for the achievements there either. However, I’ve discovered that gamification does work on me if it is implemented with privileges as rewards, and that these privileges helps me Get Stuff Done or Get Stuff Done Better. I’m a productivity and efficiency freak, and it is little wonder that this method is so effective for me.

Mac: Home and End in the Terminal

In the Terminal preferences: Settings > Keyboard tab. Select HOME and for the string to send, press ctrl+a. It should show up as \001. For END, press ctrl+e which shows up as \005.

Quick Tip: ASCII Codes and Link_to

Problem: I wanted an ASCII character, », to appear inside the body of a link. By default, Rails 3 escapes HTML for safety so I get this:

Solution: Append .html_safe at the end of the body parameter.

<%= link_to 'Learn more about collaborative consumption &raquo;'.html_safe,
'http://blog.unstash.com',
:class => 'btn primary large' %>

Ebook: Rails 3 in Action

While I wouldn’t say this is a great book, it is a good book. There aren’t many review of this book out yet, so I thought I would put in my two cents, as a beginner Rails developer (9 months).

Tossing Out Old Hard Drives

Ever since watching the YouTube videos promoting Toronto’s e-waste program, I’ve been scrounging my house for obsolete electronics to recycle. I’m glad they have curb-side pick-up now – I don’t have the time to make a special trip to transfer station. I’ve cleared out quite a bit: old monitors, a TV, a printer, a scanner and several hard drives.

Being the security-conscious person that I am, I want to thoroughly erase all data on these drives before setting it out on the curb. Deleting won’t do. Emptying the recycle bin won’t do. Formatting won’t do. I would bash the drives with a sledgehammer if I had one. So what’s a tech geek to do? Use Linux. Here’s my special recipe for utterly destroying data and making it near impossible to recover.

Workaround: Launchy Doesn’t Launch

While doing BDD, I encountered a problem with Cucumber’s “Then show me the page” step. It may have been due to moving to a Mac or something else, but in any case, Firefox doesn’t launch and the error displayed is:

Failure in opening /Users/samuel/unstash/unstash/tmp/capybara/capybara-201109071505526995598430.html with options {}: No application found to handle scheme ''. Known schemes: file, ftp, http, https

There’s an open issue on launchy’s github page, but even if it does get fixed in the next release, I would be wary of updating because of all the other gem dependencies… I don’t want to fix something that works 99% of the time.

My workaround is a simple bash script (I called it “launchff”) that pulls out the file path in the error message, and launches firefox.

Raising RecordNotFound Exceptions

In our app, bringing up a user’s profile, items, or messages is done through the user’s nickname (a.k.a. username). It makes for very beautiful URLs and encourages users to be early-adopters so they can claim their name. For example, http://unstash.com/samuelwong will bring you to my profile page.

ActiveRecord in Rails makes it easy to grab the records associated with an id or attribute (in this case, a nickname):

@item = Item.find(params[:id])
@user = User.find_by_nickname(params[:nickname])

However, when you use any ‘find_by_*’ methods, RecordNotFound exceptions are not raised for you. A simple trick solves this problem: use the ‘bang’ version of the method.

Remapping Keyboard and Mouse in Mac OS X Lion

I recently got a Mac Mini (mid-2011) and I’m back to fighting with my keyboard and mouse to make it the most productive and comfortable experience it can be. I spend too much time in front of the screen, and spending even an hour to get everything Just Right is worth it. In a nutshell, I want my Logitech wave keyboard (K350) and mouse (M510) to be exactly the same as with my Ubuntu setup.

My final setup is as follows:

  • CapsLock behaves as Ctrl.
  • Windows key behaves as Command
  • Left and right scroll wheel tilt behaves as back and forward buttons in browser (Firefox, Chrome) and Finder, respectively
  • Tracking speed is Just The Way I Like It.
  • Wheel button launches Mission Control.
  • Thumb button launches links in new tab. (Command-click)
  • Home and end keys jump the cursor to before the first and after the last characters in the current line, respectively.

Here’s how I did it.