Skip to content

Instantly share code, notes, and snippets.

@avdi
avdi / example.rb
Created October 30, 2009 22:28
Rack::Stereoscope
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 February 8, 2011 02:47
YAML modifies strings when it serializes them. What the crap?
$ 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"
require 'spec_helper'
describe "Registration" do
before(:all) do
FakeWeb.allow_net_connect = true
end
after(:all) do
FakeWeb.allow_net_connect = false
# encoding: iso8859-1
require 'yaml'
x = "Antonio Giménez Muñoz"
x.force_encoding('BINARY')
p x.encode('UTF-8')
# 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 June 25, 2011 17:37
View Source for Ruby
# 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 December 22, 2011 05:22
Avdi Grimm's creation, pulled from Objects on Rails
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
cat redis_keys.txt | cut --delimiter=: -f 1,2 | sort | uniq -c | sort -r -n
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 March 8, 2012 06:11
Annotate your "bundle outdated" with GitHub compare URLs
#!/usr/bin/env ruby
#
# Annotate your "bundle outdated" with GitHub compare URLs
#
require 'open-uri'
require 'json'
def rubygems_gem_info(gem_name)