Skip to content

Instantly share code, notes, and snippets.

View RedBeard0531's full-sized avatar

Mathias Stearn RedBeard0531

View GitHub Profile
@RedBeard0531
RedBeard0531 / gist:d3526dfdd5edfbca25c3
Last active August 29, 2015 14:03
Write Unit of Work Example Code
// pseudo-c++
//
// High Level Examples
//
void insert(BSONObj obj, bool shouldLogOp) {
do {
WriteUnitOfWork wunit;
if (!collection)
#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 February 20, 2015 23:08
Cursor API Proposal
#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
class OpDebug : public Decorable<OpDebug> {
public:
//
// Removed existing members for brevity.
//
class Extension {
virtual void appendToString(StringBuilder*) = 0;
virtual void appendToBson(BSONObjBuilder*) = 0;
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,
db.events.mapReduce(
function(){
emit({category:this.category, uid:this.uid}, null);
},
function(key, values){
return null;
},
{query: {type: "pageview"}}
).map_reduce(
function(){
#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;
$ 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.
> 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 ] }
/* test.c */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#ifndef _WIN32
#include <sys/time.h>
#endif
static char hexbyte1(char hex){