This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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>' |
NewerOlder