Skip to content

Instantly share code, notes, and snippets.

View daniel-j-h's full-sized avatar
🤗

Daniel J. H. daniel-j-h

🤗
View GitHub Profile
@daniel-j-h
daniel-j-h / ct-strings.cc
Created July 15, 2016 21:42
Compile-time strings and string concatenation
#include <stdexcept>
#include <utility>
class Str {
public:
template <std::size_t N>
constexpr Str(const char(&a)[N]) : p(a), s(N - 1) {}
constexpr char operator[](std::size_t n) const {
@daniel-j-h
daniel-j-h / cut.sh
Created July 9, 2016 22:44
some of my favorite North by Northwest (http://www.imdb.com/title/tt0053125/) shots, cutting and transcoding to webm
#!/usr/bin/env bash
set -o errexit
set -o pipefail
set -o nounset
# https://trac.ffmpeg.org/wiki/Encode/VP8
# https://libav.org/documentation/avconv.html
@daniel-j-h
daniel-j-h / default.nix
Created July 7, 2016 22:47
Nix C++ compiler, CMake, Boost skeleton --- stable ABI
# Nix skeleton for compiler, cmake, boost.
# Dependencies (boost and others you specify) are getting built with selectec compiler (for ABI compatibility).
# Examples:
# nix-shell --argstr compiler gcc5 --run 'mkdir build && cd build && cmake .. && cmake --build .'
# nix-shell --argstr compiler gcc6 --run 'mkdir build && cd build && cmake .. && cmake --build .'
# nix-shell --argstr compiler clang_38 --run 'mkdir build && cd build && cmake .. && cmake --build .'
{ nixpkgs ? import <nixpkgs> {}, compiler ? "gcc6" }:
let
@daniel-j-h
daniel-j-h / LICENSE.md
Last active October 26, 2016 16:57
Lambdas instead of visitors

The MIT License (MIT)

Copyright (c) 2016 Daniel J. Hofmann

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

@daniel-j-h
daniel-j-h / line_range.h
Created May 18, 2016 14:23
Recursively Splittable Line Range for Intel TBB
#ifndef LINE_RANGE_HPP
#define LINE_RANGE_HPP
#include <cstddef>
#include <algorithm>
#include <iterator>
#include <tbb/parallel_reduce.h>
#include <tbb/tbb_stddef.h>
#include <utility>
template <typename Fn>
void make(Fn&& fn) {
auto fst = [cap1 = std::forward<Fn>(fn)]{
auto snd = [cap2 = std::forward<decltype(cap1)>(cap1)]{
cap2();
};
};
@daniel-j-h
daniel-j-h / spawn.js
Last active April 28, 2016 21:56
ES6 untangling callback 🍝
'use strict';
const fs = require('fs');
function spawn(generator) {
let it = generator(function (err, data) {
if (err) it.throw(err);
return it.next(data);
});
it.next();
@daniel-j-h
daniel-j-h / free_monad.cc
Last active March 27, 2016 10:55
Read about the Free Monad here: http://degoes.net/articles/modern-fp
#include <string>
#include <vector>
#include <iterator>
#include <iostream>
#include <boost/variant.hpp>
// http://degoes.net/articles/modern-fp
@daniel-j-h
daniel-j-h / build-boost-1-60.sh
Last active March 24, 2016 17:11
Script for building a local LLVM 3.8 distribution from source (with clang, libc++, lldb, ...); in addition scripts to then build Boost and Intel TBB against LLVM 3.8 and libc++
#!/usr/bin/env bash
# Builds a local Boost 1.60 distribution from source
# Usage: ./build-boost-1-60.sh directory
set -o errexit
set -o pipefail
set -o nounset
readonly where=$(realpath ${1:-boost-dev})
@daniel-j-h
daniel-j-h / is_instantiable.cc
Created February 24, 2016 16:54
Is there a specialization for a template class?
#include <utility>
#include <type_traits>
#include <iostream>
template <template <typename> class T, typename P, typename = void>
struct is_instantiable final : std::false_type {};
template <template <typename> class T, typename P>
struct is_instantiable<T, P, decltype((void)(T<P>(0)))> final : std::true_type {};