Skip to content

Instantly share code, notes, and snippets.

@fabware
fabware / listener.js.patch
Created June 5, 2011 14:44
make socket.io resource take a extra argument
*** listener.js.bak 2011-06-05 21:17:31.777158283 +0800
--- listener.js 2011-06-05 22:39:51.097153447 +0800
***************
*** 69,74 ****
--- 69,82 ----
var path = url.parse(req.url).pathname, parts, cn;
if (path && path.indexOf('/' + this.options.resource) === 0){
parts = path.substr(2 + this.options.resource.length).split('/');
+
+ // remove extra from check
@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;
}
@fabware
fabware / js_cookie.js
Created May 31, 2011 06:32
javascript cookie
@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 / 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")
#------------- consumer ---------------
import simplejson
def check_callable(cb):
if not callable(cb):
raise TypeError("callback isn't a callable")
class ConsumerBase(object):
--------- 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',
---------- clients.py ----------
class PikaPubSubSubscribeClient(object):
def __init__(self, message_processor,
host,
port,
virtual_host,
username,
password,
------------ 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)),
'''
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 .