Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)That's it!
| from flask import Flask, request, redirect, url_for, make_response, abort | |
| from werkzeug import secure_filename | |
| from pymongo import Connection | |
| from pymongo.objectid import ObjectId | |
| from gridfs import GridFS | |
| from gridfs.errors import NoFile | |
| ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif']) | |
| DB = Connection().gridfs_server_test | |
| FS = GridFS(DB) |
| # A fixed @jsonify decorator for Pylons that allows for | |
| # class implemented __json__ serializers | |
| from decorator import decorator | |
| from pylons.decorators.util import get_pylons | |
| import warnings | |
| import json | |
| import logging | |
| log = logging.getLogger(__name__) |
| # SEE: http://d.hatena.ne.jp/shim0mura/20110730/1312046133 | |
| # SEE: https://gist.github.com/1031961 | |
| # SEE: http://atrpms.net/documentation/install/ | |
| # 1. prepare | |
| $ cat /etc/yum.repos.d/atrpms.repo | |
| [atrpms-stable] | |
| name=ATrpms RHEL5 stable | |
| baseurl=http://dl.atrpms.net/el5-$basearch/atrpms/stable/ | |
| gpgkey=http://ATrpms.net/RPM-GPG-KEY.atrpms |
| """SSL client/server certificates verification for `urllib2`. | |
| It works on Python 2.6, 2.7, 3.1, 3.2 | |
| It also works on Python 2.4, 2.5 if `ssl` is installed (``pip install ssl``) | |
| Example:: | |
| >>> import urllib2, urllib2_ssl | |
| >>> opener = urllib2.build_opener(urllib2_ssl.HTTPSHandler( | |
| ... key_file='clientkey.pem', |
| #! -*- Coding: utf-8 -*- | |
| from gevent import monkey | |
| monkey.patch_all() | |
| import gevent | |
| import time | |
| from envoy import run | |
| from sys import exit, argv | |
| import subprocess | |
| import pip |
Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)That's it!
| wget -q -O - https://raw.github.com/gist/2204072/install_tmux_1.6_on_ubuntu_10.04.sh | sudo bash |
| var parser = document.createElement('a'); | |
| parser.href = "http://example.com:3000/pathname/?search=test#hash"; | |
| parser.protocol; // => "http:" | |
| parser.hostname; // => "example.com" | |
| parser.port; // => "3000" | |
| parser.pathname; // => "/pathname/" | |
| parser.search; // => "?search=test" | |
| parser.hash; // => "#hash" | |
| parser.host; // => "example.com:3000" |
| import urllib2 | |
| def xiami_decode(s): | |
| s = s.strip() | |
| if not s: | |
| return False | |
| result = [] | |
| line = int(s[0]) | |
| rows = len(s[1:]) / line | |
| extra = len(s[1:]) % line |
| body { | |
| font-family: Helvetica, arial, sans-serif; | |
| font-size: 14px; | |
| line-height: 1.6; | |
| padding-top: 10px; | |
| padding-bottom: 10px; | |
| background-color: white; | |
| padding: 30px; } | |
| body > *:first-child { |