Skip to content

Instantly share code, notes, and snippets.

# ---------
# Prompt
# ---------
function gitprompt {
blue='\[\e[0;34;1m\]'
red='\[\e[0;38;1m\]'
green='\[\e[0;32;1m\]'
none='\[\e[0m\]'
prompt_info=""
require 'ruby2ruby'
require 'parse_tree'
#########################
# Description: Dumps class source. Does not work for some core class.
#
# Example: MyClass.code
#
########################
require 'ruby2ruby'
git remote rm heroku
git remote add heroku git@heroku.com:newname.git
source_url=source_url.com
app_name=app_name
# We download the full webside content
wget --mirror -r $source_url
# We move the web content into the rack public folder
mkdir -p $app_name/public
mv $source_url/* $app_name/public
rm -rf $source_url
# Tmp files
*.orig
*.swp
*.dot
# Source control files
.hgignore
.hg*
**/*.svn
.svn
class BlankSlate
instance_methods.each { |m| undef_method m unless m =~ /^__/ }
end
class MyProxy < BlankSlate
def initialize(obj, &proc)
@proc = proc
@obj = obj
end
require 'tempfile'
def vi(txt, arguments_str = "")
Tempfile.open('rubyview') do | file |
file << txt
file.close
cmd = "vim #{arguments_str} \"#{file.path}\""
system( cmd )
end
end
# Currently running gems
gems = Gem.loaded_specs.map{|name, spec| [name, spec.version.version]}
extend Hirb::Console
table gems
module RemoteCopy
def rmcp(filename)
s3_connect
full_path = File.expand_path(filename)
basename = File.basename(full_path)
S3Object.store("file_name.txt", basename, 'RemoteClipboard')
S3Object.store("content", File.open(full_path), 'RemoteClipboard')
end
AWS::S3::Base.establish_connection!(
:access_key_id => ENV['AMAZON_ACCESS_KEY_ID'],
:secret_access_key => ENV['AMAZON_SECRET_ACCESS_KEY']
)
def remote_serve(file_content, ext = "html", expires_in = 60 * 60 * 2 * 365)
# To generate a unique filename to avoid name colision
filename = Digest::SHA1.hexdigest(file_content + Time.now.to_s) + "." + ext.to_s
bucket_name = 'RemoteAccess'
obj = AWS::S3::S3Object.store(filename, file_content, bucket_name)