Skip to content

Instantly share code, notes, and snippets.

Avatar

Mathias Stearn RedBeard0531

View GitHub Profile
@RedBeard0531
RedBeard0531 / gist:d3526dfdd5edfbca25c3
Last active Aug 29, 2015
Write Unit of Work Example Code
View gist:d3526dfdd5edfbca25c3
// pseudo-c++
//
// High Level Examples
//
void insert(BSONObj obj, bool shouldLogOp) {
do {
WriteUnitOfWork wunit;
if (!collection)
View gist:f929d9da37c805ba2563
#include <boost/static_assert.hpp>
#include <type_traits>
#include <vector>
int main() {
////////////////// PROXY OBJECTS /////////////////
{
auto bools = std::vector<bool>{true, false};
@RedBeard0531
RedBeard0531 / cursors.cpp
Created Feb 20, 2015
Cursor API Proposal
View cursors.cpp
#include <utility>
template <typename T> using some_iterator_type = T*;
template <typename T> struct ptr {}; // from mongo ptr.h
// Defining concepts using struct syntax. These are like interfaces, but not in
// the virtual-dispatch sense. Actual Cursor implementations must have an API
// that is usable as-if it had these signatures, even if the types don't match.
#define concept struct
View gist:8ce71a176e1ff071b42a
class OpDebug : public Decorable<OpDebug> {
public:
//
// Removed existing members for brevity.
//
class Extension {
virtual void appendToString(StringBuilder*) = 0;
virtual void appendToBson(BSONObjBuilder*) = 0;
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){