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/env python | |
import sqlite3 | |
from_location_group = { | |
'OBD1': 'Online', | |
'OBD2': 'Online', | |
'CB07': 'Retail', | |
'CB08': 'Retail', | |
'CB09': 'Retail', |
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
import random | |
import itertools | |
def sample(population, k): | |
"How random.sample should really be defined." | |
if callable(getattr(population, '__len__', None)) and callable(getattr(population, '__getitem__', None)): | |
return random.sample(population, min(k, len(population))) | |
p = iter(population) |
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: "g++ -O3 -march=native -std=c++11 -Wall -Werror endian.cpp -o endian" -*- | |
#include <fstream> | |
#include <ostream> | |
#include <istream> | |
#include <cstdint> | |
#include <algorithm> | |
#include <cassert> | |
#include <string> | |
#include <vector> | |
#include <limits> |
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++ -Weverything -Wno-c++98-compat -ggdb -o test -std=c++11 -stdlib=libc++ test.cpp" -*- | |
#include <iostream> | |
#include <type_traits> | |
template <typename T, typename U, bool boolable = std::is_convertible<T,bool>::value, bool assignable = std::is_assignable<T, U>::value > | |
struct or_assign_helper; | |
template <typename T, typename U> | |
struct or_assign_helper<T, U, true, true> { |
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 test -std=c++11 -stdlib=libc++ test.cpp" -*- | |
#include <iostream> | |
float add(float x, float y) { | |
return x+y; | |
} | |
auto add_fourty_two = +[](float x) { return add(x, 42); }; | |
auto add_pie_and_fourty_two = +[]() { return add_fourty_two(3.1415926); }; |
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_98 -std=c++98 -stdlib=libc++ two_stars_98.cpp" -*- | |
#include <algorithm> | |
#include <iostream> | |
using namespace std; | |
bool points_to_two(int* x) { | |
return *x == 2; | |
} |
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; |
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
"""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++ -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 |