Skip to content

Instantly share code, notes, and snippets.

View val314159's full-sized avatar

val314159 val314159

View GitHub Profile
@val314159
val314159 / yottapubsub.py
Last active September 30, 2015 22:59
Yotta Pub-Sub
#!/usr/bin/env python
class YottaPubSub(object):
def __init__(_): _.sessions, _.channels = {}, {}
def add(_,sid,fun): _.sessions[sid] = fun ; _.sub( sid, [] )
def pop(_,sid): _.sessions.pop( sid ) ; _.channels.pop( sid )
def sub(_,sid,channels): _.channels[sid] = ["*",sid] + channels
def pub(_,sid,channel,msg):
for key,func in _.sessions.iteritems():
if key!=sid and channel in _.channels[key]:
func( sid, channel, msg )
@val314159
val314159 / test_gist.py
Created March 23, 2015 21:26
test gist
print "this is a gist meant to test python API calls for comments"
@val314159
val314159 / level_db.py
Last active August 29, 2015 14:07
db driver for leveldb
from leveldb import LevelDB as _LevelDB
def _DB(_=[]): return (_ or _.append(_LevelDB('.db')) or 1) and _[0]
def ZAP(): list(DLT(k) for k,v in RNG([]))
def DLT(k): _DB().Delete(':'.join(k))
def GET(k): return json.loads(_DB().Get(':'.join(k)))
def PUT(k,v): _DB().Put(':'.join(k),json.dumps(v))
def RNGP(pfx=''):return (((k.split(':'),json.loads(v)) for k,v in
_DB().RangeIter(pfx,pfx+'~~~')))
def RNG(k=[]): return RNGP(':'.join(k))
def DLT1P(del_pfx): return ( DLT( k ) for k,v in RNG(del_pfx) )
@val314159
val314159 / env.sh
Last active August 29, 2015 14:06
qsvr.py
source .v/bin/activate
run_qsvr () { python -u qsvr.py; }
run () { python -u qsvr.py; }
launch_qsvr () { python -u qsvr.py 1>LOG 2>&1 &}
launch () { python -u qsvr.py 1>LOG 2>&1 &}
unlaunch () { killall -9 python; }
cln () { rm -fr .? *.pyc *~ 2>/dev/null; }
$*
'''
small util lib for cors handling (in bottle)
'''
def add_headers(response):
'''
call this to slap the proper CORS headers into any dict-like object
'''
#allow_methods = ', '.join(['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'OPTIONS'])
allow_methods = ', '.join(['GET', 'HEAD', 'POST', 'OPTIONS'])
allow_headers = ', '.join(['Origin', 'X-Requested-With', 'Content-Type',