Skip to content

Instantly share code, notes, and snippets.

@socantre
socantre / gist:8904310
Created February 9, 2014 18:56
break thread pool async implementation
#include <iostream>
#include <future>
#include <vector>
#include <cassert>
struct S {
bool on_main_thread = false;
int tasks_run_on_this_thread = 0;
S() { std::cerr << "S ctor\n"; }
@socantre
socantre / gist:db01e449d3bb8640addc
Created May 3, 2014 16:55
for (auto &&kv : enumerate(x))
#include <vector>
#include <iostream>
#include <tuple>
#include <functional>
template<typename Container>
struct enumerate_iterator {
typename Container::size_type i;
typename Container::iterator v;
@socantre
socantre / make_killer.cpp
Created September 4, 2014 16:08
construct worst case for arbitrary? sort algorithm
#include <vector>
#include <algorithm>
void make_killer(int size, std::vector<int>& v) {
int candidate = 0;
int num_solid = 0;
int gas = size - 1;
std::vector<int> tmp(size);
v.resize(size);
@socantre
socantre / knights_tour.cpp
Created September 18, 2014 18:32
Knight's Tour, with Warnsdorff heuristic
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <iterator>
#include <vector>
#include <functional>
#include <cassert>
#include <chrono>
#include <array>
#include <memory>
#include <vector>
#include <algorithm>
#include <iterator>
#include <chrono>
#include <random>
#include <iostream>
#include <functional>
std::vector<int> all_equal(std::vector<int>::size_type n) {
return std::vector<int>(n, 1000000);
@socantre
socantre / tessellate_sphere.cpp
Last active August 29, 2015 14:07
(relatively) even tessellation of sphere
void tessellate_sphere(...) {
// tetrahedron
//Point a{ { 1, 1, 1 } }, b{ { 1,-1, -1 } }, c{ { -1, 1, -1 } }, d{ { -1, -1, 1 } };
//std::vector<Triangle> tris = {
// { { a, b, c } },
// { { a, c, d } },
// { { a, d, b } },
// { { b, d, c } }
@socantre
socantre / .clang-format
Created October 1, 2014 18:50
Clang format template
BasedOnStyle: LLVM # LLVM, Google, Chromium, Mozilla, WebKit
AccessModifierOffset: -4
AlignEscapedNewlinesLeft: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: true
AllowShortFunctionsOnASingleLine: false # None(false), Inline, All(true)
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
@socantre
socantre / master.cfg
Created October 11, 2014 22:10
buildbot master config for llvm/clang/libc++/lld
# -*- python -*-
# ex: set syntax=python:
c = BuildmasterConfig = {}
####### authentication credentials
web_status_users = [("user","fakefakefake")]
slaves = [("local-slave", "fakefakefake"),
@socantre
socantre / check_clock_resolution.cpp
Created October 23, 2014 16:47
see what resolution a chrono clock has
#include <future>
#include <atomic>
#include <iostream>
#include <vector>
#include <chrono>
template<typename Clock>
typename Clock::duration
check_clock_resolution() {
auto s = Clock::now();
#include <iostream>
#include <random>
#include <cassert>
#include <cstdint>
static int odd_bits(std::uint64_t i) {
auto a = (0xFFFFFFFFu & i) ^ (i >> 32);
auto b = (0x0000FFFFu & a) ^ (a >> 16);
auto c = (0x000000FFu & b) ^ (b >> 8);
auto d = (0x0000000Fu & c) ^ (c >> 4);