public
Last active

  • Download Gist
irbrc.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
%W{rubygems
wirble
fileutils
what_methods
mechanize
xmlsimple
open-uri
gdata
json
open-uri
pp}.each do |requirement|
begin
require requirement
rescue LoadError => e
puts "load error: #{e}"
end
end
 
alias q exit
 
# gotta make sure IRB doesn't crash if something goes funky
begin
IRB.conf[:AUTO_INDENT]=true
 
defined? Wirble and Wirble.colorize
 
include FileUtils if defined? FileUtils
 
defined? WWW::Mechanize and @safari = WWW::Mechanize.new { |agent| agent.user_agent_alias = 'Mac Safari' }
 
# some twitter fun
if defined? JSON
module Twitter
def self.search(query,options={})
data = { :q => query }
data.merge!(options)
params = data.map do |k,v|
[CGI.escape(k.to_s),CGI.escape(v.to_s)] * "="
end
puts url = "http://search.twitter.com/search.json?#{params.join('&')}"
open(url) { |line| data = JSON.parse(line.read) }
data
end
end
 
# lets search some tweets
def twitter(query=nil,options={})
Twitter.search(query,options)
end
end
 
# reload files
def rl(*files)
files.map! do |file|
file << '.rb' unless file =~/\.rb$/
end
(@recent_files ||= []) + files
@recent_files.each { |file| load "#{file}" }
end
 
# temp directory to perform some operations
def temp
@timestamp = Time.now.to_i
dir = "/tmp/backup+#{@timestamp}"
mkdir_p dir
begin
cd dir { yield }
ensure
rm_rf dir
end
end
 
def ls(arg='*')
Dir[arg]
end
 
def cd(arg= '.')
Dir.chdir(arg)
Dir.pwd
end
 
# fun object extensions
class Object
def m
methods - Object.methods
end
# The hidden singleton lurks behind everyone
def metaclass
class << self
self
end
end
 
def meta_eval &blk
metaclass.instance_eval &blk
end
 
# Adds methods to a metaclass
def meta_def name, &blk
meta_eval { define_method name, &blk }
end
end
 
# quick password generation
def password(length = 8)
key = Time.new.to_s
cypher = ([*'A'..'Z']+[*0..9])
a = cypher[rand(36)].to_s
a += cypher[rand(36)].to_s
key.crypt(a)[0..length]
end
 
rescue Error => e
puts "Error: #{e}"
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.