Skip to content

Instantly share code, notes, and snippets.

#include <algorithm>
#include <cstdint>
#include <iostream>
#include <mutex>
#include <random>
#include <thread>
using namespace std;
using u32 = uint_fast32_t;
using nl = numeric_limits<u32>;

Keybase proof

I hereby claim:

  • I am tclamb on github.
  • I am tclamb (https://keybase.io/tclamb) on keybase.
  • I have a public key whose fingerprint is A688 1FE6 7570 32B7 7096 D192 8ED2 3BAB 8112 71B5

To claim this, I am signing this object:

@tclamb
tclamb / gist:a599302beb39677f43f7
Last active August 29, 2015 14:17
defn, but with source and env attached for introspection
(defmacro defn*
"Like clojure.core/defn, with the function definition in :source metadata and env in :env metadata."
{:arglists (:arglists (meta #'defn))}
[f & xs]
`(defn ~(with-meta f (assoc (meta f)
:source `(quote ~&form)
:env `(zipmap (quote ~(keys &env))
(list ~@(keys &env)))))
~@xs))
@tclamb
tclamb / invention.h
Created April 18, 2014 19:06
Bach's Invention in C Major, BWV 772
#define C4_ 3821
#define Db4_ 3607
#define D4_ 3404
#define Eb4_ 3213
#define E4_ 3033
#define F4_ 2862
#define Gb4_ 2702
#define G4_ 2550
#define Ab4_ 2407
#define A4_ 2272
@tclamb
tclamb / chrono_io.hpp
Created April 2, 2014 18:14
an easily customizable duration printer for use with `<chrono>`
#include <chrono>
#include <iostream>
#include <tuple>
using day_t = std::chrono::duration<long long, std::ratio<3600 * 24>>;
template<typename> struct duration_traits {};
#define DURATION_TRAITS(Duration, Singular, Plural) \
template<> struct duration_traits<Duration> { \
constexpr static const char* singular = Singular; \
@tclamb
tclamb / indexer.hpp
Last active August 29, 2015 13:58
random access iterator for any container implementing `.size()` and `operator[](UInteger)`
#include <iterator>
#include <memory>
template<template<typename> class C,
typename T,
typename Index = std::size_t,
typename Difference = long
>
class indexer : public std::iterator<std::random_access_iterator_tag, T, Difference>
{
@tclamb
tclamb / unique_handle.cpp
Created April 2, 2014 18:05
DeadMG's `unique_ptr` wrapper for opaque types
#include <memory>
int open() { return 1; }
void close(int) {}
template<typename T, typename Deleter, Deleter d, T null_value = T{}>
struct value_deleter
{
struct wrapper
{
@tclamb
tclamb / mini-catch.cpp
Last active December 9, 2015 21:06
minimal working implementation of catch-lib's CHECK
#include <iostream>
struct is_unary
{
operator bool() { return {}; };
};
template <typename lhsT, typename rhsT>
struct result
{
@tclamb
tclamb / webserver.cpp
Created December 29, 2013 16:41
modification of `webserver.cpp` example that shows how to use `url_obj`
#include <iostream>
#include <native/native.h>
#include <sstream>
using namespace native::http;
int main() {
http server;
int port = 8080;
if(!server.listen("0.0.0.0", port, [](request& req, response& res) {
res.set_status(200);
@tclamb
tclamb / make_function.h
Created September 2, 2013 21:25
helper function for lambda type erasure (converting from lambda to std::function)
#include <functional>
#include <type_traits>
#include <utility>
namespace
{
/* SFNIAE helper struct for call signature extraction of
* member functions */
template<typename T> struct remove_class {};