Veezus Kreist

Ignoring machine-specific changes to .rvmrc

At Hashrocket, we use RVM to manage our rubies and gemsets on client projects. We typically specify the version of ruby that’s in production in our .rvmrc, like so:

rvm_gemset_create_on_use_flag=1
rvm 1.8.7-p249@vurl

However, sometimes a machine will have a problem with an installation of ruby, and so we’ll use a different version on that machine. Yeah, the correct solution is to fix the damn ruby, but we solved the problem today by flexing some little-used git fu… updating the index to ignore local changes to a file.

So, our `git status` shows us:

# On branch master
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   .rvmrc
#
no changes added to commit (use "git add" and/or "git commit -a")

Now let’s instruct git to assume our .rvmrc is unchanged:

git update-index --assume-unchanged .rvmrc

And now our `git status` looks much better:

# On branch master
nothing to commit (working directory clean)

Repeating the previous command in bash

As a developer, I’m always looking for ways to keep my hands on the home row when typing. One of the few times I still use the arrow keys on my keyboard is when I want to repeat the previous command in bash. The solution? Use ctrl+p to cycle through previous commands, and ctrl+n to move forward through them.

Thanks, Bernerd!

On Chicagoan Tornado Sirens

It was a Wednesday a couple weeks ago. We were a group of Rocketeers on a wind- and rainswept balcony overlooking the river in downtown Chicago. All of the business types had fled after a table overturned in the maelstrom, but we were Hashrocket, and this was our happy hour. The waitress was thrilled that we continued to order drinks.

And then something strange happened… a siren started to sound. I had never heard anything like it, and my initial impression was that there was a normal police siren sounding that was being distorted by the buildings and rain.

Turns out, it was a tornado siren. But hey, it’s going to take more than a little tornado to keep us from our happy hour. Here’s the audio of the event:

Error: OpenSSL when installing ruby 1.8.6 with rvm

We’re hosting a project on EngineYard and, unfortunately, they currently only support ruby 1.8.6 patchlevel 287. When trying to install ruby-1.8.6-p287 with rvm, however, make generates the following error:

In file included from openssl_missing.c:22:
openssl_missing.h:123: error: conflicting types for ‘BN_rand_range’
/usr/include/openssl/bn.h:411: error: previous declaration of ‘BN_rand_range’ was here
openssl_missing.h:124: error: conflicting types for ‘BN_pseudo_rand_range’
/usr/include/openssl/bn.h:412: error: previous declaration of ‘BN_pseudo_rand_range’ was here
make[1]: *** [openssl_missing.o] Error 1
make: *** [all] Error 1

The solution involves installing a custom OpenSSL package with rvm. You can get details directions directly from the source: http://rvm.beginrescueend.com/packages/openssl/

Faking a multipart form upload with webrat

We’re developing an API of sorts for one of our clients. We’ve got an API that expects some form data for an Item and an optional file sent along. We ran into a little bit of trouble sending this file along with the request. We took a cue from the way webrat submits its forms for our solution:

file = File.open("path/to/fixtured/file")

params = { :item => {:new_file => ActionController::TestUploadedFile.new(file.path)} }

visit api_item_path(item), :put, params

Returning multiple IDs when using finder_sql

We ran into some trouble today with finder_sql. Our object graph is fairly complicated, and can be summed up like this:

Job has many
Items, which have many
Processes, which have many
Cycles, which are iterations of many
Tasks.

This leads to us doing some pretty crazy SQL to compress the graph and save on database hits, and led today to an interesting discovery. We had done a has_many on User to return a list of tasks the user was able to perform. The finder_sql we generated looked like this:


SELECT *
FROM tasks t
INNER JOIN cycles c on t.cycle_id == c.id
...
INNER JOIN jobs j ON i.job_id = j.id

Unfortunately, the fist ID returned belonged to Job, so while the attributes for each Task was correct, the ID was actually the Job’s ID.

The fix was to select only the attributes of tasks:


SELECT t.*
FROM tasks t
INNER JOIN cycles c on t.cycle_id == c.id
...
INNER JOIN jobs j ON i.job_id = j.id

Writing a Builder::XmlMarkup to file

Matt Yoho and I have been working on interfacing with a SOAP-based external service with no documentation and hosted on Windows. During the course of feeding this service XML to try to get it to react as we’d like, we realized we didn’t know how to write out a Builder::XmlMarkup object to file without adding a new to_s element.

The solution? Calling target! on your object will return the string that Builder is building.

tempfile.write xml.target!

Specifying an older rubygems version with RVM (updated)

