Skip to content

Instantly share code, notes, and snippets.

View omaraboumrad's full-sized avatar

Omar Abou Mrad omaraboumrad

View GitHub Profile
@omaraboumrad
omaraboumrad / ramdisk
Created March 19, 2013 15:03
Creating a ramdisk (tmpfs)
sudo mkdir /tmp/ramdisk
sudo chmod 777 /tmp/ramdisk
sudo mount -t tmpfs -o size=256M tmpfs /tmp/ramdisk/
@omaraboumrad
omaraboumrad / test.py
Created March 19, 2013 11:49
sqlite table creation speed.
# 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='')
@omaraboumrad
omaraboumrad / test.html
Created March 12, 2013 12:00
python tornadoweb websocket sample
<html>
<head>
<title>Foo</title>
<script type="text/javascript">
var ws = new WebSocket("ws://localhost:8888/ws");
ws.onopen = function(){
ws.send("sup?");
};
@omaraboumrad
omaraboumrad / middleware.py
Created December 20, 2012 08:23
Django middleware
class FooMiddleware(object):
def process_request(self, request):
pass
# in settings.py
MIDDLEWARE_CLASSES = (
# ...
'myapp.foo.middleware.FooMiddleware',
)
@omaraboumrad
omaraboumrad / processor.py
Created December 20, 2012 08:20
Django context processor
# 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',
)
@omaraboumrad
omaraboumrad / test.py
Created November 12, 2012 23:11
lists files based on requested path (wsgiref playground)
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>'