Skip to content

Instantly share code, notes, and snippets.

import berry
from berry import path, render, redirect
from models import Post
def index():
posts = Post.query.all()
return render('index', {'posts': posts})
path('^$').GET = index
def post(id):
# test.py
@cmd('^$')
def index():
# this is what shows up when you run python test.py
return "Welcome to test.py..."
@get('^hello (.+)$')
def hello(name):
# this shows up when you run python test.py hello <name>
@adeel
adeel / mail.py
Created August 4, 2009 03:20
simple smtplib wrapper
import smtplib
from smtplib import SMTPException
from email.mime.text import MIMEText
config = {
'host': None,
'port': None,
'username': None,
'password': None,
'use_tls': False,
@adeel
adeel / mplayer.py
Created August 24, 2009 04:09
mplayer wrapper
import os
import time
import subprocess
import threading
import Queue
# c.f.: http://is.gd/2T1p
path = '/usr/bin/mplayer'
http://74.125.95.132/search?q=cache:81MAwvRRt4kJ:twitter.com/_why/status/3389695893
programming is rather thankless. you see your works become replaced by superior works in a year. unable to run at all in a few more.
# How to get the password hint for lib.homelinux.org
import httplib
conn = httplib.HTTPConnection("lib.homelinux.org")
conn.request("HEAD", "/")
print conn.getresponse().getheaders()[3][1].decode("cp1251")
@adeel
adeel / recursive_dict_update.py
Created December 29, 2010 07:03
Like dict.update, but recursive.
def _recursive_dict_update(x, y):
for key, val in y.iteritems():
if isinstance(val, dict):
if not x.has_key(key):
x[key] = {}
x[key] = _recursive_dict_update(x[key], val)
elif isinstance(val, list):
if not x.has_key(key):
x[key] = []
x[key].extend(val)
@adeel
adeel / wdiff-html
Created February 12, 2011 02:13
How to get a word-by-word diff of two text files, and format it as html
#!/bin/sh
FILE1=$1
FILE2=$2
# http://www.gnu.org/software/wdiff/
wdiff -w "<span style='color:red; text-decoration: line-through;'>" \
-x "</span>" \
-y "<span style='color:green'>" \
-z "</span>" \
@adeel
adeel / guillemets.tex
Created February 15, 2011 17:36
LaTeX + guillemets
% This is necessary to use, for example, guillemets («, ») in your LaTeX documents.
\usepackage[utf8]{inputenc}
\usepackage[T2A]{fontenc}
@adeel
adeel / The middleware that could have been
Created April 15, 2011 13:53
pack/middleware/session.py
from pack.middleware.cookies import *
def wrap_session(app, options={}):
store = options.get("store", "memory_store")
cookie_name = options.get("cookie_name", "pack-session")
session_root = options.get("root", "/")
cookie_attrs = dict(options.get("cookie_attrs", {}),
**{"path": session_root})
def wrapped_app(req):