Category Archives: Uncategorized

Quick and usefull git commands

#Log of all the reference HEAD
$ git reflog

#Go to a previous head
$ git reset –hard HEAD@{0}.

# Check what lines were added?
git log –oneline -p

# Check how many insertions were made
git log –oneline –stat

# Display a visual representation of your git map
git log –oneline –graph

Rake Task Omniauth Identity + carrierwave

I often use rake db:populate in development mode to populate my database with random data. It’s a useful too to test your website and see how it would look like when you have a lot of users. It’s also extremely useful for testing paginations. On I build a script that auto generate random user using the Omniauth Identity gem and then generate random user’s theme that each have an image using the carrierwave gem.

namespace :db do
require ‘Faker’
require ‘omniauth’
desc “Fill database with sample data”
task :populate => :environment do

def make_users

20.times do |n|
name =
email = “test-#{n+1}”
password = “password”

# CREATE USERS: Populate the database with random users
Identity.create! do |user| = name = email
user.password_digest = BCrypt::Password.create(password)
Continue reading

How I set up Paypal Adaptive Payment for

Before you start, you need to create a developer account on and have set u tow user in your paypal sandbox account. One for the merchant, and one for the seller. These account will be use to test this payment here. here will be the sample email I will use to represent the merchant and is the sample email I will use to represent the seller. This payment model is a chained payment which mean that there will be more than one recipient for the amount of the sale.

 In the controller:

class OrdersController < ApplicationController
before_filter :assigns_gateway
include OrderHelper

include ActiveMerchant::Billing::Integrations

Continue reading

Installing Rmagick + ImageMagick on Mac OS 10.7 Lion can be a PITA!

Rmagick is an interface between the Ruby programming language and ImageMagick/GraphicsMagick.

In orde rot install Rmagick YOU’LL NEED ImageMagick pre-instaleld on your machine. Most tutorial will tell you that you just need to type “brew install ImageMagick” then “gem install rmagick” but this option tend to result in an error or bugs. I tried a few method and the one that ended up being my favorite one was cloning the Imagemagick package on my machine and installing it locally via ssh. Thanks to a shell script I was able to Install ImageMagick on Snow Leopard! Here are the directions: 


First you need to download the script. If you have git installed…

cd ~/src git clone git:// cd ImageMagick-sl sh 

At one point, it runs a command using sudo, so it will ask for your password. After the script has finished, ImageMagick will be installed. Now, to install the RMagick gem…

sudo gem install rmagick 

That’s it! 


All the credit goes to Andrew on StackOverflow. Thanks to his post I was able to find a working solution. 

How to build your own gems

Gems are a pretty cool way to share ruby code. I have a lot of fun building my own gems. Here some details on what I did and a useful link to learn how to do the same..

From the RubyGem Guide:

Here the most important details you’ll need to make your gem:

First, start by creating an account on –

Let’s assume that your gem name is “my_totokudo”

Create your gem folder as follow:




my_totokudo.rb is in the subfolder “lib” of your folder “my_totokudo”

Your my_totokudo.rb contains the code of your gem and the gemspec usually contain the specification of your gems, here something you can copy and use. Make sure to edit it as per your need: do |s|        = 'my_string_extend'
  s.version     = '0.0.1'        = '2012-02-13'
  s.summary     = "Short summary"
  s.description = "Description of your gem."
  s.authors     = ["Your Name"]       = [""]
  s.homepage    = ""
  s.files       = ["lib/my_totokudo.rb"]

Before you install and push your gem you need to make sure that the name of your gem isn’t in use already:

$ gem list -r my_totokudo
Then you want to make sure that you have the last version of Rubygems installed:
$ gem update --system
Once you have all the specification of your gem and the .gemspec file ready you can build your gem. In the folder my_totokudo where the .gemspec is located Type:
$ gem build my_totokudo.gemspec

Then install it locally to test it if needed:
$ gem install ./my_string_extend-0.0.1.gem
to test it you'll have to prompt the testing command. Depending of your code and gem, what you may need to test it may varies. To launch the prompt type: 
$ irb --simple-prompt
Then require your gem:
>> require 'my_totokamo'
Do whatever test you need to do here. To exit the prompt type "quit".
Publishing your gem is very simple. You just have to type:
$ gem push my_totokamo-0.0.1.gem
And follow the instruction on the screen.  

If you build exciting Gems please share it with me by sending a mention and a link to your gem on twitter @Richardsondx

The most useful tutorials from to build a website from scratch

I love Ryan Bates’s website He is doing a great job sharing his knowledge and I am actively learning from it everyday since I started programming in Ruby on Rails. Here my personal list of most interesting tutorials I’ve found on it. I think anyone who already understand the MVC relationship and the differences between all type of variables on rails  can build an entire website just by watching, following and applying these tutorials instructions and tips.

– Pretty URL’s with FriendlyId – Episode #315

– Endless Page (revised) – Episode #114

– Paypal Recurring Billing – Episode #289

– ActiveAdmin – Episode #284

– Remember Me & Reset Password – #274

– Geocoder – Episode #273

– Trees with Ancestry – Episode #262

– Authentification from Scratch – Episode #250

– Notifications in Rails 3 – Episode #249

– Charts – Episode #223

– Subdomains in Rails 3 – Episode #221

– Mobile Devices – Episode #199

– Declarative Authorization – Episode #188

– Controllers in Rails 3 – Episode #224

– Routing in Rails 3 – Episode #203

– Validation in Rails 3 – Episode #221

– Nested Model Form Part 1 – Episode #196

– Nested Model Form Part 2 – Episode #197

– Formstatic Part 1 – Episode #184

– Formstatic Part 2 – Episode #185

– Cropping Images – Episode #182

– 7 Security Tips – Episode #178

– Pagination with AJAX – Episode #174

– Integrating Active Merchant – Episode #145

– Paperclip – Episode #134

– Beta Invitations – Episode #124

– Site Wide Announcements – Episode #103

– HTTP Basic Authentication – Episode #82

– Sending Email – Episode #61

– Restricting Access – Episode #20

Nested Ressources

Making association and link with path sound easy, but I’ve found doing it pretty complex. I had an hard time understanding nesting resources. Many tutorial assume that it is easy to grasp and assume that you’ve already a good understandings of how routes work on rails but I found this part pretty challenging. Here a few references that I found very helpful to understand those concepts.

– Rails for Zombies , many people suggest this tutorial to get onto rails but I would suggest Michael Harlt book then The Pragmatic Agile Developer to get onto Rails and once you got a good grasp of those concept to watch Rails for Zombies to see if you fully understood the concepts.

– The Ruby on Rails Guide was very helpful guide to get onto the basic concept of nested resources after you are making association but honestly it didn’t really help me to fully grasp the subject.

 The {Buckblog :here}  Good, especially for understanding path and url in rails.

– [Book] “The Rails 3 Way” is absolutely a great reference for understanding many concept of Rails and the architecture of your app folder and how methods works. Definitely buy this book and put it right next to your keyboard as a reference book

Hope you find these list helpful, feel free to comment with more links.