Skip to content

Instantly share code, notes, and snippets.

import cherrypy
class Application(object):
def index(self):
return "Hello World!"
index.exposed = True
wsgi_app = cherrypy.tree.mount(Application())
#!/bin/sh
GUNICORN=/usr/local/bin/gunicorn
ROOT=/home/thomas/tex2png/
PID=/var/run/gunicorn.pid
BIND=unix:/tmp/gunicorn.sock
WORKERS=2
APP=app:application
if [ -f $PID ]
@pelletier
pelletier / LaTeX in.html
Created April 19, 2010 07:12
Simple script which uses tex2png to convert latex <eq> into PNGs.
<!DOCTYPE>
<html>
<head>
<title>My math web page</title>
<meta charset="utf-8">
<style type="text/css" media="screen">
eq img {
position: relative;
top: 4px;
}
@pelletier
pelletier / Django Debian init script
Created May 13, 2010 08:48
This is a simple Debian init.d script for my self-hosted Django/Gunicorn websites which run inside a virtualenv.
#!/bin/sh
### BEGIN INIT INFO
# Provides: seismic_web
# Required-Start: $local_fs $syslog
# Required-Stop: $local_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Gunicorn processes for seismic_web
### END INIT INFO
def load_modules(path):
"""
Load all Python modules from a directory into a dict.
:param path: the path to the living place of the modules to load.
:type path: :class:`str`
:returns: map between loaded modules name and their content.
:rtype: :class:`dict`
"""
import os, imp
def dict_delta(old, new):
"""
Compute the differences between two versions of a dictionary
>>> dict1 = {\
'ipsum': 'ABC',\
'dsqdq': 'sssdqs',\
'opapoaaz': 'dpqsnqsd',\
'pPlolf': 'popoazn',\
'pfkv': 'blah',\
@pelletier
pelletier / tuple_to_list.erl
Created August 4, 2010 10:20
I know this function already exists, but here is my idea of implementation.
% Converts a tuple to a list.
% {a, b, c, d} -> [a, b, c, d]
tuple_to_list(T) ->
tuple_to_list(T, 0).
tuple_to_list(_T, -1) ->
[];
tuple_to_list(T, Id) ->
Max = tuple_size(T) - 1,
"""
This is a simple example of WebSocket + Tornado + Redis Pub/Sub usage.
Do not forget to replace YOURSERVER by the correct value.
Keep in mind that you need the *very latest* version of your web browser.
You also need to add Jacob Kristhammar's websocket implementation to Tornado:
Grab it here:
http://gist.github.com/526746
Or clone my fork of Tornado with websocket included:
http://github.com/pelletier/tornado
Oh and the Pub/Sub protocol is only available in Redis 2.0.0:
# projectfoo/config/__init__.py
from os import path
ROOT_PATH = path.dirname(path.dirname(path.abspath(__file__)))
DEBUG = True
TEMPLATE_DEBUG = DEBUG
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
This is a simple Twitter to email script.
You need:
- An SMTP server (such as Sendgrid.net).
- A Redis server.
- Python.
Don't forget: