Skip to content

Instantly share code, notes, and snippets.

View daf's full-sized avatar
✴️
halp

Dave Foster daf

✴️
halp
View GitHub Profile
@daf
daf / sample_subscriber.py
Created January 6, 2011 16:46
Sample uses of the subscriber class within the context of a process
class SampleProcess(Process):
###
### 1. Subclass subscriber to override what you want
###
class ANFSubscriber(Subscriber):
def ondata(self, data):
print "custom handling of ANF data"
diff --git a/ion/core/messaging/messaging.py b/ion/core/messaging/messaging.py
index 61a8930..1bca0cd 100644
--- a/ion/core/messaging/messaging.py
+++ b/ion/core/messaging/messaging.py
@@ -212,15 +212,8 @@ class Consumer(messaging.Consumer):
@param config is a dict of amqp options that __init__ extracts.
"""
connection = ex_space.connection # broker connection
- # @TODO: Exchange config dict should not clobber the passed in config dict -
- # it means that I cannot create a queue with auto_delete=False if the
@daf
daf / inttest_ingest.py
Created March 24, 2011 20:02
integration test for ingestion
#!/usr/bin/env python
"""
@file inttest_ingest.py
@author Dave Foster <dfoster@asascience.com>
@test
"""
import ion.util.ionlog
from twisted.internet import defer
@daf
daf / gist:1187211
Created September 1, 2011 20:39
lrudict bug
diff --git a/ion/util/cache.py b/ion/util/cache.py
index cdee405..3555ffd 100644
--- a/ion/util/cache.py
+++ b/ion/util/cache.py
@@ -125,9 +125,14 @@ class LRUDict(object):
def purge(self):
while self.total_size > self.limit:
if self.first == self.last:
+ obj = self.first.me[1]
+ if hasattr(obj, 'clear'):
@daf
daf / walk.py
Created October 19, 2011 20:23
walker for discovery of items in python enumerables
#!/usr/bin/python
def walk(o, cb):
if hasattr(o, '__iter__'):
if isinstance(o, dict):
return dict(((k, walk(v, cb)) for k,v in o.iteritems()))
else:
return [walk(x, cb) for x in o]
else:
return cb(o)
@daf
daf / ipy-gevent.py
Created October 26, 2011 00:01
ipython embedded and greenlets?
#!/usr/bin/env python
from gevent import spawn, joinall
import time
import IPython
def work():
while True:
time.sleep(2)
print "Hello"
@daf
daf / damon.py
Created October 26, 2011 15:04
CC with daemonize 100% cpu
#!/usr/bin/env python
from daemon import DaemonContext
from lockfile import FileLock
import time
with DaemonContext(pidfile=FileLock('down.pid')):
from pyon.public import Container
print "hello"
time.sleep(15)
@daf
daf / mpt.py
Created November 2, 2011 17:11
msgpack speed tests
#!/usr/bin/python
import msgpack
import os
import time
import base64
def packit(data_size):
data = base64.urlsafe_b64encode(os.urandom(data_size))
st = time.time()
@daf
daf / channel.py
Created December 1, 2011 16:27
Skeleton channel rework
class BaseChannel2(object):
_amq_chan = None
def __init__(self, close_callback=None):
"""
Initializes a BaseChannel instance.
@param close_callback The method to invoke when close() is called on this BaseChannel. May be left as None,
@daf
daf / transport.py
Created February 10, 2012 19:57
new underlying transport abstraction for classes
#!/usr/bin/env python
"""
Transport layer abstractions
TODOS:
- port _sync_call from Channel layer for better error flow, add close callback to channel/client
"""
__author__ = 'Dave Foster <dfoster@asascience.com>'