This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from wsgiref import simple_server | |
def format_html(entries): | |
html = """<html><body><ul>%s</ul></body></html""" | |
return html % entries | |
def format_entries(requested_dir, children): | |
result = [] | |
a = '<li><a href="%s">%s</a></li>' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# in processor.py | |
def site_processor(request): | |
return {'Foo': 'Bar'} | |
# in settings.py | |
from django.conf import global_settings as DEFAULT_SETTINGS | |
TEMPLATE_CONTEXT_PROCESSORS = DEFAULT_SETTINGS.TEMPLATE_CONTEXT_PROCESSORS + ( | |
'myapp.processor.site_processor', | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FooMiddleware(object): | |
def process_request(self, request): | |
pass | |
# in settings.py | |
MIDDLEWARE_CLASSES = ( | |
# ... | |
'myapp.foo.middleware.FooMiddleware', | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Foo</title> | |
<script type="text/javascript"> | |
var ws = new WebSocket("ws://localhost:8888/ws"); | |
ws.onopen = function(){ | |
ws.send("sup?"); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Slow: python test.py | |
# Fast: python test.py -p /path/to/ramdisk | |
import os | |
import sqlite3 | |
# Helper | |
from optparse import OptionParser | |
options = OptionParser() | |
options.add_option("-p", "--prefix", dest="prefix", default='') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo mkdir /tmp/ramdisk | |
sudo chmod 777 /tmp/ramdisk | |
sudo mount -t tmpfs -o size=256M tmpfs /tmp/ramdisk/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class NodeList(list): | |
def __init__(self, root, items): | |
self.root = root | |
super(NodeList, self).__init__(items) | |
def append(self, item): | |
item._parent = self.root | |
super(NodeList, self).append(item) | |
class Node(object): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/python | |
import os | |
def cmd(txt): | |
print '>>> {} <<<'.format(txt) | |
return os.system(txt) >> 8 | |
def test(what): | |
return cmd(what) == 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import pygame | |
class Character(pygame.sprite.Sprite): | |
def __init__(self, *group): | |
super(Character, self).__init__(*group) | |
self.sheet = pygame.image.load('char.png') | |
self.at = 0 | |
self.elapsed = 0 | |
self.rect = pygame.rect.Rect(50, 100, 50, 50) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Define | |
def singledispatch(func): | |
through_map = {} | |
def register(through): | |
def _on(what): | |
through_map[through] = what | |
return what | |
return _on | |
def dispatch(what): |
OlderNewer