Skip to content

Instantly share code, notes, and snippets.

@jashmenn

jashmenn/gist:6626

Created Aug 21, 2008
Embed
What would you like to do?
nate murray's .irbrc
# Nate Murray's ~/.irbrc
#
# Can be found at:
# http://gist.github.com/6626
# git clone git://gist.github.com/6626.git gist-6626
#
# Include colorization
require 'rubygems'
require 'wirble'
Wirble.init
Wirble.colorize
# Pretty Print
require 'pp'
# Auto Indentation
IRB.conf[:AUTO_INDENT]=true
# Readline-enable prompts.
require 'irb/ext/save-history'
IRB.conf[:USE_READLINE] = true
IRB.conf[:SAVE_HISTORY] = 1000
IRB.conf[:HISTORY_PATH] = File::expand_path("~/.irb.history")
def enable_trace( event_regex = /^(call|return)/, class_regex = /IRB|Wirble|RubyLex|RubyToken/ )
puts "Enabling method tracing with event regex #{event_regex.inspect} and class exclusion regex #{class_regex.inspect}"
set_trace_func Proc.new{|event, file, line, id, binding, classname|
printf "[%8s] %30s %30s (%s:%-2d)\n", event, id, classname, file, line if
event =~ event_regex and
classname.to_s !~ class_regex
}
return
end
def disable_trace
puts "Disabling method tracing"
set_trace_func nil
end
# clipboard code: http://project.ioni.st/post/1334#snippet_1334
class MacClipboard
class << self
def read
IO.popen('pbpaste') {|clipboard| clipboard.read}
end
def write(stuff)
IO.popen('pbcopy', 'w+') {|clipboard| clipboard.write(stuff)}
end
end
end
# automate creating pasties
require 'net/http'
def pastie
url =
pastie_url = Net::HTTP.post_form(URI.parse("http://pastie.caboo.se/pastes/create"),
{"paste_parser" => "ruby",
"paste[authorization]" => "burger",
"paste[body]" => MacClipboard.read}).body.match(/href="([^\"]+)"/)[1]
MacClipboard.write(pastie_url)
system("open #{pastie_url}")
pastie_url
end
alias :pst :pastie
def products(sku, opts={})
Product.find_by_sku(sku.to_s, opts)
end
def sites(short_name, opts={})
Site.find_by_short_name(short_name.to_s, opts)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.