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 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++ -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: "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
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
#!/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
// -*- compile-command: "clang++ -ggdb -std=c++11 -stdlib=libc++ -Wall -Werror tad_test.cpp -o tad_test" -*- | |
#include <iostream> | |
using namespace std; | |
template <typename T, typename U> | |
struct Foo { | |
T v; | |
U w; |
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
public class Copy { | |
public static void main(String[] args) throws Throwable { | |
int next; | |
while ((next = System.in.read()) != -1) { | |
System.out.write(next); | |
} | |
System.out.flush(); | |
} | |
} |
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/local/bin/bash | |
#How to manipulate the path in an intelligent fashion with bash. Note: this doesn't work with Bourne shell. | |
function idempotent_path_add { | |
DIR="$1" | |
PREPEND=$2 | |
if [[ ! "$PATH" =~ (^|:)"$DIR"(:|$) ]] | |
then | |
if [ $PREPEND ] | |
then |
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
from string import Formatter | |
import sys | |
def keywords_to_questionmarks(format_string, *args, **kwargs): | |
'''Convert a format string keyword formatted query to a ? wildcarded prepared statement | |
that is pyodbc compatible, along with the args tuple to pass to it. | |
* format_string: Python format compatible representation of a query | |
* args: positional args for the format string | |
* kwargs: keyword args for the format string |