Skip to content

Instantly share code, notes, and snippets.

require 'benchmark'
include Benchmark
class Weeble
attr_reader :name, :age, :salary, :language
def initialize(name, age, salary, language)
@name, @age, @salary, @language = name, age, salary, language
end
def sorter
options.scan(/\w+=\w+/).inject({}) { |h,opt| k,v = opt.split('=',2); h[k] = v; h }
require 'benchmark'
class Validated
def valid?
true
end
end
c1 = [Validated.new]
c10 = c1 * 10
Host project1.github.com
HostName github.com
User git # Probably not needed but just a note if you want to skip it
IdentityFile ~/.ssh/your_key_file
IdentitiesOnly yes # This is only if you want to avoid trying other identities which can speed things up a bit.
# at the very least, use inheritance!
class Object
alias_method :try, :send
end
class NilClass
def try(*args)
nil
end
class ApplicationController < ActionController::Base
around_filter :you_are_here
def you_are_here
puts "***** NEW ACTION: #{controller_name} - #{action_name} *****"
begin
yield
ensure
puts "<pre>"
if $! then
export PS1="\[\033[36m\]\h:\W>\[\033[0m\] "
export PS1="\[\033[36m\]\h:\w \[\033[33m\]\$(parse_git_branch)\$(parse_svn_branch)\[\033[00m\]$\[\033[00m\] "
# drop this in config/initializers/count_fix.rb to work around
# hmt/named_scope count bug https://rails.lighthouseapp.com/projects/8994/tickets/2189
class ActiveRecord::Base
protected
def self.construct_count_options_from_args(*args)
name_and_options = super
name_and_options[0] = '*' if name_and_options[0].is_a?(String) && name_and_options[0] =~ /\.\*$/
name_and_options
end
# require_here.rb
# by Josh Susser
class String
# __FILE__.require_here 'foo' # => require 'CURRENT_DIR/foo'
# __FILE__.require_here %w(lib foo) # joins path segments so you don't have to
# __FILE__.require_here # add the current file's directory to the load path
def require_here(path=nil)
here = File.expand_path(File.dirname(self))
if path
# an object representing a duck type that can be used in a case expression
class Protocol
def initialize(*selectors)
@selectors = selectors
end
def ===(object)
@selectors.all? {|selector| object.respond_to?(selector)}
end
end