Skip to content

Instantly share code, notes, and snippets.

@pbrit
pbrit / install-ruby-debug-ubuntu-ruby-1.9.3
Created December 7, 2011 10:34 — forked from boriscy/install-ruby-debug-ubuntu-ruby-1.9.3
ruby-debug in ruby-1.9.3 and ubuntu
#To install ruby-debug on Ubuntu ruby-1.9.3 you need to download from http://rubyforge.org/frs/?group_id=8883
linecache19-0.5.13.gem
ruby_core_source-0.1.5.gem
ruby-debug19-0.11.6.gem
ruby-debug-base19-0.11.26.gem
#Then in your console
export RVM_SRC=/your/path/to/ruby-1.9.3
@pbrit
pbrit / time_diff_with_nano
Created May 15, 2012 18:11
Time diff with nanosec
def diff t2, t1
nsec = t2.nsec - t1.nsec
sec = (t2 - t2.nsec) - (t1 - t1.nsec)
sec + nsec
end
@pbrit
pbrit / decode rails devise cookie session
Created August 10, 2012 11:54
decode rails devise cookie session
@pbrit
pbrit / text.sh
Created August 16, 2012 23:12
Shell command for download and execute sort algorithm
curl -s https://gist.github.com/gists/f5f20c1d973dd6c3ebdb/download | tar -xO | ruby -- - "`ruby -e 'require "pp"; pp (1..1000).to_a.shuffle'`" :desk
@pbrit
pbrit / merge_sort.rb
Created August 17, 2012 00:27
Naive implementation of merge sort
require 'pp'
def merge_sort(array,dir = :ask)
pp array if $VERBOSE
raise ArgumentError, "direction must be :ask or :desk symbol" unless [:ask,:desk].include? dir
return array if array.count == 1
array.reverse!
middle = array.count / 2
right, left = array[0...middle].reverse, array[middle..-1].reverse
pp [left,right] if $VERBOSE
@pbrit
pbrit / capybara cheat sheet
Created August 18, 2012 19:49 — forked from zhengjia/capybara cheat sheet
capybara cheat sheet
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
@pbrit
pbrit / unicorn worker clean up
Created August 22, 2012 08:58
Force shutdown all worker on a node
for pid in $(ps ax | grep unicorn | grep -v grep | awk '{ print $1 }'); do sudo kill -9 $pid; done
@pbrit
pbrit / gist:3433391
Created August 23, 2012 06:29
Show last migration file
ls db/migrate | grep `rake db:version | egrep -o '\w+$'`
@pbrit
pbrit / gist:3433600
Created August 23, 2012 06:54
Make your migration reversible always
rake db:migrate && rake db:rollback && rake db:migrate
@pbrit
pbrit / gist:3501799
Created August 28, 2012 18:30
To test Rails FormBuilder in IRB
include ActionView::Helpers::FormOptionsHelper