Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)That's it!
| # /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 |
| #!/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") |
| # !/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 sys, os, time, atexit | |
| from signal import SIGTERM | |
| class Daemon: | |
| """ | |
| A generic daemon class. | |
| Usage: subclass the Daemon class and override the run() method |
| 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): |
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 | |
| """ |
| from flask import make_response | |
| from reportlab.pdfgen import canvas | |
| # ... | |
| @app.route('/pdf') | |
| def pdf(): | |
| import cStringIO | |
| output = cStringIO.StringIO() |
| # setting up irq affinity according to /proc/interrupts | |
| # 2008-11-25 Robert Olsson | |
| # 2009-02-19 updated by Jesse Brandeburg | |
| # | |
| # > Dave Miller: | |
| # (To get consistent naming in /proc/interrups) | |
| # I would suggest that people use something like: | |
| # char buf[IFNAMSIZ+6]; | |
| # | |
| # sprintf(buf, "%s-%s-%d", |
| from datetime import datetime | |
| from sqlalchemy import Column, Integer, DateTime, ForeignKey | |
| from sqlalchemy.orm import relationship | |
| from sqlalchemy.ext.declarative import declared_attr | |
| from flask_security import current_user | |
| class AuditMixin(object): | |
| created_at = Column(DateTime, default=datetime.now) | |
| updated_at = Column(DateTime, default=datetime.now, onupdate=datetime.now) |