Skip to content

Instantly share code, notes, and snippets.

View anthonywu's full-sized avatar

Anthony Wu anthonywu

  • Silicon Valley / Bay Area
View GitHub Profile
@anthonywu
anthonywu / graceful_auto_reconnect.py
Created January 29, 2012 01:25
Gracefully handle a PyMongo AutoReconnect
import functools
import pymongo
import logging
import time
MAX_AUTO_RECONNECT_ATTEMPTS = 5
def graceful_auto_reconnect(mongo_op_func):
"""Gracefully handle a reconnection event."""
@functools.wraps(mongo_op_func)
@anthonywu
anthonywu / quick_enums.py
Created February 1, 2012 23:50
Python enum classes
# Author: Anthony Wu
# A quick way to make Python enum classes.
# Uses range/enumerate to quickly generate a list of enumerated values,
# but only safe/useful for your application logic where you don't have
# to persist these values to a data store.
# Example A: hard code enum classes
class Fruits(object):
@anthonywu
anthonywu / human_enum.py
Created February 27, 2012 00:43
Python Human Enums
"""
Copyright (c) 2012 Anthony Wu, twitter.com/anthonywu
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
@anthonywu
anthonywu / py_tuple_unpack.py
Created February 29, 2012 23:13
Python args tuple unpacking
def foobar(a, b, c, (username, password)=(None,None)):
print a, b, c, username, password
foobar(1, 2, 3, ('hello','world')) # 1 2 3 hello world
foobar(1, 2, 3) # prints "1 2 3 None None"
@anthonywu
anthonywu / update_ubuntu_old_release.sh
Created March 9, 2012 23:08
Redirecting Ubuntu apt-get to old-releases
# Point end-of-life Ubuntu versions' apt source URLs to old-releases.*
# See: https://help.ubuntu.com/community/EOLUpgrades
sudo sed -i s/us.archive.ubuntu/old-releases.ubuntu/g /etc/apt/sources.list
sudo sed -i s/security.ubuntu/old-releases.ubuntu/g /etc/apt/sources.list
sudo apt-get update
@anthonywu
anthonywu / dot_emacs.el
Created March 29, 2012 05:42
my dot emacs
(add-to-list 'load-path "~/.emacs-lisp")
;; Auto-Complete
(require 'anything)
;; Python nice-to-haves
(require 'lambda-mode)
(add-hook 'python-mode-hook #'lambda-mode 1)
(setq lambda-symbol (string (make-char 'greek-iso8859-7 107)))
@anthonywu
anthonywu / osx_pdf_join.sh
Created April 18, 2013 02:35
Mac OS X – bash function to join pdfs on the command line
function pdf_join {
join_py="/System/Library/Automator/Combine PDF Pages.action/Contents/Resources/join.py"
read -p "Name of output file > " output_file && "$join_py" -o $output_file $@ && open $output_file
}
@anthonywu
anthonywu / fb-git-review-install.sh
Created May 8, 2013 17:54
Install Facebook git-review on OS X
# checkout git-review from GitHub and install
# note: this is not the same git-review available via pip installer
git clone git@github.com:facebook/git-review.git
cd git-review/
sudo python setup.py install
# assuming you have Homebrew installed
brew install tkdiff
@anthonywu
anthonywu / install_ubuntu_chrome.sh
Created May 8, 2013 18:02
Install Google Chrome on Ubuntu
# run with sudo user privileges
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
sudo sh -c 'echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list'
sudo chmod 644 /etc/apt/sources.list.d/google-chrome.list
sudo apt-get update
sudo apt-get install google-chrome-stable
@anthonywu
anthonywu / quick_install_memcached_mac.sh
Created May 8, 2013 18:23
Quick install memcached on Mac OS X
# install via Homebrew
brew install memcached
# optional: make memcached start along with the system
ln -sfv /usr/local/opt/memcached/*.plist ~/Library/LaunchAgents
# load memcached now for immediate use
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.memcached.plist
# check the process that just launched