Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
%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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.