Skip to content

Instantly share code, notes, and snippets.

View aggregate.cs
var customerAggregations = provider.AggregationSet<Customer>();
customerAggregations.Apply(x =>x.RecordShell.Age + 3,
"AgeInThreeYears");
View CompareAndUpdateScript.java
public static String script = "" +
"local key = KEYS[1]" +
"local field = ARGV[1]" +
"local value = ARGV[2]" +
"local op = ARGV[3]" +
"local current = redis.call('hget', key, field)" +
"if (current == null) then " +
" redis.call('hset', key, field, value)" +
"elseif op == '>' then" +
" if tonumber(value) > tonumber(current) then" +
@banker
banker / keybase.md
Created November 20, 2018 20:17
keybase.md
View keybase.md

Keybase proof

I hereby claim:

  • I am banker on github.
  • I am hwaet (https://keybase.io/hwaet) on keybase.
  • I have a public key ASAz4KeG_T7Aeq6EJ727hEqaMlBSGzGBzx1iwJEONZLoQwo

To claim this, I am signing this object:

@banker
banker / set_benchmark.rb
Created August 30, 2012 16:32
Which of these is the fastest?
View set_benchmark.rb
x = 10000.times.to_a
a,b,c = x.dup, x.dup, x.dup
Benchmark.measure { 1000.times { out = []; out += a; out += b; out +=c; out.uniq! } }
Benchmark.measure { 1000.times { out = Set.new; out += a; out += b; out +=c; } }
Benchmark.measure { 1000.times { out = {}; a.each {|e| out[e] ||= 1}; b.each {|e| out[e] ||= 1}; c.each {|e| out[e] ||= 1}; } }
View mr.js
> db.f.save({u: 1, v: 2})
> db.f.save({u: 2, v: 2})
> db.f.save({u: 1, v: 5})
> db.f.save({u: 2, v: 10})
> m = function() { emit(this.u, this.v) }
function () {
emit(this.u, this.v);
}
> r = function(k, vs) { r = 0; vs.forEach(function(v) { r += v; }); return r; }
function (k, vs) {
@banker
banker / mongoc
Created January 6, 2012 22:17 — forked from anonymous/mongoc
MongoDB connection via C driver
View mongoc
#include <stdio.h>
#include "mongo.h"
int main() {
mongo conn[1];
int status = mongo_connect( conn, "127.0.0.1", 27017 );
if( status != MONGO_OK ) {
switch ( conn->err ) {
case MONGO_CONN_SUCCESS: printf( "connection succeeded\n" ); break;
@banker
banker / mongodb-at-db-ruby.md
Created September 8, 2011 22:03
MongoDB for Rails at DC Ruby
View mongodb-at-db-ruby.md

MongoDB Pointers for Rubyists

Kyle Banker

DC Ruby | September, 2011

THE RAILS

1. Is MongoDB a good choice for your Rails project?

@banker
banker / map_reduce_fix.rb
Created September 1, 2011 19:22
map_reduce_fix.rb
View map_reduce_fix.rb
module Mongo
class Collection
def map_reduce(map, reduce, opts={})
map = BSON::Code.new(map) unless map.is_a?(BSON::Code)
reduce = BSON::Code.new(reduce) unless reduce.is_a?(BSON::Code)
raw = opts.delete(:raw)
hash = BSON::OrderedHash.new
hash['mapreduce'] = self.name
@banker
banker / oplog.c
Created August 22, 2011 19:54
oplog.c
View oplog.c
#include "mongo.h"
#include "bson.h"
int main() {
bson query[1], empty[1];
mongo conn[1];
int res;
mongo_cursor *cursor;
mongo_replset_init(conn, "test-rs");
@banker
banker / einval.rb
Created August 16, 2011 21:23 — forked from cgriego/einval.rb
MacBook Pro Early 2011, Lion, REE 2011.03, Mongo, forking #=> Errno::EINVAL
View einval.rb
#!/usr/bin/env ruby
require 'rubygems'
require 'bundler/setup'
require 'mongo'
@conn = Mongo::Connection.new
@db = @conn['supply_chain_development']
puts @db['properties'].find.to_a.size