Skip to content

Instantly share code, notes, and snippets.

View RedBeard0531's full-sized avatar

Mathias Stearn RedBeard0531

View GitHub Profile
// ==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==
@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:
@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()); \
class OpDebug : public Decorable<OpDebug> {
public:
//
// Removed existing members for brevity.
//
class Extension {
virtual void appendToString(StringBuilder*) = 0;
virtual void appendToBson(BSONObjBuilder*) = 0;
@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
#include <boost/static_assert.hpp>
#include <type_traits>
#include <vector>
int main() {
////////////////// PROXY OBJECTS /////////////////
{
auto bools = std::vector<bool>{true, false};
@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)
// Example Query
db.runCommand({aggregate:'zips',
explain:true,
pipeline: [
{$group: {_id:'$state', totalPop: {$sum:'$pop'}}},
{$sort: {totalPop:1}},
{$limit:10}]})
// Unsharded:
{
@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) {}
@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