Skip to content

Instantly share code, notes, and snippets.

View kaiwren's full-sized avatar

Sidu Ponnappa kaiwren

View GitHub Profile
~ λ rgc rails3 && rgu rails3 ruby-1.8.7-p302
info: Gemset 'rails3' created.
info: Now using gemset 'rails3'
~ λ /usr/bin/time gem install rails --no-rdoc --no-ri ruby-1.8.7-p302@rails3
Successfully installed activesupport-3.0.0
Successfully installed builder-2.1.2
Successfully installed i18n-0.4.1
Successfully installed activemodel-3.0.0
@kaiwren
kaiwren / do_undo.rb
Created September 10, 2010 09:01
Redefine methods, then undo the change
require 'rubygems'
require 'rspec'
module Redefiner
def redefine(method_name, &block)
self.metaclass.send(:alias_method, "__#{method_name}__", method_name)
self.metaclass.send(:define_method, method_name, &block)
end
def undo(method_name, &block)
~wrest (master)λ gem in vimeo
Successfully installed vimeo-1.2.0
1 gem installed
Installing ri documentation for vimeo-1.2.0...
Building YARD (yri) index for vimeo-1.2.0...
Updating ri class cache with 3871 classes...
Installing RDoc documentation for vimeo-1.2.0...
~wrest (master)λ irb ruby-1.8.7-p174
ruby-1.8.7-p174 > require 'vimeo'
LoadError: no such file to load -- oauth_client
@kaiwren
kaiwren / reality.rb
Created September 6, 2010 12:41
There are more things in heaven and earth.
c = 1
case c
when 1
p "Name"
else
p "yeah!"
end
c == 1 # => true
class ActiveRecord::Base
def self.ignore_fields(fields)
self.class_eval do
define_method(:ignore_fields) do
*fields
end
end
end
end
~ λ wrest
ruby-1.8.7-p174
Ruby 1.8.7, 2009-06-12, i686-darwin10.3.1
Loading Wrest 1.0.0.beta2
ruby-1.8.7-p174 > 'https://api.wordpress.org/secret-key/1.1/salt/'.to_uri.get.body
--> (GET 2164536540 2164536500) https://api.wordpress.org:443/secret-key/1.1/salt/
<-- (GET 2164536540 2164536500) 200 OK (768 bytes 1.74s)
=> "define('AUTH_KEY', 'V|@ z>Iqm~ZugQ+BFG.i0L[%)u Vqi*7y!5-qOzwNkF>a$pfaXdJddR/iF8*U]0)');\ndefine('SECURE_AUTH_KEY', 'z[cv,EiUpJ-C;V+C{Za$WG38xOVUlG!V%4hj;h7xF![x$[1=4M5J/}@/}$NR#K]:');\ndefine('LOGGED_IN_KEY', 'SO~<GlF;(-nBh^9x |s XkYmq62(Ov&u^}DjaTjP kXoN(x*8`Hyv^&28Q.%v;Aa');\ndefine('NONCE_KEY', '[`FfSInp_A:;}.9QVF-2^cPzvz}%3OP:,yBV)xy)%w+V,PgRHO|Bo6lVQmj3_Unw');\ndefine('AUTH_SALT', 'YQdi+v0:=CA r$tU`6OFnN}xXAuayt<PJ&LNLWfSp]e%>KS[*ulU4&4+/RH#*@1<');\ndefine('SECURE_AUTH_SALT', '<{/]x&TsWU~TW7Ik/MCH @b;EEL6w5Z_9Ab!kg+ZPM!UnnL=FVn>gubQDVe]bB4e');\ndefine('LOGGED_IN_SALT', '<+|K{J|S4t`-b|UY4p?0P8<&NJen^>G^kt-Ljd!A1|70N2wzR(5-5o!%!m-?0%n?');\ndefine('NONCE_SALT',
@kaiwren
kaiwren / gist:562205
Created September 2, 2010 12:14 — forked from anonymous/works
class Resource
end
class Record
end
@resource = mock(Resource, :id => '1')
Resource.stub!(:find).and_return([@resource]) # works
Record.stub!(:serialize).and_return(true)
@record = mock(Record, :id => '1', :resource_ids => [1], :current_language => 'de') # fails later with:
# undefined method `serialize' for Spec::Mocks::Mock:Class
@kaiwren
kaiwren / mate_open_gem.rb
Created August 18, 2010 12:17
Open a gem in TextMate (supports opening specific versions)
#!/usr/bin/env ruby -wKU
gemname = ARGV[0]
version = ARGV[1]
exit unless gemname
possible = `gem list #{gemname} | tail`.strip
versions = possible.gsub(/.*\(/, '').gsub(/\)$/, '').split(', ')
if versions.empty?
puts "#{gemname} not found"
exit
@kaiwren
kaiwren / dev_camp_registration_count.rb
Created August 18, 2010 07:25
A one line registration counter for DevCamp Bangalore 2010
# > gem in wrest
# > wrest
# Type out the line below in the Wrest irb shell.
# Of course, we're assuming that you have ruby and that nobody has messed up the table on the wiki :)
"http://devcamp.in/index.php/Bangalore/2010/Registrations".to_uri.get.body.scan(/<tr>/).size
require 'rubygems'
require 'rspec'
describe 'Int with scope' do
class Ooga
def initialize
@bar = 'woot'
end