Skip to content

Instantly share code, notes, and snippets.

Avatar

Mathias Stearn RedBeard0531

View GitHub Profile
View gist:243047
function( key , values ){
var confidence_threshold = 0.0
var total = 0
var sc = 0.0
var cats = []
var links = []
for ( var i=0; i<values.length; i++ ) {
total += values[i].count
sc += (values[i].score || 0)
links.push({hash:values[i].hash,title:values[i].title,
View gist:303202
db.events.mapReduce(
function(){
emit({category:this.category, uid:this.uid}, null);
},
function(key, values){
return null;
},
{query: {type: "pageview"}}
).map_reduce(
function(){
View conn.c
#include "test.h"
#include "mongo.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(){
mongo_connection conn[1];
mongo_connection_options opts;
View gist:333367
$ MONGO_INCLUDE_PATH=/usr/include/mongo/ scons .
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
g++ -o gridfs_c_helpers.o -c -I/usr/include/mongo -INone gridfs_c_helpers.cpp
scons: done building targets.
View gist:340574
> db.test.find({loc:{$near:[0,0]}})
{ "_id" : ObjectId("4ba7e616b8c125a527c38708"), "name" : "a", "loc" : [ 0, 0 ] }
{ "_id" : ObjectId("4ba7e61ab8c125a527c38709"), "name" : "b", "loc" : [ 0, 0 ] }
{ "_id" : ObjectId("4ba7e620b8c125a527c3870a"), "name" : "c", "loc" : [ 1, 1 ] }
View gist:703610
/* test.c */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#ifndef _WIN32
#include <sys/time.h>
#endif
static char hexbyte1(char hex){
View gist:720237
> db.foo.ensureIndex({a:1})
> db.foo.ensureIndex({b:1})
> db.foo.insert({a:1})
> db.foo.insert({b:1})
> db.foo.insert({a:1, b:1})
> db.foo.find({$or:[{a:1}, {b:1}]}).explain()
{
"clauses" : [
{
"cursor" : "BtreeCursor a_1",
View gist:873508
#!/usr/bin/python
from pymongo import Connection
import subprocess
import sys
def advance(cur)
try:
return cur.next()
except StopIteration:
@RedBeard0531
RedBeard0531 / functions.js
Created Feb 22, 2012
Min, Max, Sum, Count, Avg, and Std deviation using MongoDB MapReduce
View functions.js
// derived from http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Parallel_algorithm
function map() {
emit(1, // Or put a GROUP BY key here
{sum: this.value, // the field you want stats for
min: this.value,
max: this.value,
count:1,
diff: 0, // M2,n: sum((val-mean)^2)
});
@RedBeard0531
RedBeard0531 / gist:2845543
Created May 31, 2012
using convert with netpbm format
View gist:2845543
$ convert - /tmp/o.png << EOF
P1
# This is an example bitmap of the letter "J"
6 10
0 0 0 0 1 0
0 0 0 0 1 0
0 0 0 0 1 0
0 0 0 0 1 0
0 0 0 0 1 0
0 0 0 0 1 0