Skip to content

Instantly share code, notes, and snippets.

Avatar

Alvin Liang aliang

  • Burlingame, CA
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:
#
# https://github.com/rails/rails/blob/11fd052aa815ae0255ea5b2463e88138fb3fec61/activerecord/lib/active_record/attribute_assignment.rb#L113-L218
#
# and DataMapper:
@aliang
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: http://wiki.opscode.com/display/chef/Troubleshooting+and+Technical+FAQ
# set some sensible defaults
current_dir = File.dirname(__FILE__)
user = ENV['OPSCODE_USER'] || ENV['USER']
log_level :debug
log_location STDOUT
node_name `hostname`
client_key ''
@aliang
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
aliang / installation.sh
Created Feb 18, 2012 — forked from mikhailov/installation.sh
Nginx+passenger application config: ssl redirection, http headers, passenger optimal settings. see details: http://mikhailov.posterous.com/nginx
View installation.sh
$ cd /usr/src
$ wget http://nginx.org/download/nginx-0.8.52.tar.gz
$ 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
aliang / build_less.py
Created Jan 22, 2012 — forked from remcoder/build_less.py
Compile LESS to CSS automatically whenever a file is modified
View build_less.py
#!/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
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 ()
{
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
comp_ssh_hosts=`cat ~/.ssh/known_hosts | \
cut -f 1 -d ' ' | \
sed -e s/,.*//g | \
grep -v ^# | \
uniq | \
grep -v "\[" ;
@aliang
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
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'
end
end
Rails.application.config.middleware.use OmniAuth::Builder do
provider :twitter, "app_name", "secret"
provider :facebook, "app_name", "secret", :scope => ''
@aliang
aliang / migrate_s3.rake
Created Jun 6, 2011 — forked from felixalias/migrate_s3.rake
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
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 - http://faker.rubyforge.org
# OR
# sudo gem install ffaker - http://github.com/EmmanuelOga/ffaker
require 'faker'
class Fakeout
You can’t perform that action at this time.