Don't miss a post! Subscribe to my mailing list.
Turn a Ruby Array into a Hash
I always forget the syntax for this:
ary = [:a, 1, :b, 2, :c, 3]
Hash[*ary] # => { :a => 1, :b => 2, :c => 3 }
sed in-place editing gotcha in OS X
I just started learning about sed and came across one "gotcha" when using the -i
option in OS X. The -i
option allows you to edit a file in-place. It takes an optional parameter - a string to use as the extension for the backup file. If this parameter...
Syntax Sugar for Defining Test Helper Methods
I prefer Ruby's Test::Unit
over RSpec, but one of the things I like about RSpec is the let
method. It allows you to create memoized helper methods in your tests. When I use Test::Unit, I usually mimic this behavior using a private helper method. Today...
LinkedIn API and Sinatra
I've been playing around with the LinkedIn API and Sinatra for about a week and wrote a tiny app. After you authenticate using your LinkedIn credentials, the app allows you to search your connections for those that have a skill you specify. The source...
Autogenerate ctags for Ruby Gems
I already mentioned in a previous post how to generate ctags for a Rails app. You can also use the gem-browse and gem-ctags gems to automatically generate a ctags file every time you install a new gem.
Find Method Usages with ctags and vim
I always forget how to set up ctags for a Ruby/Rails app so that I get tags for not only the project, but also any gems specified in my Gemfile. From the project root do:
ctags -R `bundle show rails`/../* .
Sidestep: Mobile Web App with jQTouch
Sidestep is an experiement built using Sinatra and jQTouch. It's a mobile web app that provides NJTransit train information. The source code is available on GitHub.
7 Tips for Writing User Stories
- Pick a format and stick to it. I prefer "As a <role> I want to <goal> so that <benefit>."
- Be sure to include acceptance tests with the story.
- Keep technology terms / phrases out; a story should define user interaction absent of technology.
- Have your...
JavaScript Patterns: Revealing Module
Awhile ago I wrote about the Module Pattern in JavaScript. There is an alternative that is quite popular called the Revealing Module Pattern that looks like this:
The problem is, I don't like it. My main issue with this pattern is readability:...
Side Project: Car Fuel MPG Tracker Using Sinatra
Update: Looks like ZeepMobile has shut down so the example app is no longer up. I've kept the repository though.
I was playing around with Sinatra a few months ago and decided to create a small app with it. It's a very basic online fuel efficiency...