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
for i in range(0, len(sample_data) - 2): | |
x0, y0 = mat.transform_point(*sample_data[i]) | |
x1, y1 = mat.transform_point(*sample_data[i+1]) | |
x2, y2 = mat.transform_point(*sample_data[i+2]) | |
#cr.arc(x0, y0, 6, 0, 2 * math.pi) | |
#cr.fill() | |
qx1 = (x1 - x0) * fit + x0 | |
qy1 = (y1 - y0) * fit + y0 |
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
def make_hdr(self, replyto=None, srcnode=None): | |
hdr = rucksack.interface.MsgHdr() | |
hdr.msgid = str(rucksack.util.rand64()) | |
if replyto is not None: | |
hdr.replyto = replyto | |
if srcnode is not None: | |
hdr.srcnode = self.node | |
return hdr | |
def notify_membership(self, fd, events, ev): |
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
/* Simplified implementation of ranger stat server using node.js. */ | |
var sys = require('sys'), | |
http = require('http'); | |
var buffer = ''; | |
var ring = new Array(); | |
var window = 300; // how wide is the window? | |
var percentile = 0.95; | |
var server; | |
// stdin worker |
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
/* Super simple logging module */ | |
var posix = require('posix'); | |
/* Create a function for logging. This is asynchronous, and will queue up | |
* pending log messages if log messages are submitted faster than they can be | |
* written to disk. */ | |
var log = function () { | |
/* initialize logging (blocks) */ | |
var log_fd = posix.open('ss.log', process.O_WRONLY | process.O_APPEND | process.O_CREAT, process.S_IRUSR | process.S_IWUSR).wait(); |
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
def socket_or_default(f, default): | |
try: | |
return f() | |
except socket.error: | |
return default | |
pa, pp = socket_or_default(lambda: r.getpeername(), ('0.0.0.0', 0)) |
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
#!/usr/bin/env python | |
import sys | |
import urllib | |
import pprint | |
import optparse | |
import simplejson | |
CLOSURE_PARAMS = { | |
'compilation_level': 'SIMPLE_OPTIMIZATIONS', | |
'output_format': 'json', |
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
#!/usr/bin/env python | |
# | |
# Simulates a leveraged ETF, with a stop-loss ability. The default model assumes | |
# that you guess right 1/3 times, and when you guess right the ETF increases in | |
# value by 4% and when you guess wrong the ETF decreases in value by 2%. | |
import optparse | |
import random | |
def main(opts): |
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
"""MySQL benchmark tool, for comparing different table schemas. | |
Some notes: | |
* run like: python mysqlbench.py my_config_file.yaml | |
* there's a few different options to change things up, invoke with -h to see | |
them | |
* you should run this with with a total of at least a quarter million rows or | |
so (default is one million) to ensure that you see the slowdown from MySQL | |
checking uniqueness contraints; i.e., make sure you see a slow down as | |
iterations increase for the schemas that create tables with a unique uuid |
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
def flush(self): | |
wout = self.__wbuf.getvalue() | |
wsz = len(wout) | |
# reset wbuf before write/flush to preserve state on underlying failure | |
self.__wbuf = StringIO() | |
# N.B.: Doing this string concatenation is WAY cheaper than making | |
# two separate calls to the underlying socket object. Socket writes in | |
# Python turn out to be REALLY expensive, but it seems to do a pretty | |
# good job of managing string buffer operations without excessive copies | |
buf = pack("!i", wsz) + wout |
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
ctrl-z | |
bg | |
touch /tmp/stdout | |
touch /tmp/stderr | |
gdb -p $! | |
# In GDB | |
p dup2(open("/tmp/stdout", 1), 1) | |
p dup2(open("/tmp/stderr", 1), 2) |