Skip to content

Instantly share code, notes, and snippets.

@jtallieu
jtallieu / bnch_latency.py
Last active March 5, 2017 02:41
Gevent latency benchmark script
import sys
import gevent
import timeit
from gevent.event import Event
from plotter import graph_latency, graph_ops
RUNS = [100, 500, 1000, 5000, 10000, 20000, 30000, 60000, 100000, 120000, 150000]
start_event = Event()
greenlets = []
times = []
def connect(args):
con = initialize(args['NAME'], karma=0.001)
con.simple_bind_s(args['USER'], args['PASSWORD'])
return con
pool = DBPool.ConnectionPool(
connect, {
'NAME': 'ldap://ldapserver',
'USER': 'xxxxxxx',
'PASSWORD': 'xxxxx',
class DatabaseWrapper(BaseDatabaseWrapper):
SEARCH_PAGE_SIZE=999
def __init__(self, *args, **kwargs):
super(DatabaseWrapper, self).__init__(*args, **kwargs)
self.charset = "utf-8"
self.creation = DatabaseCreation(self)
self.features = DatabaseFeatures(self)
if django.VERSION > (1, 4):
self.ops = DatabaseOperations(self)
@jtallieu
jtallieu / pyscreen_sample_5.py
Last active September 9, 2016 20:11
Eagle Eye Networks Inc :: Python screening - Debug I
"""
::Eagle Eye Networks Inc.:::
::Python screening::
The following script is purposley written poorly.
Fix the 'magic' function.
"""
def magic(X, additional=[]):
@jtallieu
jtallieu / pyscreen_sample_4.py
Created September 9, 2016 19:26
Eagle Eye Networks Inc. :: Python screening sample - Duplication
"""
::Eagle Eye Networks Inc.:::
::Python screening::
The 'has_dups' function checks an array for
duplicate strings. It's pretty inefficient.
Improve the 'has_dups' function and explain
how you improved it.
"""
@jtallieu
jtallieu / pyscreen_sample_3.py
Last active April 20, 2017 14:34
Eagle Eye Networks :: Python screening sample - Exceptions
"""
::Eagle Eye Networks Inc.:::
::Python screening::
The "SummertimeService" will drive you insane.
It throws random errors. Summertime it works
summertime it don't.
Some errors you can ignore and assume worked,
others you need to reset the service.
@jtallieu
jtallieu / pyscreen_sample_2.py
Last active September 12, 2016 18:39
Eagle Eye Networks Inc. :: Python screening sample - Optimize
"""
::Eagle Eye Networks Inc.:::
::Python screening::
The following script is purposley written poorly.
The City class depends on an external service that is really
slow. Improve the code below so that 'test1' is more performant
but preserves:
- the ability to get a City as a dict or string.
@jtallieu
jtallieu / pyscreen_sample_1.py
Last active September 12, 2016 18:35
Eagle Eye Networks Inc :: Python screening sample - String handling optimization
"""
::Eagle Eye Networks Inc.:::
::Python screening::
The following script is purposley written poorly.
Improve upon the code and explain your improvements.
The id_csv method must return a unicode string of
representation of a comma separated list of uuid's
"""
import dhashpy
_dhash = None
_host = None
_port = None
class DHash(object):
"""Wrap the dhashpy to make the simple things simpler"""
def __init__(self, dhash):
import requests
import datetime
import calendar
import json
token = "------------"
project_id= "--------------"
iron_host = "worker-aws-us-east-1.iron.io/2/projects/%s" % project_id