This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# Save this file as protoc-gen-depends, put it in your path (executable) and add "--depends-out=/whatever/path" to your protoc invocation | |
from google.protobuf.compiler.plugin_pb2 import CodeGeneratorRequest,CodeGeneratorResponse | |
from sys import stdin,stdout | |
req = CodeGeneratorRequest() | |
req.MergeFromString(''.join(stdin.readlines())) | |
res = CodeGeneratorResponse() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Setups up a new CentOS machine on Joyent running a Salt minion talking to your salt master. From there, you can do the rest of your setup work from the Salt Master. | |
# Requires Joyent Command Line SDK be installed as well as Node's jsontool (npm install jsontool) | |
# If you don't provide a Joyent ID, the code assumes the master is labeled with metadata "salt-role=master" or with "role=salt-master" | |
# Tweak these variables should have done anything creative with your salt setup | |
SALT_ROOT=/ | |
SALT_MASTER_UID=root |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// -*- compile-command: "clang++ -ggdb -o dont_terminate -std=c++0x -stdlib=libc++ dont_terminate.cpp" -*- | |
// Demonstration of the problem that can happen with using std::uncaught_exception() to determine | |
// whether it is safe to throw from within a destructor | |
// Problem identified, as always, by GOTW: http://www.gotw.ca/gotw/047.htm | |
#include <stdexcept> | |
#include <iostream> | |
#include <cassert> | |
using namespace std; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// -*- compile-command: "clang++ -ggdb -o brace_initializer -std=c++0x -stdlib=libc++ brace_initializer.cpp" -*- | |
#include <string> | |
#include <ostream> | |
#include <memory> | |
#include <iostream> | |
#include <sstream> | |
#include <new> | |
class Foo { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// -*- compile-command: "clang++ -std=c++11 -stdlib=libc++ -Wall -Werror func.cc -o func" -*- | |
#include <iostream> | |
#include <functional> | |
#include <utility> | |
#include <iomanip> | |
//The ugly beast we're wrapping | |
template <typename T1, typename T2, typename T3> | |
struct Hooks3 { | |
virtual bool Fire (int *, T1 t1, T2 t2, T3 t3) { return false; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#demonstration of hack to declaratively set param_storage_class declaratively using a decorator | |
#also demonstrates how to write an IPN handler with Flask | |
from flask import Flask, make_response | |
from itertools import chain | |
app = Flask(__name__) | |
#Normally this parameter would come from a config | |
IPN_URLSTRING = 'https://www.sandbox.paypal.com/cgi-bin/webscr' | |
IPN_VERIFY_EXTRA_PARAMS = (('cmd', '_notify-validate'),) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// -*- compile-command: "clang++ -pedantic -g -O3 -o the_nullptr_story -std=c++0x -stdlib=libc++ the_nullptr_story.cpp" -*- | |
// Simple example of how it is perfectly reasonable to have a pointer that may or may not be nullptr, | |
// and therefore delete a pointer that may or may not be nullptr. | |
// Formatting is a bit unusual/dense to make it easy to focus on the important bits. | |
#include <string> | |
#include <ostream> | |
class Person { | |
public: | |
//Moved to the top so nobody misses it |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Traverses the directory tree deleting any .pyc's who do not have a source .py. | |
Helpful when switching between revisions with source control.""" | |
from os.path import join | |
from os import walk, unlink | |
import re | |
import sys | |
PYTHON_RE = re.compile(R'^(.*\.py)(c)?$') | |
global count |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// -*- compile-command: "clang++ -ggdb -o random_selection -std=c++0x -stdlib=libc++ random_selection.cpp" -*- | |
//Reference implementation for doing random number selection from a container. | |
//Kept for posterity and because I made a surprising number of subtle mistakes on my first attempt. | |
#include <random> | |
#include <iterator> | |
template <typename RandomGenerator = std::default_random_engine> | |
struct random_selector | |
{ | |
//On most platforms, you probably want to use std::random_device("/dev/urandom")() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// -*- compile-command: "clang++ -ggdb -o two_stars -std=c++0x -stdlib=libc++ two_stars.cpp" -*- | |
#include <algorithm> | |
#include <iostream> | |
using namespace std; //laziness | |
int main(int argc, char** argv) { | |
int a = 1; | |
int b = 2; | |
int c = 3; |
OlderNewer