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 | |
| from flask import request | |
| import json | |
| import requests | |
| import hashlib as hasher | |
| import datetime as date | |
| node = Flask(__name__) | |
| # Define what a Snakecoin block is | |
| class Block: |
| #! /usr/bin/python | |
| """ | |
| This simple script makes it easy to create server certificates | |
| that are signed by your own Certificate Authority. | |
| Mostly, this script just automates the workflow explained | |
| in http://www.tc.umn.edu/~brams006/selfsign.html. | |
| Before using this script, you'll need to create a private |
| #!/bin/bash | |
| aptitude -y install expect | |
| // Not required in actual script | |
| MYSQL_ROOT_PASSWORD=abcd1234 | |
| SECURE_MYSQL=$(expect -c " | |
| set timeout 10 |
| ## Colours and font styles | |
| ## Syntax: echo -e "${FOREGROUND_COLOUR}${BACKGROUND_COLOUR}${STYLE}Hello world!${RESET_ALL}" | |
| # Escape sequence and resets | |
| ESC_SEQ="\x1b[" | |
| RESET_ALL="${ESC_SEQ}0m" | |
| RESET_BOLD="${ESC_SEQ}21m" | |
| RESET_UL="${ESC_SEQ}24m" | |
| # Foreground colours |
| upstream tornadoFrontends { | |
| server 127.0.0.1:8000; | |
| server 127.0.0.1:8001; | |
| server 127.0.0.1:8002; | |
| server 127.0.0.1:8003; | |
| } | |
| server { | |
| listen 80; | |
Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)That's it!
| # coding=utf-8 | |
| from mapreduce import SimpleMapReduce | |
| from simple import FILES, file_parser | |
| def count_err_log(item): | |
| word, occurances = item | |
| return (word, sum(occurances)) |
| use test; | |
| create table rs_myisam ( | |
| follower_id bigint(20) not null, | |
| target_id bigint(20) not null, | |
| created_at datetime not null, | |
| primary key(follower_id,target_id) | |
| ) engine=MyISAM default charset=utf8; | |
| create table rs_innodb ( |
| """ An example of a Linux daemon written in Python. | |
| Based on http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/ | |
| The changes are: | |
| 1 - Uses file open context managers instead of calls to file(). | |
| 2 - Forces stdin to /dev/null. stdout and stderr go to log files. | |
| 3 - Uses print instead of sys.stdout.write prior to pointing stdout to the log file. | |
| 4 - Omits try/excepts if they only wrap one error message w/ another. |
| # vim: tabstop=4 shiftwidth=4 softtabstop=4 | |
| #!/usr/bin/python | |
| import sys | |
| import time | |
| import logging | |
| from daemon import runner | |
| # | |
| # An example daemon main logic application class. | |
| # Just keep writing timestamps to a log file periodically. | |
| # |