Skip to content

Instantly share code, notes, and snippets.

Alvin Liang aliang

  • Recovers
  • Burlingame, CA
Block or report user

Report or block aliang

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
@aliang
aliang / each_by_page.rb
Last active Dec 16, 2015
helper to iterate all by pagination using kaminari
View each_by_page.rb
# Probably should investigate how to chain this with scopes
# Also assumes mongoid with a default _id field, and the order_by method
class MyModel
def self.each_by_page(options = {})
per = options[:per] || 25
order_by = options[:order_by] || [:_id, 1]
i = 1
until (current_page = self.order_by(order_by).page(i).per(per)).empty?
current_page.each do |obj|
@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 / gist:1507475
Created Dec 21, 2011
recursive globbing
View gist:1507475
def find_files(directory, pattern):
for root, dirs, files in os.walk(directory):
for basename in files:
if fnmatch.fnmatch(basename, pattern):
filename = os.path.join(root, basename)
yield filename
for f in find_files(".", "*.txt"):
print f
@aliang
aliang / gist:1393029
Created Nov 25, 2011
monkey patch to make pymongo not throw ridiculous AutoReconnect errors
View gist:1393029
# Stolen from http://paste.pocoo.org/show/224441/
from pymongo.cursor import Cursor
from pymongo.connection import Connection
from pymongo.errors import AutoReconnect
from time import sleep
def reconnect(f):
def f_retry(*args, **kwargs):
@aliang
aliang / parse_query.rb
Created Jun 20, 2011
search query string parser, google-ish
View parse_query.rb
# via http://jablan.radioni.ca/post/4982485974/parsing-search-query-in-ruby
def parse_query s
s.scan(/((\S+)\:\s?)?([+-])?(("(.+?)")|(\S+))/).map{|match|
Hash[
[nil, :prefix, :plusminus, nil, nil, :phrase, :word].zip(match).select(&:all?)
]
}
end
@aliang
aliang / triangles.html
Created Jun 20, 2011
triangles without images
View triangles.html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<title>Triangle</title>
<meta charset="utf-8" />
<style type="text/css">
.a{width:0;height:0;border-top:100px solid #0099ff;border-left:100px solid #ff9900;border-right:100px solid #F6402D;border-bottom:100px solid #8CC63E; float:left;}
.b{
width:0;height:0;border-top:100px solid #0099ff;border-left:100px solid transparent;border-right:100px solid transparent;border-bottom:0; margin-left:60px; float:left;}
.c{width:0;height:0;border-top:100px solid transparent;border-left:0;border-right:100px solid transparent;border-bottom:100px solid #0099ff; margin-left:60px; float:left;}
@aliang
aliang / Mac SSH Autocomplete
Created Jun 14, 2011 — forked from jordandcarter/Mac SSH Autocomplete
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 "\[" ;
You can’t perform that action at this time.