Skip to content

Instantly share code, notes, and snippets.

View moea's full-sized avatar

Moe Aboulkheir moea

  • Nervous Systems, Ltd.
  • London
View GitHub Profile
@moea
moea / gist:9766808
Last active August 29, 2015 13:57
Test Style
# instead of
userColl = (yield client.getUserCollection())._coll
self.assertEqual(userColl[0]['userID'],"TestUser")
self.assertEqual(len(userColl[0]['userDeviceAddresses']),2)
self.assertTrue(userColl[0]['userDeviceAddresses'][0]=="DD:DD:DD:DD" or userColl[0]['userDeviceAddresses'][1]=="DD:DD:DD:DD")·
# i would go with something like
(userColl,) = (yield client.getUserCollection())._coll # will assign _coll[0] to userColl and explode unless there is exactly one item
self.assertEqual(userColl['userID'], 'TestUser') # consistent use of either single or double quotes
self.assertEqual(sorted(userColl['userDeviceAddress']), ['AA:AA...', 'DD:DD...']) # more managable than checking each element as above, and checks that both are in there.
@moea
moea / gist:6b2fb84a40457ea3bc51
Created April 29, 2014 20:13
Parallel encounter validation
@requiresMongo
@defer.inlineCallbacks
def getEncountersForUser(self, userID, startTime, endTime, areEncountering=lambda a, b: defer.succeed(True)):
user = yield findOne(self.users, col.userID == userID).execute()
user = ref.user(user)
def maybeInclude(encountering, u, row):
if encountering:
return (u, row)
return ()
from twisted.internet import reactor, defer
from tornado.platform.twisted import TwistedIOLoop
import nsq
from nsq import Writer, Error
from nsq.async import AsyncConn
# This doesn't work - the client errors with a failed send, and nsqd (when
# invoked with nsqd --verbose, outputs:
# 2014/06/01 21:26:09 TCP: new client(127.0.0.1:53443)
from twisted.internet import reactor, defer
from tornado.platform.twisted import TwistedIOLoop
import nsq
from nsq import Writer, Error
from nsq.async import AsyncConn
# This doesn't work - the client errors with a failed send, and nsqd (when
# invoked with nsqd --verbose, outputs:
# 2014/06/01 21:26:09 TCP: new client(127.0.0.1:53443)
@moea
moea / interfaces.py
Created June 11, 2014 00:34
interfaces sketch
from zope.interface import implements, Interface
class ILimitedProfile(Interface):
"""
Marker interface for basic profile functionality.
"""
def doLimited():
pass
class IFullProfile(ILimitedProfile):
import datrie, random, geohash, guppy, time, itertools
ghashBase32Chars = '0123456789bcdefghjkmnpqrstuvwxyz'
def timeme(func):
def wrapper(*arg,**kw):
t1 = time.time()
res = func(*arg,**kw)
t2 = time.time()
return (t2-t1), res
import random, geohash, guppy, itertools, time
def randomHash():
lat = (random.random() * 180) - 90
lng = (random.random() * 360) - 180
return geohash.encode(lat, lng)
def insert(d, hash, userId):
for c in hash[:11]:
d = d.setdefault(c, {})
(defmacro broken
[x]
(println (into {} (map (fn [[k v]] [(name k) (mapv str v)]) x))))
(broken x x {:a [a] :b [b]} x)
diff --git a/vendor/clojure.el b/vendor/clojure.el
index d9cfbd3..884cd66 100644
--- a/vendor/clojure.el
+++ b/vendor/clojure.el
@@ -13,3 +13,9 @@
(add-hook 'cider-repl-mode-hook 'subword-mode)
(add-hook 'cider-repl-mode-hook 'paredit-mode)
(add-hook 'cider-repl-mode-hook 'rainbow-delimiters-mode)
+
+(defun extend-indent ()
(ns encounters.geo
(:require [geohash.core :as geohash]))
(def ^:dynamic *geohash-precision* 1)
(def ^:dynamic *radius-km* 6371.009)
(defn great-circle-distance
([lat lon lat' lon']
(great-circle-distance lat lon lat' lon' *radius-km*))