Skip to content

Instantly share code, notes, and snippets.

View carlosbrando's full-sized avatar

Carlos Brando carlosbrando

View GitHub Profile
@carlosbrando
carlosbrando / gist:777816
Created January 13, 2011 12:55
Chain Gang with Ruby
class Query
def initialize(model)
@model = model
end
def where(hash)
@where = hash
self
end
@macournoyer
macournoyer / tm_reveal_in_github.rb
Created January 14, 2011 15:31
Reveal in GitHub TextMate command
#!/usr/bin/env ruby
# Reveal in GitHub TextMate command
require 'pathname'
path = Pathname.new(ENV["TM_FILEPATH"]).relative_path_from(Pathname.new(ENV["TM_PROJECT_DIRECTORY"]))
repo_path = `/usr/local/bin/git remote show origin`[/Fetch URL: git@(.*)\.git$/, 1].tr(":", "/")
branch = `/usr/local/bin/git symbolic-ref HEAD`[/refs\/heads\/(.*)$/, 1]
exec "open 'http://#{repo_path}/blob/#{branch}/#{path}'"
@carlosbrando
carlosbrando / app_config.rb
Created January 14, 2011 16:33
Exemplo de configuração usando OpenStruct
require 'ostruct'
AppConfig = OpenStruct.new
AppConfig.default_email = "no-reply@example.com"
AppConfig.api_url = "staging.someapi.com"
@carlosbrando
carlosbrando / Gemfile
Created January 17, 2011 18:11
Debug funcionando de acordo com a versão no Bundler
group :development, :test do
gem 'ruby-debug', :platforms => :ruby_18
gem 'ruby-debug19', :platforms => :ruby_19
end
@bryanl
bryanl / campfire-emoji.txt
Created January 27, 2011 16:34
campfire emoji
Surround these with : e.g. :calling:
+1
-1
bulb
calling
clap
cop
email
feet
@igrigorik
igrigorik / ruby-1.9-tips.rb
Created February 3, 2011 17:19
Ruby 1.9 features, tips & tricks you may not know about...
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!"
@carlosbrando
carlosbrando / gist:810238
Created February 3, 2011 21:28
Delegates
require "delegate"
class Assistant
def initialize(name)
@name = name
end
def read_email
"(#{@name}) It's mostly spam."
end
@carlosbrando
carlosbrando / gist:810656
Created February 4, 2011 02:40
Flat Scope
my_var = "Success"
MyClass = Class.new do
puts "#{my_var} in the class definition!"
define_method :my_method do
puts "#{my_var} in the method!"
end
end
@carlosbrando
carlosbrando / gist:810666
Created February 4, 2011 02:51
Shared Scope
def define_methods
shared = 0
Kernel.send :define_method, :counter do
shared
end
Kernel.send :define_method, :inc do |x|
shared += x
end
@carlosbrando
carlosbrando / gist:810670
Created February 4, 2011 02:58
Context Probe
class Myclass
def initialize
@v = 1
end
end
obj = Myclass.new
obj.instance_eval do
p self
p @v # => 1