Skip to content

Instantly share code, notes, and snippets.

CREATE TABLE stats (
column_name text,
column_value int,
test_id uuid,
score int,
height int,
PRIMARY KEY (column_name, column_value, test_id)
);
-- Now let's say we have a logical row with score=20, height=150
require 'bundler'
Bundler.require
require 'benchmark'
database = CassandraCQL::Database.new('127.0.0.1:9160')
begin
database.execute("CREATE KEYSPACE bm_test WITH strategy_class='SimpleStrategy' AND strategy_options:replication_factor=1")
database.execute("USE bm_test")
database.execute("CREATE COLUMNFAMILY bm_test (KEY uuid PRIMARY KEY) WITH comparator = uuid AND default_validation = text")
@outoftime
outoftime / pdb.rb
Last active December 14, 2015 09:58
Script to convert the output of perftools's `pprof --raw` output into a call tree in JSON or HTML. The code is messy and undocumented, and your mileage may vary, but it works for me. Also I know more about String#unpack than I did when I wrote this. Sorry, world.
#!/usr/bin/env ruby
require 'rubygems'
require 'readline'
require 'yajl'
require 'term/ansicolor'
Color = Object.new
Color.extend(Term::ANSIColor)
@outoftime
outoftime / sorted_set.js
Last active December 25, 2015 10:39
Make me a sorted set.
var SortedSet = function () {
// your code here...
}
var set = new SortedSet()
set.add(3).add(1).add(3).add(5).add(8).add(-4).add(6)
var answer = [-4, 1, 3, 5, 6, 8]
if (set.toArray() < answer || set.toArray() > answer) {
console.log("Got ", set.toArray())
process.exit(1)
connection = Cequel.connect(...)
table = connection.schema.read_table(:assessors)
my_data.each do |row|
typecast_row = {}
row.each_pair do |column_name, value|
typecast_row[column_name] = table.column(column_name).cast(value)
end
connection[:assessors].insert(typecast_row)
end
@outoftime
outoftime / CQL3 Allowed Type Transitions
Created February 1, 2014 19:38
List of type transitions that are allowed by a CQL3 ALTER TABLE statement
FROM TO ALLOWED?
===================================
ascii -> blob true
ascii -> boolean false
ascii -> decimal false
ascii -> double false
ascii -> inet false
ascii -> int false
ascii -> float false
ascii -> bigint false
class Object
def clip
string = to_s
IO.popen('pbcopy', 'w') { |io| io << string }
string
end
end
#
# Monkeypatching gem dependencies is a fact of life. But it's dangerous, because *any* update
# to a library might change internals that your patch depends on. This little snippet allows you
# to leave "reminders" in your code that you're relying on a particular version of a gem, and blows
# up if the gem loaded at runtime doesn't fit the requirement.
#
# Example:
#
# monkeypatch('awesome_lib', '1.2.2') do
# module AwesomeLib
@outoftime
outoftime / trie.rb
Created September 24, 2014 19:01
Ruby Trie
class Trie
include Enumerable
def initialize
@leaf, @children = false, {}
end
def <<(value)
add_enum(value_to_enum(value))
end