Ruby Pretty-Print XML

It's fairly easy to do with some Rails libraries, although it's different from the way that most people have suggested online due to Rails 3 changing the way that some things are laid out. If you want to use IRB or something else to pretty-print XML with Ruby, try the following:

require 'rubygems'
require 'ap'
include ActiveModel::Serializers::Xml

raw = File.read(filename)
parsed = Hash.from_xml(raw)
ap parsed

The ap is the awesome-print gem. It prints out the resultant structure in an easy-to-read format. I like the output of ap better than pp, and I like using RoR's from_xml better than, say, REXML, Nokogiri, or XmlSimple. For the first two, you basically have to roll your own pretty-printer (from what I understand). XmlSimple works, but the output seems to be a bit funky (too many arrays for keys, etc.)

Read on →

Ruby Shebang RVM

If you're wondering what the right shebang line is when you're using RVM, it's:

#!/usr/bin/env ruby

For searchers, it's also called a hashbang, hashpling, pound bang, or crunchbang.

Read on →

Getting Objective Resource Working with SDK 4.2

I cloned Objective Resource from the yfactorial ObjectiveResource github repository, initialized the git submodules, and tried building it under the SDK for 4.2.

I ran into two problems when trying to build. First, it complained about not knowing where the SDK was. To remedy this, I went to Project -> Edit Project Settings -> Build -> Base SDK, and changed it to latest. It was originally looking for the 3.0 SDK, which wasn't installed on my machine.

Read on →

! Fingerprint already exists. Please use one ssh key per Heroku account

Trying to change Heroku command-line users to add add-ons for the user in our organization that has the credit card information associated with him (Bill).

My account info: anthony@example.com His account: bill@example.com

Can run this to clear out my current Heroku username and password:

rm ~/.heroku/credentials

But unfortunately even after I authenticate with the new username and password, things don't quite work right:

Read on →

Getting autotest working with Rails 3

Here's all the stuff I needed to get autotest (formerly known as autospec) working with Rails 3 and rspec 2. I'm assuming you are using bundler.

# Gemfile
source 'http://rubygems.org'

gem 'rails', '3.0.1'

group :development, :test do
  gem 'rspec'
  gem 'rspec-rails'

  group :autotest do 
    gem 'ZenTest'
    gem 'autotest'
    gem 'autotest-rails'
  end
end
# .rspec
--format nested
--color
# autotest/discover.rb
Autotest.add_discovery { "rails" }
Autotest.add_discovery { "rspec2" }

Then you can run:

Read on →