Skip to content

Instantly share code, notes, and snippets.

View beccam's full-sized avatar

Rebecca Mills beccam

View GitHub Profile
@beccam
beccam / 0_reuse_code.js
Created July 3, 2014 14:48
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@beccam
beccam / GettingStarted.rb
Created July 3, 2014 16:39
Getting Started with Apache Cassandra and Ruby
require 'cql'
# connect to the cluster
client = Cql::Client.connect(hosts: ['127.0.0.1'])
client.use('demo')
# insert a user
client.execute("INSERT INTO users (lastname, age, city, email, firstname) VALUES ('Jones', 35, 'Austin', 'bob@example.com', 'Bob')")
# Use select to get the user we just entered
@beccam
beccam / GettingStartedDatastaxRubyDriver.rb
Last active August 29, 2015 14:06
GettingStartedDatastaxRubyDriver
require 'cassandra'
cluster = Cassandra.connect
#cluster.each_host do |host|
# puts "Host #{"127.0.0.1"}: id=#{"6123e2c1-e3ca-4d08-a544-1315b2f399f1"} datacenter=#{"datacenter1"} rack=#{"rack1"}"
#end
keyspace = 'demo'
session = cluster.connect(keyspace)
@beccam
beccam / GettingStarted.rb
Created September 5, 2014 13:17
Getting Started with the Datastax Ruby Driver
require 'cassandra'
cluster = Cassandra.connect
keyspace = 'demo'
session = cluster.connect(keyspace)
session.execute("INSERT INTO users (lastname, age, city, email, firstname) VALUES ('Jones', 35, 'Austin', 'bob@example.com', 'Bob')")
session.execute("SELECT firstname, age FROM users WHERE lastname='Jones'").each do |row|
@beccam
beccam / getting_started.rb
Created September 20, 2014 01:00
Getting Started with Apache Cassandra and the DS Ruby Driver
require 'cassandra'
cluster = Cassandra.connect
#cluster.each_host do |host|
# puts "Host #{"127.0.0.1"}: id=#{"6123e2c1-e3ca-4d08-a544-1315b2f399f1"} datacenter=#{"datacenter1"} rack=#{"rack1"}"
#end
keyspace = 'demo'
session = cluster.connect(keyspace)
@beccam
beccam / GettingStarted.php
Created May 26, 2015 16:20
Getting Started with Apache Cassandra and PHP
<?php
$cluster = Cassandra::cluster()
->build();
$keyspace = 'killrvideo';
$session = $cluster->connect($keyspace);
$statement = $session->execute(new Cassandra\SimpleStatement(
"INSERT INTO users (userid, created_date, email, firstname, lastname) VALUES (14c532ac-f5ae-479a-9d0a-36604732e01d, '2013-01-01 00:00:00', 'luke@example.com','Luke','Tillman')"
));
$result = $session->execute(new Cassandra\SimpleStatement("SELECT firstname, lastname, email FROM killrvideo.users WHERE userid=14c532ac-f5ae-479a-9d0a-36604732e01d"));
@beccam
beccam / GettingStartedTwo.php
Last active August 29, 2015 14:22
GettingStartedTwo
<?php
$cluster = Cassandra::cluster()
->withPersistentSessions(true)
->withTokenAwareRouting(true)
->build();
$keyspace = 'killrvideo';
$session = $cluster->connect($keyspace);
@beccam
beccam / GettingStartedThree.py
Last active February 4, 2016 18:34
Getting Started with Apache Cassandra Part III (cqlengine)
from cqlengine import columns
from cqlengine.models import Model
class Users(Model):
firstname = columns.Text()
age = columns.Integer()
city = columns.Text()
email = columns.Text()
lastname = columns.Text(primary_key=True)
def __repr__(self):
from cassandra.cluster import Cluster
from cassandra.policies import (TokenAwarePolicy, DCAwareRoundRobinPolicy, RetryPolicy)
from cassandra.query import (PreparedStatement, BoundStatement)
cluster = Cluster(
contact_points=['127.0.0.1'],
load_balancing_policy= TokenAwarePolicy(DCAwareRoundRobinPolicy(local_dc='datacenter1')),
default_retry_policy = RetryPolicy()
)
session = cluster.connect('demo')
@beccam
beccam / GettingStartedTwo.java
Last active July 21, 2017 21:02
Getting Started with Apache Cassandra and Java Part II
import com.datastax.driver.core.*;
public class GettingStartedTwo {
public static void main(String[] args) {
Cluster cluster;
Session session;
ResultSet results;
Row rows;