Skip to content

Instantly share code, notes, and snippets.

Anhang Zhu anhang

Block or report user

Report or block anhang

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View Easy Rails deployment with rsync
First, have an rsync_exclude file:
// my-rails-app/.rsync_exclude
Run in localhost:
$ bundle exec rake assets:precompile
anhang / .irbrc
Created Feb 22, 2013
~/.irbrc that shows Rails environments
View .irbrc
if Rails.env
rails_env = Rails.env.production? ? 'PROD' : Rails.env[0...3].downcase
current_app = Dir.pwd.split('/').last.capitalize
IRB.conf[:PROMPT].reverse_merge!(:RAILS_ENV => {:PROMPT_I=>"#{current_app} #{rails_env} >> ", :PROMPT_N=>"#{current_app} #{rails_env} >> ", :PROMPT_S=>nil, :PROMPT_C=>"?> ", :RETURN=>"=> %s\n"})
anhang / database.yml
Created Dec 7, 2012
standard database.yml
View database.yml
# SQLite version 3.x
# gem install sqlite3
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
anhang / file_randomize
Created Aug 12, 2011
Unix Script to randomize file names
View file_randomize
for i in *
mv "$i" "$RANDOM.JPG"
View html_parse_params
// Super basic html parser written with regex.
// Experimental and untested
function parseParams(str){
return JSON.parse("{"+
function(part){ return part.replace(/(.+)(=)([^&]+)(&*)/,
function(x, key, eq, val, com){return ["\"",key,"\"",":","\"",val,"\"",(com ? "," : '')].join('');})
}) +"}");
anhang / localStorage.js
Created Jul 20, 2011
HTML5 Local Storage with Expiration
View localStorage.js = {
save : function(key, jsonData, expirationMin){
if (!Modernizr.localstorage){return false;}
var expirationMS = expirationMin * 60 * 1000;
var record = {value: JSON.stringify(jsonData), timestamp: new Date().getTime() + expirationMS}
localStorage.setItem(key, JSON.stringify(record));
return jsonData;
load : function(key){
if (!Modernizr.localstorage){return false;}
You can’t perform that action at this time.