Skip to content

Instantly share code, notes, and snippets.


Alvin Liang aliang

View GitHub Profile
View virtus-multiparameter_attributes.rb
# Rails datetime_select and similar use multiparameter attributes which are
# these dawful things from the bowels of activerecord and actionpack. This
# module extends virtus models to coerce multiparameter attributes back together
# before assigning attributes.
# Here's the implementation for ActiveRecord:
# and DataMapper:
aliang / knife.rb
Created Jul 23, 2012 — forked from wilmoore/knife.rb
Base "knife" configuration for a standard chef-solo setup
View knife.rb
# .chef/knife.rb
# SEE:
# set some sensible defaults
current_dir = File.dirname(__FILE__)
log_level :debug
log_location STDOUT
node_name `hostname`
client_key ''
aliang / knife.rb
Created Mar 22, 2012 — forked from jtimberman/knife.rb
Commented knife.rb for all the things
View knife.rb
# Knife Configuration File.
# This is a Ruby DSL to set configuration parameters for Knife's
# general options. The default location for this file is
# ~/.chef/knife.rb. If multiple Chef repositories are used,
# per-repository configuration files can be created. A per repository
# configuration file must be .chef/knife.rb in the base directory of
# the Chef repository. For example,
# ~/Development/chef-repo/.chef/knife.rb
aliang /
Created Feb 18, 2012 — forked from mikhailov/
Nginx+passenger application config: ssl redirection, http headers, passenger optimal settings. see details:
$ cd /usr/src
$ wget
$ tar xzvf ./nginx-0.8.52.tar.gz
$ rm ./nginx-0.8.52.tar.gz
$ gem install s3sync capistrano capistrano-ext passenger --no-ri --no-rdoc
$ passenger-install-nginx-module
# Automatically download and install Nginx? 2. No: I want to customize my Nginx installation
# Where is your Nginx source code located?: /usr/src/nginx-0.8.52
# Where do you want to install Nginx to?: /opt/nginx
aliang /
Created Jan 22, 2012 — forked from remcoder/
Compile LESS to CSS automatically whenever a file is modified
#!/usr/bin/env python
# determines filename and extension, then delegates compiling the LESS files to lessc via a shell command
import sys, os.path
from subprocess import call
src = sys.argv[1]
base,ext = os.path.splitext(src)
aliang / Mac SSH Autocomplete
Created Jun 14, 2011
Add auto complete to your ssh, put into your .bash_profile
View Mac SSH Autocomplete
_complete_ssh_hosts ()
comp_ssh_hosts=`cat ~/.ssh/known_hosts | \
cut -f 1 -d ' ' | \
sed -e s/,.*//g | \
grep -v ^# | \
uniq | \
grep -v "\[" ;
aliang / devise_http_rememberable.rb
Created Jun 13, 2011 — forked from jamiew/devise_http_rememberable.rb
Monkeypatch Devise to support saving sessions via HTTP auth (e.g. via bookmarklets or browser addons)
View devise_http_rememberable.rb
# config/initializers/devise_http_rememberable.rb
# Monkeypatch Devise so HTTP authentication sets remember_user_token cookie
# ABR: Always Be Remembering
module Devise
module Strategies
class Authenticatable < Base
def remember_me?
# Devise's implementation of this is:
# valid_params? && Devise::TRUE_VALUES.include?(params_auth_hash[:remember_me])
aliang / omniauth.rb
Created Jun 7, 2011 — forked from dira/omniauth.rb
OmniAuth strategy for a custom provider
View omniauth.rb
module OmniAuth
module Strategies
# tell OmniAuth to load our strategy
autoload :Pixelation, 'lib/pixelation_authorization'
Rails.application.config.middleware.use OmniAuth::Builder do
provider :twitter, "app_name", "secret"
provider :facebook, "app_name", "secret", :scope => ''
aliang / migrate_s3.rake
Created Jun 6, 2011
rake task to migrate paperclip attachments to Amazon S3
View migrate_s3.rake
namespace :attachments do
task :migrate_to_s3 => :environment do
require 'aws/s3'
# Load credentials
s3_options = YAML.load_file(File.join(Rails.root, 'config/s3.yml')).symbolize_keys
bucket = s3_options[:bucket_name]
# Establish S3 connection
aliang / fakeout.rake
Created Apr 3, 2011 — forked from matthutchinson/fakeout.rake
fill your database with crap using faker
View fakeout.rake
# a simple/configurable rake task that generates some random fake data for the app (using faker) at various sizes
# NOTE: requires the faker or ffaker gem
# sudo gem install faker -
# OR
# sudo gem install ffaker -
require 'faker'
class Fakeout