Skip to content

Instantly share code, notes, and snippets.

Avatar

Dan O'Donovan danodonovan

View GitHub Profile
@danodonovan
danodonovan / shared_memory_test.py
Last active Oct 29, 2019
Testing out performance of the multiprocessing.shared_memory in python 3.8
View shared_memory_test.py
from functools import partial
import multiprocessing
from multiprocessing.managers import SharedMemoryManager
import random
import time
NUM_PROCS = 4
@danodonovan
danodonovan / restore.py
Created Jul 18, 2018
Script to restore items deleted from a versioned S3 bueckt
View restore.py
import logging
import boto3
from healx.batching import batched
from healx.iterables import flatten
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__file__)
client = boto3.client('s3')
@danodonovan
danodonovan / cypher.cql
Last active Jan 15, 2018
Handy Neo4j Queries
View cypher.cql
// count all node labels
MATCH (n)
RETURN labels(n), count(DISTINCT n);
// describe metagraph
CALL db.schema();
// list node stats
// Sample some nodes, reporting on property and relationship counts per node.
MATCH (n) WHERE rand() <= 0.1
@danodonovan
danodonovan / test_exit.py
Last active Mar 6, 2017
PyHamcrest not catching SystemExit exception
View test_exit.py
import sys
import unittest
from hamcrest import assert_that, calling, raises
import pytest
def call_exit():
sys.exit()
@danodonovan
danodonovan / parallel_class_call.py
Created Jul 25, 2016
Call a non-static function on a class in parallel.
View parallel_class_call.py
from multiprocessing import Pool
from multiprocessing.pool import ApplyResult
def call_it(instance, name, args=(), kwargs=None):
if kwargs is None:
kwargs = {}
return getattr(instance, name)(*args, **kwargs)
View gist:795f7aad8c8c660f325d
### Keybase proof
I hereby claim:
* I am danodonovan on github.
* I am danodonovan (https://keybase.io/danodonovan) on keybase.
* I have a public key whose fingerprint is 910D 91FB 2702 4C4C 4330 0268 B631 1E01 140A B905
To claim this, I am signing this object:
View automata.py
import bisect
class NFA(object):
EPSILON = object()
ANY = object()
def __init__(self, start_state):
self.transitions = {}
self.final_states = set()
self._start_state = start_state