Skip to content

Instantly share code, notes, and snippets.

@TylerBrock
TylerBrock / aggregation.cpp
Created September 22, 2014 20:26
Aggregation Framework Example
/* Copyright 2014 10gen Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@TylerBrock
TylerBrock / crud.cpp
Last active August 29, 2015 14:06
CRUD Example - C++11
/////////////////////////////////////////////////////////////////////
/// find
/////////////////////////////////////////////////////////////////////
// Coersion from document::view into model::find
auto cursor = coll.find(doc_view);
// Explicit creation of model::find
auto cursor = coll.find(model::find(doc_view).limit(10));
@TylerBrock
TylerBrock / read_only_shard.js
Created September 24, 2014 00:22
Spin up read only shard
var st = new ShardingTest({
shards:1,
mongos:1,
other: {
rs: true,
numReplicas: 2,
separateConfig: true
}
})
### Keybase proof
I hereby claim:
* I am TylerBrock on github.
* I am tyler (https://keybase.io/tyler) on keybase.
* I have a public key whose fingerprint is D683 1F3B 3C62 7B38 E5FD 62D2 F10D 2721 439F 26D5
To claim this, I am signing this object:
@TylerBrock
TylerBrock / crowd.rb
Created November 6, 2014 16:05
Simple Crowd Integration in Ruby
require 'httparty'
require 'logger'
require 'json'
BASE_PATH = '/crowd/rest/usermanagement/'
API_VERSION = 1
AUTH_PATH = '/authentication'
SESSION_PATH = '/session'
USER_PATH = '/user'
@TylerBrock
TylerBrock / notes.md
Last active August 29, 2015 14:11
Effective Modern C++ Items 10 + 11

Item 10: Prefer scoped enums to unscoped enums

  • Scoped
    • Generally declaring a name inside of curly braces limits scope to inside the braces.

    • Not so for C++98 style enums.

    • Names belong to scope containing the enum

    • Nothing else in that scope can have the same name

      enum Color { black, white, red }; // black, etc in the same scope as color

@TylerBrock
TylerBrock / words.go
Last active August 29, 2015 14:27
Go program to find the shortest path from one word to another
package main
import "log"
import "bytes"
import "bufio"
import "os"
import "sync"
import "runtime"
import "io/ioutil"
@TylerBrock
TylerBrock / five_stars.py
Created September 19, 2011 22:33
Max Sum Sublist
#!/usr/bin/python
"""
Tyler Brock for Five Stars - 2011
Write function f in python, that given a list of numbers
L returns i, j such that L[i:j] has maximal sum.
For example, if L = [1, -2, 3, 4, 5, -1] then f(L) should return (2, 5).
"""
@TylerBrock
TylerBrock / handlers.py
Created September 19, 2011 22:54
Handlers from ReadrBoard
from piston.handler import AnonymousBaseHandler
from django.http import HttpResponse, HttpResponseBadRequest
from django.db.models import Count
from decorators import status_response, json_data
from exceptions import JSONException
from utils import *
from userutils import *
from authentication.token import *
from settings import BASE_URL
from django.forms.models import model_to_dict
@TylerBrock
TylerBrock / mr.js
Created January 13, 2012 21:19
Map Reduce for Free-5947
db.logs.remove()
db.logs.insert(
{"name":"James Carr",
"log" : [
{
"comment" : "",
"time" : ISODate("2011-11-01T21:37:44.897Z"),
"user" : "Brad ************",
"action" : "Call",