Skip to content

Instantly share code, notes, and snippets.

View anhang's full-sized avatar
👋

Anhang Zhu anhang

👋
  • San Francisco, CA
View GitHub Profile
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 February 22, 2013 08:53
~/.irbrc that shows Rails environments
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 December 7, 2012 22:47
standard 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 August 12, 2011 05:22
Unix Script to randomize file names
for i in *
do
mv "$i" "$RANDOM.JPG"
done
@anhang
anhang / html_parse_params
Created August 3, 2011 22:47
HTML Params parser
// 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 July 20, 2011 23:07
HTML5 Local Storage with Expiration
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;}