Skip to content

Instantly share code, notes, and snippets.

View thobbs's full-sized avatar
🎨

Tyler Hobbs thobbs

🎨
View GitHub Profile
@thobbs
thobbs / multiproc.py
Created March 7, 2014 19:44
Multiprocess Example
#!/usr/bin/env python
import logging
log = logging.getLogger()
log.setLevel('DEBUG')
handler = logging.StreamHandler()
handler.setFormatter(logging.Formatter("%(asctime)s [%(levelname)s] %(name)s: %(message)s"))
log.addHandler(handler)
#!/usr/bin/env python
import logging
log = logging.getLogger()
log.setLevel('INFO')
handler = logging.StreamHandler()
handler.setFormatter(logging.Formatter("%(asctime)s [%(levelname)s] %(name)s: %(message)s"))
log.addHandler(handler)
@thobbs
thobbs / cassandra_leaks.py
Created March 18, 2014 18:45
Memory Leak Repro
import resource
import gc
from guppy import hpy
def print_heap(hp):
h = hp.heap()
strs = []
strs.extend(str(h).split('\n')[1:-1])
for i in range(10):
@thobbs
thobbs / chaos.sh
Created July 22, 2014 21:11
chaos.sh
#! /bin/bash
while true; do
echo "stopping node1"
./ccm node1 stop
sleep 1
echo "starting node1"
./ccm node1 start
@thobbs
thobbs / gist:702116
Created November 16, 2010 17:22
pycassa-25.diff
index 7abca4f..c451f90 100644
--- a/pycassa/connection.py
+++ b/pycassa/connection.py
@@ -47,6 +47,7 @@ class ClientTransport(object):
"""Encapsulation of a client session."""
def __init__(self, keyspace, server, framed_transport, timeout, credentials, recycle):
+ self.server = server
host, port = server.split(":")
socket = TSocket.TSocket(host, int(port))
@thobbs
thobbs / example.py
Created December 15, 2011 00:32
Pycassa DateTimeString Replacement
class DatetimeStingType(pycassa.types.CassandraType):
def __init__(self):
self.pack = lambda dtime: dtime.strftime('%Y-%m-%d')
self.unpack = lambda dtime_str: datetime.strptime('%Y-%m-%d')
@thobbs
thobbs / gist:2356773
Created April 11, 2012 04:03
Pycassa Test
[default@unknown] connect localhost/9160;
Connected to: "Test Cluster" on localhost/9160
[default@unknown] create keyspace Foo;
b2461b50-838a-11e1-0000-242d50cf1ffe
Waiting for schema agreement...
... schemas agree across the cluster
[default@unknown] use Foo;
Authenticated to keyspace: Foo
[default@Foo] CREATE COLUMN FAMILY mycf
... WITH column_type = 'Standard'
@thobbs
thobbs / gist:2418598
Created April 19, 2012 04:38
Pycassa super column test
import time, logging
import pycassa
from pycassa.system_manager import SystemManager, SIMPLE_STRATEGY
pycassa.PycassaLogger().get_logger().addHandler(logging.StreamHandler())
sys = SystemManager()
if "Keyspace1" not in sys.list_keyspaces():
sys.create_keyspace("Keyspace1", SIMPLE_STRATEGY, {"replication_factor": "1"})
sys.create_column_family("Keyspace1", "CF1", super=True)
CREATE TABLE scores (
some_partition_key text,
score int,
test_id uuid,
field_a text,
field_b text,
PRIMARY KEY (some_partition_key, score, test_id)
);
@thobbs
thobbs / gist:4287021
Created December 14, 2012 17:10
Pagination of a row with phpcassa
<?php
$cf->return_format = ColumnFamily::ARRAY_FORMAT;
function get_page($cf, $key, $page, $page_size) {
$start_col = "";
$current_page = 0;
$page_data = null;
while ($current_page < $page) {
// fetch one extra column at the end