Skip to content

Instantly share code, notes, and snippets.

import redis
from django.conf import settings
from django.core.signals import request_finished
try:
from eventlet.corolocal import local
except ImportError:
from threading import local
"""
I've been thinking lately about how perfect Redis would be for storing a
simple social graph. I posited that it would be relatively few lines of code,
and that it'd be clean code too. So here it is: a basic social graph built on Redis.
"""
class FriendGraph(object):
def __init__(self, ring):
self.ring = ring
#!/usr/bin/env python
import httplib
import simplejson
# Based on Christian Dowski's iresponse http://blog.dowski.com/2008/04/02/reading-chunked-http11-responses/
class IterableResponse(httplib.HTTPResponse, object):
def __iter__(self):
assert self.chunked != httplib._UNKNOWN, "Response is not chunked!"
from flask import Module, request, redirect, url_for, render_template, abort
from formalchemy import FieldSet
from example import db
from example import Service, User, Forum, Category, Topic, Post
mod = Module(__name__)
models = {
import time
from contextlib import contextmanager
@contextmanager
def easyprofile(msg):
before = time.time()
yield
print '%s took %0.2fsec' % (msg, time.time() - before)
import uuid
import simplejson
import amqplib.client_0_8 as amqp
class SimpleCelery(object):
def __init__(self, task_map, host, port, user, password, exchange, vhost,
ssl=False, retries=5, routing_key='celery'):
self._task_map = task_map
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>ASDF</title>
<style>
.animate {
-webkit-transition-property: -webkit-transform;
-webkit-transition-duration: 2s;
-webkit-transform: matrix3d(0.5, -0.5, -0.707107, 0, 0.853553, 0.146447, 0.5, 0, -0.146447, -0.853553, 0.5, 0, 0, 0, 0, 1);
<ul>
{{#tweets}}
<li>{{text}}</li>
{{/tweets}}
</ul>
import random
import time
from eventlet import patcher, greenpool, pools
patcher.monkey_patch()
import simplegeo
LAYER = 'your.layer.identifier.here'
OAUTH_KEY = 'YOUR OAUTH KEY HERE'
# Copypasta of Django's runserver management command, modified to use gunicorn http://github.com/benoitc/gunicorn
import os
import signal
import sys
import threading
import time
from optparse import make_option