Skip to content

Instantly share code, notes, and snippets.

@Sutto
Created January 13, 2009 03:28
Show Gist options
  • Save Sutto/46308 to your computer and use it in GitHub Desktop.
Save Sutto/46308 to your computer and use it in GitHub Desktop.
# Require RubyGems by default.
require 'rubygems'
# Require UtilityBelt for lots of functionality
# http://utilitybelt.rubyforge.org/
require 'utility_belt'
UtilityBelt::Equipper.equip(:defaults)
UtilityBelt::Equipper.equip(:with, :string_to_proc, :pipe, :pastie, :not,
:language_greps, :is_an, :google,
:convertable_to_file, :clipboard,
:interactive_editor)
# Require PrettyPrint cuz it pwns...how did I not know about this?
require 'pp'
# Requiring some awesome libs for console
# http://drnicwilliams.com/2006/10/12/my-irbrc-for-consoleirb/
# require 'map_by_method'
# require 'what_methods'
# Benchmarking
require 'benchmark'
def bench(n=1e3,&b)
Benchmark.bmbm do |r|
r.report {n.to_i.times(&b)}
end
end
class Object
def local_methods(obj = self)
(obj.methods - obj.class.superclass.instance_methods).sort
end
end
# Use the simple prompt if possible.
IRB.conf[:PROMPT_MODE] = :SIMPLE if IRB.conf[:PROMPT_MODE] == :DEFAULT
if ENV['RAILS_ENV']
# QUERYING
module ActiveRecord
class Base
def self.[](*ids)
find(*ids)
end
end
end
def sql(query)
ActiveRecord::Base.connection.select_all(query)
end
require 'logger'
Object.const_set(:RAILS_DEFAULT_LOGGER, Logger.new(STDOUT))
def loud_logger
set_logger_to Logger.new(STDOUT)
end
def quiet_logger
set_logger_to nil
end
def set_logger_to(logger)
ActiveRecord::Base.logger = logger
ActiveRecord::Base.clear_active_connections!
end
else
UtilityBelt::Equipper.equip(:symbol_to_proc)
end
def ring_server(force = false)
if force || @__rs.nil?
require 'rinda/ring'
DRb.start_service
@__rs = Rinda::RingFinger.primary
end
return @__rs
rescue RuntimeError
@__rs = nil
return nil
end
def say(text)
system "say", text.to_s
end
def growl(msg, title = "hallo thar!", sticky = false)
args = ["growlnotify", "-n", "irb", "-m", msg, title]
args << "-s" if sticky
system(*args)
end
def notify
if block_given?
yield
growl "I'm done", "notify via irb", true
say "Done!"
else
say "Give me a block, dumb ass."
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment