Skip to content

Instantly share code, notes, and snippets.

Christopher Smith cbsmith

  • Ticketmaster
Block or report user

Report or block cbsmith

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@cbsmith
cbsmith / protoc-gen-depends.py
Created Apr 16, 2012
Makefile dependency generator plugin for protoc.
View protoc-gen-depends.py
#!/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()
@cbsmith
cbsmith / joyent-instant-centos-salt-minion.sh
Created Apr 29, 2012
Instant CentOS Minion on Joyent
View joyent-instant-centos-salt-minion.sh
#!/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
@cbsmith
cbsmith / dont_terminate.cpp
Created Aug 8, 2012
The problem with std::uncaught_exception illustrated
View dont_terminate.cpp
// -*- 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;
@cbsmith
cbsmith / brace_initializer.cpp
Created Nov 27, 2012
Demonstration of brace initialization as well as variadic templates.
View brace_initializer.cpp
// -*- 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 {
@cbsmith
cbsmith / func.cc
Last active Dec 14, 2015
Me proving myself wrong.
View func.cc
// -*- 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; }
@cbsmith
cbsmith / declarative_storage.py
Last active Dec 14, 2015
My rather lame approach to setting parameter storage class. It also demonstrates how to write an IPN handler with Flask, as that was my use case where form argument order mattered (most annoying). End result is uglier than just setting the storage class inside your function, but does make it easier to see when that special case is being used.
View declarative_storage.py
#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'),)
@cbsmith
cbsmith / the_nullptr_story.cpp
Last active Dec 16, 2015
A 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. We've got people of type Person who, when they get married, may choose to take on their spouse's last name. These people always have a given last name, called "lastname", but they may…
View the_nullptr_story.cpp
// -*- 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
@cbsmith
cbsmith / cleanup.py
Last active Dec 16, 2015
Python code that traverses one or more directories, removing any orphaned .pyc's.
View cleanup.py
"""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
@cbsmith
cbsmith / random_selection.cpp
Last active Dec 6, 2018
Hopefully serves as a reference implementation on how to do random selection of an element from a container.
View random_selection.cpp
// -*- 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")()
@cbsmith
cbsmith / two_stars.cpp
Created May 21, 2013
Demonstration of how two_star programming works with STL containers and algorithms.d
View two_stars.cpp
// -*- 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;
You can’t perform that action at this time.