Skip to content

Instantly share code, notes, and snippets.

View jdmaturen's full-sized avatar

jd jdmaturen

View GitHub Profile
@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
import logging
import gevent
from gevent.queue import Queue
from thrift.server.TServer import TServer
from thrift.transport.TTransport import TTransportException
"""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
@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
@jdmaturen
jdmaturen / bucket_client.py
Created April 16, 2011 08:31
riak bucket that manages retries + conflict resolution w/ example increment counter implementation
from riak import RiakError
class Bucket(object):
"""Wrap up retries and conflict resolution"""
def __init__(self, client, name, resolve, retries=5):
self.client = client
self.name = name
self.bucket = client.bucket(name) # base bucket
self.resolve = resolve
self.retries = retries
@jdmaturen
jdmaturen / gist:939068
Created April 23, 2011 23:05
Riak resource allocation (rough expansion)
# of keys: 10,000,000
size of key: 60bytes (40bytes bitcask + 20bytes for name)
bounded size of each value: 1k
# of active items (usually per day): 1,000,000 (of course how you determine this number is up for grabs, I suggest measuring)
RF: 3
130% * (1k * 1mm * 3) / 1024**3 ~= 4GB for filesystem cache
130% * (10mm * 60b * 3) / 1024**3 ~= 2GB+ for key space
@jdmaturen
jdmaturen / pbc_pool_transport.py
Created June 20, 2011 23:39
Riak python client PBC connection pooling
import logging
log = logging.getLogger('socrates')
from Queue import Empty, Full, Queue
from riak.transports import RiakPbcTransport
from riak.transports.transport import RiakTransport
class PbcPoolTransport(RiakTransport):
<?php
// … 
/**
* Default, shared method for authenticating a connection to AWS.
*
* @param string $operation (Required) Indicates the operation to perform.
* @param array $payload (Required) An associative array of parameters for authenticating. See the individual methods for allowed keys.
* @return CFResponse Object containing a parsed HTTP response.
*/
public function authenticate($operation, $payload)
The token system is ridiculous because it makes security weaker, by offering a
larger surface area for attack.
If I had to guess, Salesforce is concerned that users are embedding their
passwords into scripts which could be stolen and used outside the company for
other purposes. Why are users putting their passwords in scripts? I imagine
it's because of the web-centric oauth flow coupled with short oauth token
expiration intervals but THATS a different story.
So *within* an authorized set of IP addresses, the regular password works.
@jdmaturen
jdmaturen / gist:3627593
Created September 4, 2012 22:44 — forked from argv0/gist:3627514
Markov Chain Thing I Wrote A Long Time Ago
just write something funny, dufus.