Skip to content

Instantly share code, notes, and snippets.

View thobbs's full-sized avatar
🎨

Tyler Hobbs thobbs

🎨
View GitHub Profile
@thobbs
thobbs / .gdbinit
Created October 29, 2013 19:51
A version of .gdbinit that provides a pystack and pystackv command that does not hang forever. The problem appeared to be an infinite loop, so to fix it I just added a basic counter that breaks the while loop after 200 iterations.
# -*- ksh -*-
#
# If you use the GNU debugger gdb to debug the Python C runtime, you
# might find some of the following commands useful. Copy this to your
# ~/.gdbinit file and it'll get loaded into gdb automatically when you
# start it up. Then, at the gdb prompt you can do things like:
#
# (gdb) pyo apyobjectptr
# <module 'foobar' (built-in)>
# refcounts: 1
cqlsh:keyspace1> UPDATE mentions SET mentions = 3 WHERE day = '01/05/11' AND item = 'acunu' AND time = 1;
cqlsh:keyspace1> select * from mentions;
day | item | time | mentions
----------+-------+------+----------
01/05/11 | acunu | 1 | 3
cqlsh:keyspace1> UPDATE mentions SET mentions = 5 WHERE day = '01/05/11' AND item = 'acunu' AND time = 2;
cqlsh:keyspace1> select * from mentions;
cqlsh> CREATE KEYSPACE keyspace1 WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1' };
cqlsh> use keyspace1;
cqlsh:keyspace1> CREATE TABLE cf3 ( key blob PRIMARY KEY, id varint, postcode text, price varint ) WITH COMPACT STORAGE;
cqlsh:keyspace1> CREATE INDEX cf3_id_idx ON cf3 (id) ;
cqlsh:keyspace1> CREATE INDEX cf3_price_idx ON cf3 (price) ;
cqlsh:keyspace1> DESCRIBE COLUMNFAMILY keyspace1.cf3;
CREATE TABLE cf3 (
key blob PRIMARY KEY,
id varint,
<?php
require_once(__DIR__.'/lib/autoload.php');
use phpcassa\Connection\ConnectionPool;
use phpcassa\ColumnFamily;
use phpcassa\Index\IndexExpression;
use phpcassa\Index\IndexClause;
~/pycassa (master)$ ./pycassaShell -k Keyspace1
----------------------------------
Cassandra Interactive Python Shell
----------------------------------
Keyspace: Keyspace1
Host: localhost:9160
Available ColumnFamily instances:
* CF1 ( CF1 )
@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
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: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)
@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 / 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')