Skip to content

Instantly share code, notes, and snippets.

View sunliwen's full-sized avatar

Liwen S sunliwen

View GitHub Profile
# vim: ft=sh:ts=4:sw=4:autoindent:expandtab:
# Source: https://github.com/django/django/blob/stable/1.5.x/extras/django_bash_completion
# #########################################################################
# This bash script adds tab-completion feature to django-admin.py and
# manage.py.
#
# Testing it out without installing
# =================================
#
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDN0sO2/S6Q19vOz2ZO7Y+TAFzHQb1LCtlbcGNFACq0M3PXFVQ1rTyayiNcrnfz+ckfCZe38IUZLoAJXiqg2A7Ww8vazuG8exdR1+GXWYSAFsAkJkqptQ2B/fl0ZelJZLEVJVDJw4Y0d/oYlhpL8FKuvrHQJLscPfuxB/VxJBxsaWDQvrNb862R/A5A28VpE1/pZRWp1e/6qtDwxhYhJPoPsdur9l8TOWz/AzBpqxpSB3zKGIK07hHBSYtfZXBO8gcOaGU4s+btAodJ5L0U0E3hXlUGc0e+ZYFU6f6Sz2tzYiwPfS9sYVjBN14vzZh4Bz5cZZQurjcgwaPhyxCzh9ql sunliwen@gmail.com
# http://lxml.de/installation.html#using-lxml-with-python-libxml2
STATIC_DEPS=true pip install lxml
@sunliwen
sunliwen / test_json_decimal.py
Last active August 29, 2015 14:08
Demonstrate how to loads/dumps json with float value as decimal.Decimal in Python
import json
import decimal
import pprint
# refs: https://djangosnippets.org/snippets/2410/
# refs: http://stackoverflow.com/questions/1960516/python-json-serialize-a-decimal-object
class DecimalEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, decimal.Decimal):
return float(obj)
@sunliwen
sunliwen / init_nmp.py
Created September 17, 2011 17:53
Fabric install Nginx+PHP-FPM+MySQL on Ubuntu 10.04 LTS
def init_nmp():
install_nginx()
install_php()
install_phpfpm()
def install_nginx():
sudo("add-apt-repository ppa:nginx/stable")
sudo("apt-get update")
sudo("apt-get -y -q install nginx-full nginx-common")
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>org.mongodb.mongod</string>
<key>ProgramArguments</key>
<array>
<string>/opt/local/bin/mongod</string>
@sunliwen
sunliwen / keys_memcached
Last active December 16, 2015 13:48
redis command "KEYS *" for memcached
# It's not possible to have a "KEYS *" command in memcached directly
# but could achieve by two steps
➜ ~ telnet 127.0.0.1 11211
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
set one 0 60 1
1
STORED
@sunliwen
sunliwen / Preferences.sublime-settings
Created May 24, 2013 16:12
My Sublime Text 2 user settings
{
"color_scheme": "Packages/Color Scheme - Default/Solarized (Dark).tmTheme",
"font_size": 15.0,
"draw_white_space": "selection",
"trim_trailing_white_space_on_save": true,
"tab_size": 2,
"translate_tabs_to_spaces": true,
"tab_completion": true,
"save_on_focus_lost": true,
"highlight_line": true
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/handlebars.js/1.0.0-rc.3/handlebars.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/ember.js/1.0.0-rc.6/ember.min.js"></script>
<link href="http://getbootstrap.com/dist/css/bootstrap.css" rel="stylesheet" type="text/css" />
<script src="http://getbootstrap.com/dist/js/bootstrap.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
# Ubuntu upstart file at /etc/init/mongodb.conf
limit nofile 32768 32768
kill timeout 300 # wait 300s between SIGTERM and SIGKILL.
pre-start script
mkdir -p /data/mongodb &> /dev/null
mkdir -p /data/logs/mongo &> /dev/null
chown mongodb:nogroup /data/mongodb &> /dev/null