Skip to content

Instantly share code, notes, and snippets.

View devdazed's full-sized avatar

Russ Bradberry devdazed

View GitHub Profile
@devdazed
devdazed / redis_key.rb
Created January 13, 2011 17:41
manage surrogate keys usign Redis
require 'redis'
require 'digest/sha1'
class RedisKey
def initialize
@redis = Redis.new
end
def surrogate_key(dimension, data)
nk = Digest::SHA1.hexdigest(data)
@devdazed
devdazed / mongo_vs_redis.rb
Created January 14, 2011 02:07
Testing increment, speed in Mongo and Redis
require 'redis'
require 'mongo'
require 'benchmark'
class MongoVsRedis
ITERATIONS = 100_000
MONGO_CRITERIA = {"_id"=>BSON::ObjectId.from_string("4d2fa98a858d68644662156d")}
REDIS_CRITERIA = "benchmark_test"
def initialize
@devdazed
devdazed / expresso_suite_runner.js
Created January 26, 2011 18:40
wraps expresso to allow for multiple async tests to be run simultaneously
var util = require('util'),
spawn = require('child_process').spawn,
expresso = 'expresso',
async = require('async');
async.parallel({
"My Test" : function(cb){ runTest('./test/my_test.js', "My Test", cb) },
"My Other Test" : function(cb){ runTest('./test/my_other_tests', "My Other Test", cb) },
},function(errors, results){
util.print("Tests:\n");
@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]})
@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 / 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 / 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 / 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 / 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 / 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');