Skip to content

Instantly share code, notes, and snippets.

View samnang's full-sized avatar
🚀

Samnang Chhun samnang

🚀
View GitHub Profile
@samnang
samnang / console.rb
Created January 2, 2011 02:01
Tips – Simulate Rails Console in Ruby Project
#!/usr/bin/env ruby
app_path = File.expand_path("../", File.dirname(__FILE__))
boot_path = File.join(app_path,"boot")
command = "irb -r irb/completion -r #{boot_path}"
exec command
class A
end
puts "--" + A.instance_methods(false).join(', ')
class A
def otro
end
end
@samnang
samnang / singleton_methods.rb
Created January 15, 2011 04:11
Different ways to define singleton methods
##############################################
# Different ways to define singleton methods #
##############################################
def test_singleton_method
animal = 'dog'
yield animal
puts animal.speak
@samnang
samnang / ruby-1.9-tips.rb
Created February 4, 2011 01:08 — forked from igrigorik/ruby-1.9-tips.rb
0 Ruby 1.9 Tips, Tricks & Features:
def tip(msg); puts; puts msg; puts "-"*100; end
#
# 30 Ruby 1.9 Tips, Tricks & Features:
# http://www.igvita.com/2011/02/03/new-ruby-19-features-tips-tricks/
#
tip "Upgrading to Ruby 1.9 is simple: rvm install 1.9.2 && rvm --default 1.9.2"
tip "Ruby 1.9 supports named captures in regular expressions!"
@samnang
samnang / fix_pg_gem_installation
Created February 24, 2011 11:05
Fix 'gem install pg' on Ubuntu
sudo apt-get install libpq-dev
@samnang
samnang / a.rb
Created March 5, 2011 03:23 — forked from zzak/a.rb
class A
@@a = 1
@a = 2
a = 3
end
@samnang
samnang / .irbrc
Created March 9, 2011 06:59 — forked from jsmestad/.irbrc
# Make gems available
require 'rubygems'
# http://drnicutilities.rubyforge.org/map_by_method/
begin
require 'map_by_method'
rescue LoadError
puts "map_by_method is not installed. To enable, run: gem install map_by_method"
end
@samnang
samnang / increment.js
Created March 19, 2011 18:13
Javascript increment
var i = 1;
var j = ++i; // 2
var i = 1;
var k = i++; // 1
Then /^(?:|I )should see "([^\"]*)"(?: within "([^\"]*)")?$/ do |text, selector|
with_scope(selector) do
if defined?(Spec::Rails::Matchers)
page.should have_xpath("//*[text()='#{text}']", :visible => true)
else
assert page.has_xpath("//*[text()='#{text}']", :visible => true)
end
end
end
require "spec_helper"
describe "group 1" do
it "group 1 example 1" do
end
it "group 1 example 2" do
end
end