Skip to content

Instantly share code, notes, and snippets.

View jdmaturen's full-sized avatar

jd jdmaturen

View GitHub Profile
@jdmaturen
jdmaturen / example_output
Last active August 29, 2015 14:16
From an individual box's viewpoint probabilistically limit the global concurrency of requests of a given actor based on observed local concurrency, the cluster size, and a set threshold.
burp-2:foo jd$ python probabilistic_strategy.py 1000 16 64
request_count: 1000 cluster_size: 16 threshold: 64
probability of being quotad at a given local concurrency:
1 0.015070684079
2 0.07629533815
3 0.202571187171
4 0.378831226431
mean observed global concurrency limit: 64.033

Heads or Tails Extended

In fact, only 2 out of 2,862 broad domestic stock funds were able to outperform their peers consistently over five years, according to one measure: performance in the top quartile of funds over five consecutive 12-month periods ended in March 2014. That translates to just 0.07 percent of the funds, which means that more than 99.9 percent of funds fell short of that feat.

Repeat those double flips five times and you’ll find the probability of a mutual fund ending up in the top quartile five times in a row through chance: 0.098 percent. (We’re flipping the coin twice for each year of mutual fund performance.) That’s a bigger probability than the 0.07 percent scored by the actual funds. This means that if mutual fund managers had just flipped coins, roughly three of them — not two — would have been expected to end up in the top quartile for five years in a row.

Indeed:

>>> 100 * .25 ** 5
@jdmaturen
jdmaturen / Gorillaz - Plastic Beach (2010).sh
Created March 1, 2010 17:06
Gorillaz - Plastic Beach (2010)
#!/bin/bash
wget http://del.interoute.com/?id=aa1fa024-ae1d-4285-923e-3ccfc6385200&delivery=download
wget http://del.interoute.com/?id=0be7e9f6-e572-411c-81cf-5b59de45336d&delivery=download
wget http://del.interoute.com/?id=3b30d50f-850b-495a-acfb-8d6d7d6a3e57&delivery=download
wget http://del.interoute.com/?id=23cc3dcc-4b11-4809-8d95-8cc07f1b5cae&delivery=download
wget http://del.interoute.com/?id=bd58c55a-136f-46c2-abf6-51c05ecaa780&delivery=download
wget http://del.interoute.com/?id=0d5ba0c2-bdd2-4a72-b654-55053e125527&delivery=download
wget http://del.interoute.com/?id=ad9e99c7-e5ad-49bc-8e12-0230db2807be&delivery=download
wget http://del.interoute.com/?id=08227202-0d13-4020-b99e-8b9c6741b656&delivery=download
wget http://del.interoute.com/?id=ca16419d-5f81-4d12-a998-f87a08e72971&delivery=download
# In-memory Cassandra-ish thingy... useful for unit tests. Maybe useful for other
# stuff too? No support for SuperColumns, but that should be easy enough to add.
import bisect
import copy
from cassandra.ttypes import NotFoundException, Column, ColumnPath, ColumnOrSuperColumn
class SSTable(object):
import multiprocessing
import sys
from multiprocessing import JoinableQueue
from multiprocessing import Pipe
from multiprocessing import Queue
from multiprocessing import Process
from pylibmc import Client
from time import sleep
@jdmaturen
jdmaturen / gist:530803
Created August 17, 2010 16:52
Cassandra 0.7 thrift example. CC license.
<?php
$GLOBALS['THRIFT_ROOT'] = '/path/to/thrift/';
require_once $GLOBALS['THRIFT_ROOT'].'/packages/cassandra/Cassandra.php';
require_once $GLOBALS['THRIFT_ROOT'].'/packages/cassandra/cassandra_types.php';
require_once $GLOBALS['THRIFT_ROOT'].'/transport/TSocket.php';
require_once $GLOBALS['THRIFT_ROOT'].'/protocol/TBinaryProtocol.php';
require_once $GLOBALS['THRIFT_ROOT'].'/transport/TFramedTransport.php';
require_once $GLOBALS['THRIFT_ROOT'].'/transport/TBufferedTransport.php';
function microsecond_timestamp() {
<?php
namespace app;
include '../config/bootstrap.php';
use \Exception;
use \Http404;
@jdmaturen
jdmaturen / sleep.php
Created January 14, 2011 08:07
ms timeout in tornado
diff --git a/tornado/httpclient.py b/tornado/httpclient.py
index 25d07ae..89e1fd4 100644
--- a/tornado/httpclient.py
+++ b/tornado/httpclient.py
@@ -536,7 +536,8 @@ def _curl_setup_request(curl, request, buffer, headers):
curl.setopt(pycurl.FOLLOWLOCATION, request.follow_redirects)
curl.setopt(pycurl.MAXREDIRS, request.max_redirects)
curl.setopt(pycurl.CONNECTTIMEOUT, int(request.connect_timeout))
- curl.setopt(pycurl.TIMEOUT, int(request.request_timeout))
+ curl.setopt(pycurl.NOSIGNAL, 1)
from gevent import monkey; monkey.patch_socket()
import gevent
import httplib2
from gevent import queue
from time import time
def worker(q):
h = httplib2.Http(timeout=0.1)
from gevent import monkey; monkey.patch_socket()
import gevent
import httplib2
from gevent import http
from time import time