Skip to content

Instantly share code, notes, and snippets.

View arnab's full-sized avatar

Arnab Deka arnab

View GitHub Profile
@arnab
arnab / mri_1_8.rb
Created November 19, 2010 00:44
Standard Exceptions in Ruby (MRI 1.9 and 1.8) and how to generate them
ruby-1.8.7-p302 > tree_printer.call tree
Exception
IRB::Abort
NoMemoryError
ScriptError
LoadError
NotImplementedError
SyntaxError
SignalException
Interrupt
#
# = Hash Recursive Merge
#
# Merges a Ruby Hash recursively, Also known as deep merge.
# Recursive version of Hash#merge and Hash#merge!.
#
# Category:: Ruby
# Package:: Hash
# Author:: Simone Carletti <weppos@weppos.net>
# Copyright:: 2007-2008 The Authors
@arnab
arnab / rails_202_properties.rb
Created April 9, 2011 04:06
Rails 3.0.6 Properties
# see https://github.com/rails/rails/blob/v2.0.2/railties/builtin/rails_info/rails/info.rb
@properties = {
:ruby => "#{RUBY_VERSION} (#{RUBY_PLATFORM})",
:rubygem => Gem::RubyGemsVersion,
:rails => Rails::VERSION::STRING,
:app_root => File.expand_path(RAILS_ROOT),
:env => RAILS_ENV,
:db_adapter => ActiveRecord::Base.configurations[RAILS_ENV]['adapter'],
:db_schema_version => (ActiveRecord::Migrator.current_version || nil),
@arnab
arnab / word-wrap.css
Created July 11, 2011 23:34
How do you ord-wrap a link
.wrap-words {
word-wrap: break-word;
}
@arnab
arnab / ruby-like-inspect-in-javascript.rb
Created August 5, 2011 15:59
You know you do a console.log(object) and you see a string called "Location" (except if you are in Chrome :)). Well here's the solution...
console.log("%o", window.location);
# From http://nathansjslessons.appspot.com/lesson?id=1080
counter = ( ->
count = 0 # cannot be accessed as it's tied to the closure
f = ->
count += 1
f
)()
console.log counter() # 1
@arnab
arnab / .tmux.conf
Created January 25, 2012 20:23
My dotfiles
# set-option -g prefix C-a
bind-key C-b last-window
unbind % # Remove default binding since we’re replacing
bind | split-window -h
bind - split-window -v
# Set status bar
set -g status-bg black
set -g status-fg white
def some_method(other_method, args)
puts "before"
other_method.call args
puts "after"
end
def other_method(stuff)
puts "other_method called with #{stuff.inspect}"
end
@arnab
arnab / show_available_errors.rb
Created February 23, 2012 17:29
Show available errors in a Ruby environment (so you know to raise the right error)
# From http://weblog.jamisbuck.org/2007/3/7/raising-the-right-exception
exceptions = []
tree = {}
ObjectSpace.each_object(Class) do |cls|
next unless cls.ancestors.include? Exception
next if exceptions.include? cls
next if cls.superclass == SystemCallError # avoid dumping Errno's
exceptions << cls
cls.ancestors.delete_if {|e| [Object, Kernel].include? e }.reverse.inject(tree) {|memo,cls| memo[cls] ||= {}}
@arnab
arnab / .travis.yml
Created March 25, 2012 20:11
set up test db before running tests in travis.ci
before_script: "bundle exec rake db:migrate"