Skip to content

Instantly share code, notes, and snippets.

View devdazed's full-sized avatar

Russ Bradberry devdazed

View GitHub Profile
for ks in SYSTEM_MANAGER.list_keyspaces():
describe_keyspace(ks)
for cf in SYSTEM_MANAGER.get_keyspace_column_families(ks):
describe_column_family(ks, cf)
import json
from pycassa.pool import ConnectionPool
from pycassa.columnfamily import ColumnFamily
from pycassa.cassandra.ttypes import ConsistencyLevel, NotFoundException
HOSTS = ['localhost']
pool = ConnectionPool('my_keyspace', HOSTS)
my_cf = ColumnFamily(pool, 'my_cf')
@devdazed
devdazed / lp_counters.py
Created October 11, 2012 16:14
Simple Linear Probabilistic Counters
"""
Simple Linear Probabilistic Counters
Credit for idea goes to:
http://highscalability.com/blog/2012/4/5/big-data-counting-how-to-count-a-billion-distinct-objects-us.html
http://highlyscalable.wordpress.com/2012/05/01/probabilistic-structures-web-analytics-data-mining/
Installation:
pip install smhasher
pip install bitarray
@devdazed
devdazed / proxy_bench.js
Created September 19, 2012 20:33
Harmony Proxy Benchmark
var noop = function(){};
var obj = {
'1':function(){ console.log(1) },
'10':function(){ console.log(10) },
'100':function(){ console.log(100) },
'1000':function(){ console.log(1000) },
'10000':function(){ console.log(10000) }
};
console.time('checking');
@devdazed
devdazed / aws_csshx.rb
Created May 1, 2012 14:29
csshX wrapper to log into all running servers in an AWS security group
#!/usr/bin/env ruby
require 'right_aws'
EC2_PRIVATE_KEY = ENV['EC2_PRIVATE_KEY']
AWS_ACCESS_KEY = ENV['AWS_ACCESS_KEY']
AWS_SECRET_KEY = ENV['AWS_SECRET_KEY']
def group
@group ||= ARGV[0]
end
@devdazed
devdazed / gist:2481257
Created April 24, 2012 16:34 — forked from elubow/gist:2008708
Nagios Passive Check
#foobar
# Send the passive service check back to Nagios
logger.debug("Constructing the Nagios result string")
nag_message = config.get('nagios','message')
nag_status = 0
logger.info("Passive check result sent to Nagios")
except Exception, e:
nag_status = 2
nag_message = "%s" % (e)
@devdazed
devdazed / jgrep.js
Created November 23, 2011 16:48
JSON Field Grep in Node.JS
#!/usr/bin/env node
var stdin = process.stdin,
fields = process.argv.slice(2),
buf = [];
if (fields.length === 0){
console.error('Usage: jgrep "some.fields in.json" < STDIN');
process.exit(1);
}
@devdazed
devdazed / loop_bench.js
Created November 4, 2011 14:46
Interesting differences in loops and incrementers
var i = 0, n = 100000000, t = 0;
console.time('i++');
for (; i < n; i++){
t += 1;
}
console.timeEnd('i++');
//i++: 147ms
i = 0; t = 0;
@devdazed
devdazed / bson_string_symbol.rb
Created July 22, 2011 18:32
Show the difference between storing strings as BSON and symbols.
require 'mongo'
foo = ['this', 'that']
bar = [:this, :that]
a = {:foo => ['this', 'that']}
b = {:foo => [:this, :that]}
bson_a = BSON.serialize(a).to_s
#=> "'\x00\x00\x00\x04foo\x00\x1D\x00\x00\x00\x020\x00\x05\x00\x00\x00this\x00\x021\x00\x05\x00\x00\x00that\x00\x00\x00"
bson_b = BSON.serialize(b).to_s
#=> "'\x00\x00\x00\x04foo\x00\x1D\x00\x00\x00\x0E0\x00\x05\x00\x00\x00this\x00\x0E1\x00\x05\x00\x00\x00that\x00\x00\x00"
@devdazed
devdazed / insert_bson_symbols.rb
Created July 21, 2011 18:39
BSON Symbols and Node.JS
require 'mongo'
@db = Mongo::Connection.new['test']
@symbol_coll = @db['bson_symbols']
@string_coll = @db['bson_string']
[@symbol_coll, @string_coll].each{|c| c.remove }
3.times do |i|
@symbol_coll.insert({'foo' => [:a, :b, :c, :d]})