Skip to content

Instantly share code, notes, and snippets.

@fabware
fabware / gist:305572
Created February 16, 2010 14:57 — forked from apit/gist:284705
"""
Usage:
import debug
class BaseHandler(tornado.web.RequestHandler):
def get_error_html(self, status_code, **kwargs):
if self.application.settings['debug']:
return debug.display(self, kwargs['exception'])
'''
Copyright 2010 Josiah Carlson
Released into the public domain
copy_redis.py
A convenient utility function for copying data from one redis server to
another.
Requires http://github.com/andymccurdy/redis-py .
------------ model.py ----------------
meta = MetaData()
usersession_table = Table('kg_usersession', meta,
Column('session_id', String(32), primary_key=True),
Column('user_id', BigInteger, index=True, nullable=False),
Column('create_time', DateTime, index=True),
Column('expire_time', DateTime, index=True),
Column('site', String(10)),
---------- clients.py ----------
class PikaPubSubSubscribeClient(object):
def __init__(self, message_processor,
host,
port,
virtual_host,
username,
password,
--------- clients.py --------
class PikaPubSubPublishClient(object):
def __init__(self, host=settings.APP_MESSAGER_DEFAULT_HOST,
port=settings.APP_MESSAGER_DEFAULT_PORT,
virtual_host=settings.APP_MESSAGER_DEFAULT_VIRTUALHOST,
username=settings.APP_MESSAGER_DEFAULT_USERNAME,
password=settings.APP_MESSAGER_DEFAULT_PASSWORD,
exchange_name='ground',
#------------- consumer ---------------
import simplejson
def check_callable(cb):
if not callable(cb):
raise TypeError("callback isn't a callable")
class ConsumerBase(object):
@fabware
fabware / webdis_slow_qps.py
Created May 24, 2011 08:57
webdis slow publish rps compared with raw client
--------- webdis_consumer.py ----------
# -*- coding: utf-8 -
import simplejson
import httplib
def check_callable(cb):
if not callable(cb):
raise TypeError("callback isn't a callable")
@fabware
fabware / applications.py
Created May 26, 2011 08:05
tornadio crash tornado iostream
# -*- coding: utf-8 -*-
import os
import tornado
import tornadio
from handlers import PostMessageHandler, MessageConnection
import settings
MessageRouter = tornadio.get_router(MessageConnection, resource='message/*', extra_re='\d+', extra_sep='/')
@fabware
fabware / js_cookie.js
Created May 31, 2011 06:32
javascript cookie
@fabware
fabware / gist:1008924
Created June 5, 2011 12:33 — forked from jslatts/gist:1008072
Example of using connect session cookies with socket.io
socket.on('connection', function(client){
// helper function that goes inside your socket connection
client.connectSession = function(fn) {
if (!client.request || !client.request.headers || !client.request.headers.cookie) {
disconnectAndRedirectClient(client,function() {
console.log('Null request/header/cookie!');
});
return;
}