Skip to content

Instantly share code, notes, and snippets.

View kaiwren's full-sized avatar

Sidu Ponnappa kaiwren

View GitHub Profile
@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
~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 / 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)
~ λ 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 / net_http_debug.rb
Created September 22, 2010 12:48
Enable debug for all Ruby HTTP requests
require 'net/http'
module Net
class HTTP
def self.enable_debug!
raise "You don't want to do this in anything but development mode!" unless Rails.env == 'development'
class << self
alias_method :__new__, :new
def new(*args, &blk)
instance = __new__(*args, &blk)
instance.set_debug_output($stderr)
@kaiwren
kaiwren / write_to_clipboard.rb
Created October 3, 2010 21:20
Write any string to the clipboard in OSX
IO.popen('pbcopy', "w").tap{|io| io.write "some string"}.close
ruby-1.8.7-p174 > u = URI.parse('http://foo:bar@localhost:3000')
=> #<URI::HTTP:0x101e2bc40 URL:http://foo:bar@localhost:3000>
ruby-1.8.7-p174 > u.user=nil
=> nil
ruby-1.8.7-p174 > u
=> #<URI::HTTP:0x101e2bc40 URL:http://localhost:3000>
ruby-1.8.7-p174 > u.to_s
=> "http://localhost:3000"
@kaiwren
kaiwren / quote.txt
Created October 30, 2010 19:16
Managers, management, churches and religion.
The first myth of management is that it exists. Managers are to management as churches are to religion.
@kaiwren
kaiwren / js_route.js
Created January 31, 2011 15:50
js routes from ruby routes
FooNamespace.Routes = {
myResourcePath: function(){ return '<%= my_resource_path(:format => 'json') %>' }
}
@kaiwren
kaiwren / hash_ordering_18.rb
Created February 23, 2011 18:31
Hash ordering in Jruby vs CRuby
~ λ rvm jruby-head
~ λ ruby -v
jruby 1.6.0.dev (ruby 1.8.7 patchlevel 249) (2011-01-13 b9f8624) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_22) [darwin-x86_64-java]
~ λ irb
jruby-head :001 > {:a => :b, :c => :d}.select{true}
=> [[:a, :b], [:c, :d]]
jruby-head :002 > {:a => :b, :c => :d}.select{true}
=> [[:a, :b], [:c, :d]]
jruby-head :003 > {:a => :b, :c => :d}.select{true}
=> [[:a, :b], [:c, :d]]