Skip to content

Instantly share code, notes, and snippets.

View RedBeard0531's full-sized avatar

Mathias Stearn RedBeard0531

View GitHub Profile
> 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",
#!/usr/bin/python
from pymongo import Connection
import subprocess
import sys
def advance(cur)
try:
return cur.next()
except StopIteration:
@RedBeard0531
RedBeard0531 / gist:2845543
Created May 31, 2012 19:10
using convert with netpbm format
$ 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
@RedBeard0531
RedBeard0531 / ptr.hpp
Last active December 18, 2015 05:58
A dumb non-owning pointer type that implicitly converts from any smart or dumb pointer.
/** A generic non-owning pointer type for function arguments.
* It will convert from any pointer type except auto_ptr.
* Semantics are the same as passing the pointer returned from get()
* const ptr<T> => T * const
* ptr<const T> => T const * or const T*
*/
template <typename T>
struct ptr {
ptr() : _p(NULL) {}
// Example Query
db.runCommand({aggregate:'zips',
explain:true,
pipeline: [
{$group: {_id:'$state', totalPop: {$sum:'$pop'}}},
{$sort: {totalPop:1}},
{$limit:10}]})
// Unsharded:
{
@RedBeard0531
RedBeard0531 / compile_test.cpp
Created May 5, 2016 00:07
Compile fail test
#include <type_traits>
/**
* Test that 'Code' fails to compile.
* 'Type' is aliased to 'Alias' and it must be used in 'Code'
*/
#define COMPILE_FAIL_TEST(Name, Type, Alias, Code) \
struct Name { \
template <typename Alias> \
static auto compiles(Alias && ) -> decltype((void)(Code), std::true_type()); \
@RedBeard0531
RedBeard0531 / evergreen_waterfall_console.user.js
Last active January 18, 2017 21:13
Crappy js to paste into console
// ==UserScript==
// @name Compact Waterfall Summary
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Make it Smaller
// @author Mathias Stearn
// @match https://evergreen.mongodb.com/waterfall/*
// @grant none
// ==/UserScript==
// vim: sts=2 sw=2:
// ==UserScript==
// @name Show Failures by Test
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://evergreen.mongodb.com/version/*
// @grant none
// ==/UserScript==
import tables
import critbits
import os
import sequtils
import times
import random
import xxhash
#import murmur
import murmur3
import hashes