Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)That's it!
| #!/usr/bin/env python | |
| """ | |
| Convert camel-case to snake-case in python. | |
| e.g.: CamelCase -> snake_case | |
| Relevant StackOverflow question: http://stackoverflow.com/a/1176023/293064 | |
| """ |
Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)That's it!
| class cached_property(object): | |
| """A decorator that converts a function into a lazy property. The | |
| function wrapped is called the first time to retrieve the result | |
| and then that calculated result is used the next time you access | |
| the value:: | |
| class Foo(object): | |
| @cached_property | |
| def foo(self): |
| #!/usr/bin/env python | |
| import sys, os, time, atexit | |
| from signal import SIGTERM | |
| class Daemon: | |
| """ | |
| A generic daemon class. | |
| Usage: subclass the Daemon class and override the run() method |
| # !/usr/bin/env python | |
| # -*- coding:utf-8 -*- | |
| import sys | |
| import time | |
| import Queue | |
| import threading | |
| import traceback | |
| class ExitException(Exception): |
| #!/usr/bin/env python | |
| import argparse | |
| import ConfigParser | |
| conf_parser = argparse.ArgumentParser( | |
| # Turn off help, so we print all options in response to -h | |
| add_help=False | |
| ) | |
| conf_parser.add_argument("-c", "--conf_file", | |
| help="Specify config file", metavar="FILE") |
| # /etc/init.d/nginx | |
| #! /bin/sh | |
| ### BEGIN INIT INFO | |
| # Provides: nginx | |
| # Required-Start: $all | |
| # Required-Stop: $all | |
| # Default-Start: 2 3 4 5 | |
| # Default-Stop: 0 1 6 |