Updated with user-based configuration – thanks, Wayne

I’ve recently been in the uncomfortable position of trying to work on rspec-rails (which requires rubygems 1.3.6) and a legacy app that Hashrocket has been maintaining (which works with 1.3.5 or earlier). I’d been hearing about RVM and decided to give that a whirl.

However, by default, RVM was installing rubygems 1.3.6. After a little bit of struggling, I found the place to change the default rubygems version to install. In ~/.rvm/config/user, add the following line:

rubygems_version=1.3.5

This will override the default setting in ~/.rvm/config/db. Install a new ruby and check your gem version:

rvm install 1.8.7-p174

rvm gem -v

Prune your remotes

Lark and I were working on a project the other day and were nowhere near a commit at the end of the day. So we created a feature branch and pushed a WIP commit:

1
2
3
4
5
6
veez ~/code/some_app (master)$ git co -b client_edits_business
M        app/models/user.rb
M        spec/models/user_spec.rb
...
Switched to a new branch 'client_edits_business'
veez ~/code/some_app (client_edits_business)$ 

We finished up the feature the next day, and a week or so later Lark IMed me asking if there was anything on the branch that needed saving. I knew there wasn’t, so I deleted the remote branch:

1
2
3
4
5
6
7
8
9
10
11
veez ~/code/some_app (master)$ git branch -a
  client_edits_business
* master
  remotes/origin/client_edits_business
  remotes/origin/master
veez ~/code/some_app (master)$ git branch -d client_edits_business
Deleted branch client_edits_business (was 1fc95e5).
veez ~/code/some_app (master)$ git push origin :client_edits_business
To git@github.com:hashrocket/some_app.git
 - [deleted]         client_edits_business
veez ~/code/some_app (master)$ 

The next morning Lark asked me about the branch again, as it was still showing up in his tracked branches:

1
2
3
4
jon@mbp2:~/git_hashrocket/some_app$ git branch -a
* master
  remotes/origin/client_edits_business
  remotes/origin/master

The solution? Prune your remote:

1
2
3
4
jon@mbp2:~/git_hashrocket/some_app$ git remote prune origin
Pruning origin
URL: git@github.com:hashrocket/some_app.git
* [pruned] origin/client_edits_business

Integration testing without cucumber

There are three main testing cliques at Hashrocket: the Fakirs, the Derivatives, and Team Zombie. Fakirs are so named because they stub and mock everything – making it all fake. Derivatives are the exact opposite, preferring to forego unit testing in most cases and just write integration tests that interact with the code through a browser. Team Zombie (the “decomposers”) had just the right mix for me: integration testing for core business value, unit testing individual methods, and stubbing them elsewhere. Personally, such a technique helped me with my data models: too many stubs means too complex a model.

Additionally, I’ve never been in love with cucumber; the regexes drive me crazy, and I’ve never had a client who wants the (admittedly very nice) story formatting that it gives. I’ve been working on a green-field app this week at Hashrocket for the first time in months and it’s given me an opportunity to try out a new integration testing methodology and has called into serious question my membership in Team Zombie. Tip of the hat to Sandro for turning me and Voxdolo on to this technique.

Here’s a quick and dirty implementation of integration testing with rspec and webrat on Vurl (source), using the techniques I picked up this week.

Configure your application

In config/environment.rb:

1
2
config.gem 'rspec-rails', :lib => false, :version => '1.2.7.1'
config.gem "webrat", :version => "0.5.3", :lib => false

In spec/spec_helper.rb:

1
2
3
4
5
6
7
8
9
10
11
require 'webrat'

Webrat.configure do |config|
    config.mode = :rails
end

Spec::Runner.configure do |config|
  ...
  config.include(Webrat::Matchers, :type => [:integration])
  ...
end

Create your spec

1
mkdir spec/integration

Here’s my spec/integration/create_vurl_spec.rb file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))

describe "Create Vurls" do
  it "redirects to the vurl show page" do
    submit_vurl 'http://google.com'
    current_url.should == vurl_url(Vurl.last)
  end 
  it "shows a success message" do
    submit_vurl 'http://google.com'
    response.body.should include('Vurl was successfully created')
  end 
  it "creates a vurl" do
    submit_vurl 'http://veez.us'
    Vurl.last.url.should == 'http://veez.us'
  end 
end

def submit_vurl url 
  visit root_path
  fill_in "vurl_url", :with => url 
  click_button 'Vurlify!'
end

Run your spec

Since your spec file ends in _spec.rb, it will run with the rest of your spec files. Just give your app a

