Skip to content

Instantly share code, notes, and snippets.

Avatar
👋

Anhang Zhu anhang

👋
  • San Francisco, CA
View GitHub Profile
View Easy Rails deployment with rsync
from: http://blog.anhangzhu.com/2016/05/03/easy-rails-deployment-with-rsync/
First, have an rsync_exclude file:
// my-rails-app/.rsync_exclude
.bundle
tmp
log
Run in localhost:
$ bundle exec rake assets:precompile
@anhang
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"})
IRB.conf[:PROMPT_MODE] = :RAILS_ENV
end
@anhang
anhang / database.yml
Created Dec 7, 2012
standard database.yml
View database.yml
# SQLite version 3.x
# gem install sqlite3
development:
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
anhang / file_randomize
Created Aug 12, 2011
Unix Script to randomize file names
View file_randomize
for i in *
do
mv "$i" "$RANDOM.JPG"
done
View html_parse_params
// Super basic html parser written with regex.
// Experimental and untested
function parseParams(str){
return JSON.parse("{"+
str.replace(/.+?=.+?(&|$)/g,
function(part){ return part.replace(/(.+)(=)([^&]+)(&*)/,
function(x, key, eq, val, com){return ["\"",key,"\"",":","\"",val,"\"",(com ? "," : '')].join('');})
}) +"}");
}
@anhang
anhang / localStorage.js
Created Jul 20, 2011
HTML5 Local Storage with Expiration
View localStorage.js
AZHU.storage = {
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;}