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 | |
# http://en.wikipedia.org/wiki/Join_(SQL) | |
def crossJoin(table_a, table_b): | |
""" | |
Cross join returns the Cartesian product of rows from tables in the join. | |
In other words, it will produce rows which combine each row from the first | |
table with each row from the second table. | |
""" | |
results = JoinTable(table_a, table_b) |
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 | |
def _procMemoryGrep(filename, vmkeys): | |
size_scale = {'kb': 1024.0, 'mb':1048576.0, 'gb':1073741824.0} | |
values = {} | |
fd = open(filename) | |
try: | |
for line in fd: | |
for vmkey in vmkeys: |
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 | |
def bsearch(data, key, cmpfunc): | |
end = len(data) | |
start = 0 | |
while start < end: | |
m = (start + end) / 2 | |
c = cmpfunc(data[m], key) |
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
#define spinlock_t union ticket_lock | |
#define spin_init ticket_init | |
#define spin_destroy ticket_destroy | |
#define spin_lock ticket_acquire | |
#define spin_unlock ticket_release | |
union ticket_lock { | |
volatile unsigned int data; | |
struct { | |
volatile unsigned short next_ticket; |
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 | |
def encodeZigZag32(n): return (n << 1) ^ (n >> 31) | |
def encodeZigZag64(n): return (n << 1) ^ (n >> 63) | |
def decodeZigZag32(n): return (n >> 1) ^ -(n & 1) | |
def decodeZigZag64(n): return (n >> 1) ^ -(n & 1) | |
def encodeVInt(n): | |
data = '' | |
while n >= 0x80: |
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
from SocketServer import TCPServer, StreamRequestHandler | |
class LineService(StreamRequestHandler): | |
""" | |
Simple StreamRequestHandler that allows you to handle line requests | |
Example: | |
telnet localhost 8080 | |
> mycommand | |
> quit | |
""" |
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
from SocketServer import TCPServer, StreamRequestHandler | |
class JSonService(StreamRequestHandler): | |
""" | |
Simple StreamRequestHandler that allows you to handle json requests | |
Example: | |
telnet localhost 8080 | |
> {"action": [1, 2, 3]} | |
> ["do this", "do that"] | |
""" |
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 _hashKey(key): | |
return long(md5(key).hexdigest(), 16) | |
def _nodeKey(node, replica): | |
return _hashKey('%s:%d' % (str(node), replica)) | |
class ConsistentRing(object): | |
""" | |
Consistent Hashing: |
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
/* | |
* - stream interface | |
* [filter stream] | |
* - buffered stream | |
* - encoded stram | |
* - buffer stream | |
* - chunkq stream | |
* | |
* Copyright 2011-2012 Matteo Bertozzi | |
* |
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
from cStringIO import StringIO | |
SYMBOLS_QUOTE = ('"', "'") | |
TOKEN_STRING = 0 | |
TOKEN_NUMBER = 1 | |
TOKEN_KEYWORD = 2 | |
TOKEN_PARENTHESES_OPEN = 3 | |
TOKEN_PARENTHESES_CLOSE = 4 | |
TOKEN_COMMA = 5 |
OlderNewer