Created
June 26, 2013 18:03
-
-
Save jashmenn/5869778 to your computer and use it in GitHub Desktop.
put in ~/.irbrc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# vim: set ft=ruby | |
# | |
# 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' | |
# https://github.com/carlhuda/bundler/issues/183#issuecomment-1149953 | |
if defined?(::Bundler) | |
global_gemset = ENV['GEM_PATH'].split(':').grep(/ruby.*@global/).first | |
if global_gemset | |
all_global_gem_paths = Dir.glob("#{global_gemset}/gems/*") | |
all_global_gem_paths.each do |p| | |
gem_path = "#{p}/lib" | |
$LOAD_PATH << gem_path | |
end | |
end | |
end | |
require 'wirble' | |
require 'pry' | |
Wirble.init | |
Wirble.colorize | |
# Pretty Print | |
require 'pp' | |
# Auto Indentation | |
IRB.conf[:AUTO_INDENT]=true | |
# Readline-enable prompts. | |
require 'irb/completion' | |
require 'irb/ext/save-history' | |
ARGV.concat [ "--readline", "--prompt-mode", "inf-ruby" ] | |
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 | |
$:.unshift(File.expand_path("~/lib/ruby")) | |
# paste whatever is in the clipboard to gist using gisit from http://gist.github.com/5774 | |
# and MacClipboard code from http://project.ioni.st/post/1334#snippet_1334 | |
# this goes in your ~/.irbrc | |
# * todo, change code to update an existing gist | |
def gistit | |
require 'mechanize' | |
require 'gistit' | |
gist = Gistit.new | |
number = gist.paste(MacClipboard.read) # => 12345 | |
gist_url = Gistit::LOGIN_SUCCESS_URL + number.to_s | |
puts "Pastie is now at: #{gist_url}" | |
MacClipboard.write(gist_url) | |
puts "Saved to clipboard" | |
gist_url | |
end | |
$:.unshift("./lib") | |
# require 'irb_rocket' | |
def linearmap(value, istart, istop, ostart, ostop) | |
ostart + (ostop - ostart) * ((value - istart) / (istop - istart)) | |
end | |
Pry.start | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment