This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gevent | |
from gevent import monkey | |
monkey.patch_all() | |
import os | |
os.environ['MONKEY'] = "True" | |
import pickle | |
import socket | |
r, w = socket.socketpair() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gevent | |
from gevent import monkey | |
monkey.patch_all() | |
import os | |
os.environ['MONKEY'] = "True" | |
import io | |
from multiprocessing import Pipe | |
from gevent.socket import wait_read, wait_write |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Imagine a situation where you have two functions | |
that operate on the same hashable resource (it has an ID). | |
And that those two functions can be called from various | |
threads that you have no control over. Each of these functions | |
can run multiple times and concurrently. Once one of the | |
functions for a resource is called, neither of the functions | |
can be allowed to run. | |
In specific terms, I have post_save and post_delete Django |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
This script till toggle the analytics feature on an esn in a tenant account. | |
To disable the analytics, you must delete the 'active_application' settings in | |
the user settings of the camera. In order to re-enable the feature, you must | |
add the settings back to the 'active_settings'. To accomplish this, we must | |
store the settings somewhere in the camera settings so that when we want to | |
enable we can copy the settings from somewhere. This script uses | |
'inactive_application' to hold the settings for us. You may choose another | |
name if you like. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Gevent example to illustrate using AsyncResults from a greenlet | |
I wanted to launch a pool or workers that would generate data | |
that is provided through an iterator. | |
""" | |
import random | |
import time | |
import gevent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import operator | |
class Filter(object): | |
""" | |
Filter class to filter on properties of a dict. | |
Arguments: property, op, value | |
Will type the existing value of the dictionary |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TagMap(dict): | |
""" | |
Interpret tag values {<model>:{name: value}, ..} and wrap to get '.' access to the value. | |
data = {'general': [('joey', 10), ('x y', 22)], 'een': ('ken', 30)]} | |
tm = TagMap(data) | |
print tm.joey | |
print tm['x y'] | |
print tm.x_y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
NewerOlder