Skip to content

Instantly share code, notes, and snippets.

@socantre
socantre / gist:5995511
Last active December 19, 2015 17:59
Print a calandar for the given year using chrono::date Usage: a.out <year>
#include <date>
#include <vector>
#include <string>
#include <iostream>
int main(int argc, char *argv[]) {
const std::vector<std::string> month_names = {
"", "January", "February", "March", "April", "May", "June", "July",
"August", "September", "October", "November", "December"
};
@socantre
socantre / gist:7667148
Last active December 29, 2015 11:59
std::async program that hangs Windows ConcRT, but works with either std::launch::deferred or std::launch::async
#include <iostream>
#include <future>
#include <vector>
#include <atomic>
#include <random>
#include <string>
const int n_tasks = 1000;
std::atomic<bool> flags[n_tasks] = {};
@socantre
socantre / gist:8588819
Created January 23, 2014 23:17
factor factorials
#include <algorithm>
#include <iostream>
#include <random>
std::vector<int> &factor(int n, std::vector<int> &prime_factors) {
auto i = 2;
while (n > 1) {
if (0 == n % i) {
prime_factors.push_back(i);
n /= i;
@socantre
socantre / feature_check.cpp
Created January 24, 2014 23:34
C++ feature checking
#include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <string>
#include <type_traits>
#include <utility>
@socantre
socantre / wasapi_test.cpp
Last active November 12, 2018 09:23
Test with windows audio API
#define NOMINMAX
#include "scoped_resource.h"
#include <Audioclient.h>
#include <atlbase.h>
#include <audiopolicy.h>
#include <mmdeviceapi.h>
#include <chrono>
@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);