How-to Install Git Completion

TL;DR; Paste the following into terminal and hit enter:

eval "$(curl -s https://gist.github.com/raw/972430/install-git-completion.sh)"

That's it! You will now have git completion! You can test it by typing git l and pressing "tab".

Continue reading for more details...

How it Works

When you run the previous command in terminal, it's going to download and run the following file:

This script downloads the correct version of the git-completion script from github, and adds a reference to it in your bash profile.

Update 8/17/2011 - Fixed the url in the script since github changed their url conventions.

How-to Add Facebook Login to a Rails App (Using Devise)

First, you need to add the omniauth gem to your Gemfile:

gem "oa-oauth", :require => "omniauth/oauth"

And then you need to modify the configuration in your devise initalizer:

You need to sign up for an appid and key from facebook at http://developers.facebook.com/setup

config.omniauth :facebook, 'appid', 'key'

Add a new controller for omniauth callbacks:

Create a new controller at ‘/app/controllers/users/omniauth_callbacks_controller.rb’, and start with the following code:

class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
  def facebook
    # You need to implement the method below in your model
    @user = User.find_for_facebook_oauth(env["omniauth.auth"], current_user)  

    if @user.persisted?
      flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Facebook"
      sign_in_and_redirect @user, :event => :authentication
    else
      session["devise.facebook_data"] = env["omniauth.auth"]
      redirect_to new_user_registration_url
    end
  end
end

Add a new route to this controller:

devise_for :user, :controllers => { 
  :omniauth_callbacks => "users/omniauth_callbacks"
}

Mark your user model as omniauthable:

Add :omniauthable to the devise helper in your user class.

class User < ActiveRecord::Base
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable,
         :omniauthable
end

Add a function to your user model to find the user for the given facebook account:

class User < ActiveRecord::Base
   def self.find_for_facebook_oauth(access_token, signed_in_resource=nil)
     data = access_token['extra']['user_hash']
     if user = User.find_by_email(data["email"])
       user
     else # Create an user with a stub password. 
       User.create!(:email => data["email"], :password => Devise.friendly_token[0,20]) 
     end
   end
end

That’s it! For more information, here’s the devise wiki article I followed: OmniAuth:Overview

Dogma

Your time is limited, so don't waste it living someone else's life. Don't be trapped by dogma - which is living with the results of other people's thinking. Don't let the noise of other's opinions drown out your own inner voice. And most important, have the courage to follow your heart and intuition. They somehow already know what you truly want to become. Everything else is secondary.

- Steve Jobs

Hacker News Unread Comments - Chrome Extension

I've built a new chrome extension that will place a red marker (*New) next to any comments that you haven't seen yet. It's useful for tracking a discussion, and seeing which comments are new since the last time you've visited the thread.

Screenshot

Try it out at: https://chrome.google.com/webstore/detail/odbfgccplknfllkhjmpfogjbnacdkdcl

View the source at: https://github.com/johngibb/Hacker-News--Show-Unread-Comments

Useful Rails Resources

As I'm developing Rails applications, and I run into a feature I'm not familiar with, I always find myself using the same resources:

  • Documentation (guides, blog posts, github documention, etc)
  • StackOverflow
  • Code Snippets

After realizing how much time I spend searching for resources I've already found before (not to mention the context switch and frustration of a failed search), I decided to throw together a quick site to keep track of what I've found before.

In the hopes that someone else could find it useful, I've decided to make it freely available.

Check it out at: http://rails-resources.heroku.com/

View the source at: https://github.com/johngibb/Rails-Resources

Here's what it looks like:

Rails-resources-screenshot

Let me know if you find it useful!