1
rake spec

A note about rspec matchers

When running these rspec tests, we don’t have access to the rspec matchers. So things like

1
flash[:error].should_not be_nil

won’t work because the be_nil matcher isn’t loaded. You can always fall back to Test::Unit:

1
assert_not_nil flash[:error]

Or, better yet, test that your content is within the body:

1
response.body.should include('There was a problem creating your vurl')

This method of integration testing feels much lighter to me; the tests take less time than cucumber equivalents and we’re not writing and maintaining a separate set of regexes to go with the app.

Enki blogging app

I’ve been going through a rebranding effort lately, moving away from Matt Remsik or Veez to Veezus Kreist. I believe Veezus will be a stronger brand that will result in less name collisions with other folks on the internet.

Part of this effort was moving my blog from Blogspot to something I’ll host myself at blog.veez.us. I considered many solutions: Mephisto, Simplelog, and Enki

Mephisto was active but seemed large and bloated with features I wouldn’t use (and the Documentation tab kept throwing 404s). Simplelog was no longer being maintained. Enki was just right, providing a simple blog application with everything I needed.

I was able to get my enki blog up and running, with all posts and comments copied over, in about two hours. I’d recommend it for a personal blog that doesn’t need features like multiple authors and that you want to easily modify.

On localpolitics.in


Being the social progressives that we are at Hashrocket, we were excited when Obama announced the Martin Luther King Jr Day of Service. Then, when we found out that Sunlight Labs was holding a contest called Apps for America, it was quickly decided that we’d honor the Day of Service and have a hack day to create an app. With a design from local firm Thought & Theory, a number of local tech folks joined us in the orbiting Hashrocket HQ to lay the foundations for localpolitics.in.

Over the course of the next two months, many small tweaks and enhancements were made and a second hack day was held. The final result was submitted to Sunlight Labs on the day of the deadline. On Sunday, we were notified that we had taken an honorable mention for our efforts. All of the sites created were well thought out and executed; I was really excited to see the quality of the work done by other contestants.

Thanks to everyone who helped work on the project. They are:


On local radio stations

Today I got followed by @chumley1073, and employee of a local new rock station called Planet Radio (107.3 FM in Jacksonville, Florida).

You see, until recently if you wanted to listen to any new rock in jax, you had to listen to Planet. What changed that fact was the arrival of X 102.9. What was previously an 80s pop station suddenly became the one thing I never expected: a competitor to Planet.

I'm not a very big fan of Planet; the reasons seem like they should go in an unordered list:
  • Lex & Terry, morning shock-jocks and relationship advisors, prevent me from rocking out in the morning
  • The music played was new rock, but it wasn't exactly what I wanted to hear. I like to hear songs that are more frenetic than heavy.
  • Commercials. Planet played a lot of commercials.
X 102.9 was all of the things Planet wasn't, and it was good. I immediately changed my number one slot to X 102.9. I think it was three days before I heard a commercial. That's likely because they didn't have any advertisers, but I still rarely hear commercials. And then they started playing snarky ads comparing the number of commercials on each station in the last hour, and about Lex & Terry being old, bald men.

Shortly thereafter, I heard their request line announcement. In order to request a song, you must text the song title to them. They apparently don't have a phone line. And then they announced their twitter username (@x1029jax)... followed by their facebook page. Last week they announced a contest you could win by becoming friends on Facebook, and today they asked listeners to friend them on twitter.

All of it makes me think of some random dude sitting in a window-less concrete-walled room recording sound bytes and checking texts, facebook, and twitter... just the type of super-lean operation that can build off of larger Planet's existing ad network. Sure you could advertise on Planet, but why not use those ads they helped you develop on our station for much less?

You can see Planet reacting already to the existence of X 102.9. I heard a kick-ass song, "Sex on Fire" by Kings of Leon, on X 102.9. About a week later I heard it on Planet. It's not the type of music I expect to hear from them. Planet has shot back at X 102.9 with an ad that suggests a puppy dies each time a listener switches to another radio station. And now, an employee of Planet has followed me on twitter. I didn't follow him back; it feels like Planet is just trying to play catch-up.

All in all, it's an interesting play that X 102.9 has made, and I'll be listening to see how it all turns out.

On vim targets

It must be noted that my first experience at Hashrocket with vim was a few weeks pairing with Tim Pope (the dude who wrote the rails.vim plugin you should be using) on a rescue mission. I didn’t touch the keyboard for three days – that’s how many hours of watching the man operate it took me to absorb the ridiculously awesome things he was doing. Credit for nearly all of my vim knowledge goes to him. The rest goes to the other Rocketeers who put up with my continual discussions about how to more quickly achieve line edits.



