Skip to content

Instantly share code, notes, and snippets.

@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_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_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_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=[]):
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)
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',
@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 = []
@jtallieu
jtallieu / bnch_scheduling.py
Last active March 5, 2017 02:42
Gevent scheduling script to determine scheduling algorithm
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, 100000]
SLEEP_TIME = float(sys.argv[1])
LOAD_TIME = 3
@jtallieu
jtallieu / plotter.py
Created March 5, 2017 02:48
Plotter library function to graph Gevent benchmarks with Plotly
import plotly.plotly as py
from plotly import tools
from plotly.graph_objs import *
from plotly.offline import plot
from numpy import *
# Make a gradient pattern of 12 colors.
N = 12
colors = ['hsl('+str(h)+',50%'+',50%)' for h in linspace(0, 360, N)]
@jtallieu
jtallieu / DotDict.py
Last active August 13, 2017 15:01
Yet another iteration at providing 'dot' access to dict items. DOES NOT COPY with copy.copy()
class Mapping(dict):
"""
Example: Map({'make': 'Toyota'}, model='Tacoma', year=1998, color='white')
"""
def __init__(self, *args, **kwargs):
super(Mapping, self).__init__(*args, **kwargs)
for arg in args:
if isinstance(arg, dict):
for k, v in arg.iteritems():
self[k] = v