Skip to content

Instantly share code, notes, and snippets.

@avdi
avdi / example.rb
Created Oct 30, 2009
Rack::Stereoscope
View example.rb
require 'sinatra'
require 'json'
require 'addressable/uri'
require File.expand_path('rack_stereoscope.rb', File.dirname(__FILE__))
configure do
use Rack::Reloader;
use Rack::Lint;
use Rack::Stereoscope;
end
@myronmarston
myronmarston / output
Created Feb 8, 2011
YAML modifies strings when it serializes them. What the crap?
View output
$ ruby --version
ruby 1.9.2p136 (2010-12-25 revision 30365) [x86_64-darwin10.5.0]
$ ruby yaml_bug.rb
YAML modifies strings when it serializes them!
Original: "1\n \n2"
Modified: "1\n\n2"
View my_awesome_spec.rb
require 'spec_helper'
describe "Registration" do
before(:all) do
FakeWeb.allow_net_connect = true
end
after(:all) do
FakeWeb.allow_net_connect = false
View foo.rb
# encoding: iso8859-1
require 'yaml'
x = "Antonio Giménez Muñoz"
x.force_encoding('BINARY')
p x.encode('UTF-8')
View argh.rb
# encoding: utf-8
Encoding.default_external = 'utf-8'
Encoding.default_internal = 'utf-8'
ENV["LANG"] = 'en_US.UTF-8'
require 'psych' if ARGV.first == 'p'
require 'yaml'
puts 'hello: "h\xc3\xa4gar"'
@clarkware
clarkware / gist:1046693
Created Jun 25, 2011
View Source for Ruby
View gist:1046693
# Toss this in your ~/.irbrc file for a convenient way
# to peruse Ruby source code in TextMate. This
# only works in Ruby 1.9!
#
# Use it in irb like so:
#
# >> require 'active_record'
# >> ActiveRecord::Base.source_for_method(:create)
class Object
@justinko
justinko / gist:1509034
Created Dec 22, 2011
Avdi Grimm's creation, pulled from Objects on Rails
View gist:1509034
def stub_module(full_name)
full_name.to_s.split(/::/).inject(Object) do |context, name|
begin
context.const_get(name)
rescue NameError
context.const_set(name, Module.new)
end
end
end
View show_redis_keys.sh
cat redis_keys.txt | cut --delimiter=: -f 1,2 | sort | uniq -c | sort -r -n
View watchable.rb
module Watchable
def events
@events ||= Hash.new { |h,k| h[k] = [] }
end
def fire event, *args
events[event].each { |e| e[*args] }
end
def on event, &block
@eric
eric / bundle-outdated-github.rb
Created Mar 8, 2012
Annotate your "bundle outdated" with GitHub compare URLs
View bundle-outdated-github.rb
#!/usr/bin/env ruby
#
# Annotate your "bundle outdated" with GitHub compare URLs
#
require 'open-uri'
require 'json'
def rubygems_gem_info(gem_name)