This file contains hidden or 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
| ''' | |
| Implementation of piece-wise parabolic quantile estimation, algorithm defined in | |
| http://www.cs.wustl.edu/~jain/papers/ftp/psqr.pdf | |
| ''' | |
| from math import copysign | |
| DEFAULT_LEVELS = (0.1, 1, 2, 5, 10, 25, 50, 75, 80, 85, 90, 95, 98, 99, 99.5, 99.8, 99.9, 99.99) | |
| class Measure(object): |
This file contains hidden or 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
| ''' | |
| Efficient online statistics gathering. Create a Stats object to track | |
| as many statistics as desired. | |
| Implementation of piece-wise parabolic quantile estimation, algorithm defined in | |
| http://www.cs.wustl.edu/~jain/papers/ftp/psqr.pdf | |
| ''' | |
| from math import copysign |
This file contains hidden or 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 Sample(object): | |
| ''' | |
| This class implements Reservoir Sampling to keep a random sample of an infinite stream. | |
| See http://gregable.com/2007/10/reservoir-sampling.html for one description. | |
| ''' | |
| def __init__(self, sample_size=2**14, type='f'): | |
| self.sample = array.array(type) | |
| self.sample_size = sample_size | |
| self.num_vals = 0 |
This file contains hidden or 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 parsley | |
| GRAMMAR = ''' | |
| digit = :x ?(x in '0123456789') -> x | |
| digit1_9 = :x ?(x in '123456789') -> x | |
| digits = (digit1_9:first <digit*>:rest -> first + rest) | '0' | |
| integer = ('-' | -> ''):sign digits:ds -> int(sign + ds) | |
| alpha_ = :x ?(x.isalpha() or x == '_') -> x | |
| alphanum_ = :x ?(x.isalnum() or x == '_') -> x |
This file contains hidden or 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
| ''' | |
| Computation of higher order statistics based on | |
| http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Higher-order_statistics | |
| Intended for use in long-running applications. | |
| ''' | |
| class Stats(object): | |
| def __init__(self): |
This file contains hidden or 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
| ''' | |
| JKS file format decoder. | |
| Use in conjunction with PyOpenSSL to translate to PEM, or load private key and certs | |
| directly into openssl structs and wrap sockets. | |
| See http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/sun/security/provider/JavaKeyStore.java#JavaKeyStore.engineLoad%28java.io.InputStream%2Cchar%5B%5D%29 | |
| ''' | |
| import struct | |
| import hashlib |
This file contains hidden or 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 heapq | |
| import collections | |
| import time | |
| import random | |
| import greenlet | |
| #import faststat | |
| class Simulation(object): |
This file contains hidden or 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 code | |
| from gevent import fileobject | |
| _green_stdin = fileobject.FileObject(sys.stdin) | |
| _green_stdout = fileobject.FileObject(sys.stdout) | |
| def _green_raw_input(prompt): | |
| _green_stdout.write(prompt) | |
| return _green_stdin.readline()[:-1] |
This file contains hidden or 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 threading | |
| import functools | |
| import gc | |
| import types | |
| class ObjBrowserThread(threading.Thread): | |
| def __init__(self): | |
| threading.Thread.__init__(self) | |
| self.daemon = True |
This file contains hidden or 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
| ''' | |
| Two main jobs: | |
| 1- calculate the desired position | |
| 2- accelerate towards that position | |
| Several acceleration profiles: | |
| "spring" acceleration -- acceleration proportional to displacement from ideal | |
| "rocket" acceleration -- max acceleration to mid point, followed by max de-celleration | |