Skip to content

Instantly share code, notes, and snippets.

View jdmaturen's full-sized avatar

jd jdmaturen

View GitHub Profile
@jdmaturen
jdmaturen / ExponentiallyDecayingSample.py
Created April 6, 2011 01:45
expontentially decaying sample algorithm w/ redis
import logging
from math import exp
from random import random
from time import sleep
from time import time
from uuid import uuid1
from redis.exceptions import WatchError
"""http://en.wikipedia.org/wiki/Reservoir_sampling
"""
import random
import struct
class RedisReservoirSample(object):
def __init__(self, redis, n, fmt='>i'):
"""
n is the sample size
import logging
import gevent
from gevent.queue import Queue
from thrift.server.TServer import TServer
from thrift.transport.TTransport import TTransportException
@jdmaturen
jdmaturen / worker3.py
Created January 25, 2011 03:42
Redis stats aggregator w/ Gevent
import gevent
from gevent import monkey
monkey.patch_socket()
import hashlib
import os
import redis
from gevent import monkey; monkey.patch_socket()
import gevent
import httplib2
from gevent import http
from time import time
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)
@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)
<?php
namespace app;
include '../config/bootstrap.php';
use \Exception;
use \Http404;
--- a/Library/Formula/membase.rb
+++ b/Library/Formula/membase.rb
@@ -1,9 +1,9 @@
require 'formula'
class Membase < Formula
- url 'http://membase.org/downloads/membase_1.6.0beta2-18-g638fc06_src.tar.gz'
+ url 'http://membase.org/downloads/membase_1.6.0beta3_src.tar.gz'
homepage 'http://membase.org'
- md5 'b0b2a5d909cf3d2e20db07c4d12259a0'
@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() {