Skip to content

Instantly share code, notes, and snippets.

View cbsmith's full-sized avatar

Christopher Smith cbsmith

View GitHub Profile
@cbsmith
cbsmith / declarative_storage.py
Last active December 14, 2015 10:09
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.
#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 / func.cc
Last active December 14, 2015 00:59
Me proving myself wrong.
// -*- 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 / brace_initializer.cpp
Created November 27, 2012 04:55
Demonstration of brace initialization as well as variadic templates.
// -*- 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 / dont_terminate.cpp
Created August 8, 2012 23:50
The problem with std::uncaught_exception illustrated
// -*- 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 / joyent-instant-centos-salt-minion.sh
Created April 29, 2012 03:22
Instant CentOS Minion on Joyent
#!/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 / protoc-gen-depends.py
Created April 16, 2012 05:15
Makefile dependency generator plugin for protoc.
#!/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()