Easy Multiple Account Management for Heroku

Written by Matt on / Jan 11

Recently, I migrated all of my personal and business sites to Heroku. Heroku, as you may know, is a fantastic service for hosting ruby applications. Oh, and it's free!

Like a lot of folks, I keep work and personal items such as email, bank accounts, github, etc in separate accounts. Heroku doesn't really place nice with multiple accounts.

So how to do we effectively manage multiple Heroku accounts?

Prerequitites

The following assumes you are on the Mac OS or *nix system, own multiple Heroku accounts, and have installed the Heroku gem. I should also be point out that you will need to create separate ssh public keys for each account.

Custom Ruby Script

One option is we can use a script such as Keith Gaddis describes over at the Collective Idea blog. With his switcher script, we can switch between two accounts like this:

ruby switcher.rb personal
ruby switcher.rb work

This essentially swaps the credentials file (used by the Heroku gem for authentication) for the account you want to use. This works well enough, however this can be tedious especially if you switch between work and personal projects frequently.

Enter Heroku Accounts Plugin

David Dollar of Heroku recently released an official Heroku plugin called heroku-accounts. With this plugin, we can switch Heroku accounts automatically.

To get started, we first install the plugin:

heroku plugins:install git://github.com/ddollar/heroku-accounts.git

The installation process will download the plugin from github and save it to the ~/.heroku/plugins directory. Now, we can setup each of our Heroku accounts with add command:

heroku accounts:add work

and for our personal account, we can run:

heroku accounts:add personal

The add command will ask you for your Heroku email address and password for each account. The plugin will maintain your account credentials in the ~/.heroku/accounts folder in your home directory. (Passwords are not saved in plain text)

To assign a project to a specific Heroku account, we run the following command in the project root:

heroku accounts:set personal # or work

This will assign a Heroku account to the project by adding an 'account' variable to the project's git config file.

Celebrate

Hooray! Now we can switch Heroku accounts automatically. Awesome.


5 Ruby Gems for Concise Code

Written by Matt on / Oct 31

At Littlelines, we have to write a lot of code under strict time constraints. We work in small teams which means that writing clean and concise code is a necessity. When a Ruby library comes along that makes code easier to grasp in a hurry, test, and maintain - we use it. Here are some gems we have in our toolbox:

Formtastic

If you're developing wep apps, more than likely it will include html forms. Forms can be a time-drain, not to mention very boring to build. Formtastic provides a more concise way of generating form views and includes inline error messages and is semantically rich.

Resource Controller

Resource Controller hides away the RESTful controller boiler plate code and make your controllers skinny. Skinny controllers help you to consolidate your business logic into one place, thus saves time on maintenance and testing.

Search Logic

Finding data can get messy. Sometimes we run into situations where we are concatenating strings to build SQL statements and this can lead to bugs. Searchlogic works by creating a number of named scopes that can be called on any ActiveRecord model. The best part, you can dynamically call scopes on associated classes and Searchlogic will take care of creating the necessary joins for you.

Alchemist

Occasionally, we work on projects dealing with conversions. Alchemist is a Ruby library that does conversions for you and thus making your code more readable and easier to maintain. For example:

Instead of:

miles = 8 * 1609.344 # converting meters to miles

We can write:

8.meters.to.miles

Alchemist includes a staggering array of conversions including distance, mass, volume, and more.

andand

andand is a handy gem that allows allows natural method chaining for methods that can return nil. This saves a lot of boilerplate code and improves readability. For example:

Instead of:

@body = (article = Article.find_by_title('test')) && article.body

We can write this:

@body = Article.find_by_title('test').andand.body

This will call find on the Article class and sends 'body' if the result is not nil. In addition, our methods are guarded from NoMethodErrors is the result is nil.


20 Clojure Links To Get You Up To Speed

Written by Matt on / Jun 6

Writing multi-threaded code is hard. If you've ever done concurrent programming, you'll probably agree. Clojure offers a compelling alternative to traditional object-oriented approaches to programming and has garnered much attention from the Ruby community because of it's elegant design that lets you get right to the essence of a problem.

What is Clojure?

Simply put, Clojure is a functional programming language for the Java Virtual Machine with several powerful features for building concurrent applications. In addition, Clojure is fast, robust, and a powerful general-purpose programming language. A dialect of Lisp, Clojure embraces traditional code-as-data philosophy and a powerful macro system, plus some syntactic sugar tailored to Java.

Now that version 1.0 is out and Stuart Halloway's new book Programming Clojure just dropped, I've rounded up some of the best articles and tutorials on Clojure to you get you up to speed quickly.

Tutorials and Links

Screencasts, Videos, and Presentations

Tools and Setup

Documentation