Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)That's it!
| function slugify(text) | |
| { | |
| return text.toString().toLowerCase() | |
| .replace(/\s+/g, '-') // Replace spaces with - | |
| .replace(/[^\w\-]+/g, '') // Remove all non-word chars | |
| .replace(/\-\-+/g, '-') // Replace multiple - with single - | |
| .replace(/^-+/, '') // Trim - from start of text | |
| .replace(/-+$/, ''); // Trim - from end of text | |
| } |
| """ | |
| Implementation of memoization decorator in Python. | |
| Written by Christian Stigen Larsen | |
| http://csl.sublevel3.org | |
| Put in the public domain by the author, 2012 | |
| This is an example of how to use decorators to implement different kind of | |
| behaviour in Python. |
Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)That's it!
| # Thanks to @samsonjs for the cleaned up version: | |
| # https://gist.github.com/samsonjs/4076746 | |
| PREFIX=$HOME | |
| VERSION=1.2.3 | |
| # Install Protocol Buffers | |
| wget http://protobuf.googlecode.com/files/protobuf-2.4.1.tar.bz2 | |
| tar -xf protobuf-2.4.1.tar.bz2 | |
| cd protobuf-2.4.1 |
| This playbook has been removed as it is now very outdated. |
| #! /usr/bin/env python | |
| # Of course, the author does not guarantee safety. | |
| # I did my best by using SQLite's online backup API. | |
| from __future__ import print_function | |
| import sys, ctypes | |
| from ctypes.util import find_library | |
| SQLITE_OK = 0 | |
| SQLITE_ERROR = 1 | |
| SQLITE_BUSY = 5 |
| #!/bin/bash | |
| # Script for installing tmux on systems where you don't have root access. | |
| # tmux will be installed in $HOME/local/bin. | |
| # It's assumed that wget and a C/C++ compiler are installed. | |
| # exit on error | |
| set -e | |
| TMUX_VERSION=1.8 |
I run a lot of web servers for different projects, all of them on different ports. Generally I start with port 8000 and increment from there as I spin up new servers, but it became tiresome to remember what projects were running on which ports and what the next available port was.
/etc/hosts won't let you specify a port, but a combination of aliasing 127.0.0.1 to 127.0.0.X, forwarding ports from 8000 to 80, and adding the 127.0.0.X IP under an alias in /etc/hosts did work.
This script finds the next available value of X, aliases it with ifconfig, forwards the given port to port 80 with ipfw, and adds a new entry to /etc/hosts that aliases the IP to the domain you want.
Now I can add a server alias with sudo domain-alias funproject 8000, run the web server at 127.0.0.X:8000, and load up http://funproject/ in my browser.
(Because I needed it to work on a Mac, I couldn't use iptables. pfctl seems to work.)
| #!/usr/bin/env python | |
| """Simple HTTP Server With Upload. | |
| This module builds on BaseHTTPServer by implementing the standard GET | |
| and HEAD requests in a fairly straightforward manner. | |
| """ |