I thought I might sit down and document some key ways that I interact with vim, and then I realized that would take a couple hours and way more thought than I want to put into a drunken Saturday night. So I decided to talk only about targets instead.

In vim are the concepts of actions and targets. Actions are pretty straightforward and are really only useful when combined with targets. Some actions in vim are listed below for reference.
  • d: delete
  • y: yank (copy)
  • c: change
  • v: select
Targets in vim are one or two character combinations. I’ve listed some of the most common targets I use below.
  • iw: in word
  • t: to the character before the next character entered
  • f: to the next character entered
  • $: to end of line
Combining actions and targets results in some interesting scenarios:
  • ciw: change in word. Whatever the word under the cursor, remove it entirely and put me in insert mode.
  • diw: delete in word. Delete the entire word currently under the cursor.
  • ct.: change to the next period. Helpful for changing the name of an object, but not the method called on it.
  • ct(: change to the next open paren. Helpful for changing the name of a method.
  • df): delete to next close paren. Helpful for deleting entire method calls.
  • yiw: yank in word. Yank the entire word under the cursor.
  • d$ or D: delete to end of line
  • c$ or C: change to end of line
  • y$: yank to end of line
Do you use vim? Why or why not? If you do, what interesting ways do you use vim’s targets?

On my first tattoo


Some people have asked why I’ve got a Hashrocket tattoo on my calf. The reasons are pretty biographical; ‘ware ye the history contained herein. Credit for the photo goes to Travis Schmeisser.



Each Wednesday Hashrocket has a midweek get-together called Hashrocket Hot Hackers Hump Day Happy Hour (or 6H). It was a chilly January evening and there were almost a dozen rocketeers milling about at the local martini bar when Sal casually asked if I wanted to go get a Hashrocket tattoo with him.

Of course, inebriated as I was, there wasn’t much chance I was going to turn down the idea of getting a Hashrocket tattoo.

Yet, there was a time when I considered tattoos silly things that a person gets to show how edgy he or she is, or to indicate an extreme level of I-will-kick-your-ass. Now I’ve got one. So why choose to get a Hashrocket tattoo?

I’ve become quite enamored of Hashrocket since I arrived in Atlantic Beach at the end of March in 2008. I was still a recovering burn-out when I came down here, and somehow Hashrocket refilled my spiritual-coding cup. That sounds extreme, but it’s just the way things are.

I spent five years at a county-level government IT shop as a web programmer. I serviced sixteen department websites and also wrote an intranet from the ground up that served 1700 employees while I was there. My boss was lost on anything past FrontPage and for help I had only a string of limited-engagement, part-time assistants of varying levels of skill.

I burned out. Totally and completely. I threw away all of my computer gear and went back to auditing hotels overnight and contemplatively staring at the moon. After about a year, I had the realization that software is what I do, and no matter how burned I felt or how much I wished otherwise, it seemed that was the value I would provide to society.

I began the slow road back to development by working as a part-time webmaster at a non-profit. Then Tiger turned me on to Ruby on Rails, and things started to happen inside of me. A strange sensation that, after experiencing a few times I was able to place: happiness. I was happy writing ruby code. I was happy using the rails framework. Just typing out each line of code somehow made me feel good.

That’s how I came to be a Rails consultant in Madison, Wisconsin. My first paid site was completed in November, 2007, and I’ve never looked back.

When Tiger invited me to come down and see how Hashrocket does things in March of 2008, I was excited to see the magic sauce that had both he and Lark raving about the company. I didn’t expect to be offered a job, but I was, and it’s been the best thing that’s happened to me.

In many of the same ways that ruby and rails took away the pain of coding for me, Hashrocket has taken away the pain of work and replaced it with happiness. Pair programming has made me a more effective and efficient programmer. Communicating all the time has taken away all the bad conversations, because nothing has time to fester. Test-driven development gives me a level of confidence in my code that makes me unafraid to change even systems I haven’t looked at in ages. I feel encouraged to excel as an individual rockstar within the community, even on the Hashrocket clock. As Les Hill (in the photo, on the right) is wont to remind us in his blog posts, working at Hashrocket is like attending an ongoing seminar.

All of these reasons, from my discovery of Ruby on Rails through joining Hashrocket and even becoming a presenter at local user groups, this is why I have a Hashrocket tattoo on my calf. If I never have another experience that I want to commemorate with a tattoo, I’m glad I’ve had this one.