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
package com.novoda.example.MemoryLeaker;
import android.os.Debug;
import android.view.View;
import java.io.File;
import java.io.IOException;
public class HeapDumpOnClickListener implements View.OnClickListener {
private static final String HPROF_DUMP_BASENAME = "MemoryLeaker.dalvik-hprof";
package com.novoda.example.MemoryLeaker;
import android.app.Activity;
import android.os.Bundle;
public class LeakingActivity extends Activity {
...
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
package com.novoda.example.MemoryLeaker;
import android.os.Debug;
import java.io.File;
import java.io.IOException;
public class HeapDumpingUncaughtExceptionHandler implements Thread.UncaughtExceptionHandler {
private static final String HPROF_DUMP_BASENAME = "LeakingApp.dalvik-hprof";
private final String dataDir;
package com.novoda.example.MemoryLeaker;
import android.app.Application;
public class MemoryLeakingApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
Thread.currentThread().setUncaughtExceptionHandler(
package com.novoda.example;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
public class LoggingWorker implements Runnable {
private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
private final int workerId;
@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):