Skip to content

Instantly share code, notes, and snippets.

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

Daniel J. H. daniel-j-h

🤗
  • Berlin, Germany
  • 16:42 (UTC +02:00)
View GitHub Profile
@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 {};
@daniel-j-h
daniel-j-h / timeline.md
Last active February 14, 2016 20:46
Mariam's Tasks
  • Learn enough Git to be dangerous! You should have an understanding of how to clone repositories, make commits, checkout branches, push branches to Github, pull / rebase changes from Github. Resources: Pro Git Book, Github Tutorial, Atlassian Git Tutorial. After years I'm still learning new Git tricks every now and then, it's always a good idea to have a solid understanding of how things work
  • Create a Git repository on Github for the project (and find a cool name for it :P). You will regularly push commits to this repository, and we can use the issue tracker as some sort of todo list. Add a Readme written in Markdown and add a License for the project
  • Read up about IRC. This is where you can find lots and lots of people that can help you, especially when it comes to technical or programming language related questions (be aware that some channels can be rough though). Either install an IRC client or use a web interface for it (probably easier). I hang out on the oftc and freenode IRC networks a
@daniel-j-h
daniel-j-h / future_list_intersect.cc
Created February 4, 2016 00:07
Trying my hands at the challenge proposed in https://www.youtube.com/watch?v=UMbc6iyH-xQ at 21:18 (what is basically a specialized liftA2)
#include <list>
#include <future>
#include <algorithm>
#include <iostream>
#include <initializer_list>
std::future<std::list<int>> intersect(std::future<std::list<int>> a, std::future<std::list<int>> b) {
return std::async([a = move(a), b = move(b)]() mutable {
std::list<int> cs;
@daniel-j-h
daniel-j-h / specialization.cc
Created February 3, 2016 15:04
Partial specialization: user partially specializes implementation, function dispatches
#include <cstdio>
template <typename T, typename U>
struct fnImpl;
template <typename T, typename U>
int fn(T, U) {
return fnImpl<T, U>::fn();
}
@daniel-j-h
daniel-j-h / jujd.cc
Last active February 3, 2016 12:31
printf all integrals with single format specifier
#include <boost/iostreams/device/mapped_file.hpp>
#include <type_traits>
#include <cstdint>
template <typename T>
auto jd(T x) {
static_assert(std::is_signed<T>() and std::is_integral<T>(), "signed integral");
return static_cast<std::intmax_t>(x);
@daniel-j-h
daniel-j-h / patterns.cc
Created January 25, 2016 22:47
Coroutine Patterns: Fan In (Multiplexer), Fan Out (Demultiplexer)
#include <boost/coroutine/all.hpp>
#include <algorithm>
#include <iterator>
#include <type_traits>
#include <utility>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
@daniel-j-h
daniel-j-h / getSat.py
Last active January 25, 2016 17:18
Get Satellite Images for Coordinate
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
import argparse, os
from mapbox import Static
def makeArguments():
parser = argparse.ArgumentParser(description='Satellite images for (latitude, longitude) tuple',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--latitude', dest='latitude', type=float, help='Latitude')
@daniel-j-h
daniel-j-h / MortonCodeHaswell.cc
Last active October 13, 2020 19:09
Making use of Haswell's BMI2 PDEP instruction for Morton Codes / Z-Order
#include <cstdint>
#include <immintrin.h>
// Z-order via bit interleaving a and b as in: a[31]b[31]a[30]b[30]...
inline std::uint64_t zorder(std::uint32_t a, std::uint32_t b) {
return _pdep_u64(a, 0xaaaaaaaaaaaaaaaaULL) | _pdep_u64(b, 0x5555555555555555ULL);
}
@daniel-j-h
daniel-j-h / CMakeLists.txt
Last active January 23, 2016 17:02
Boost.ASIO + Boost.Coroutine --- async. device-based I/O; note: no support for file descriptors!
CMAKE_MINIMUM_REQUIRED(VERSION 3.0.2 FATAL_ERROR)
PROJECT(coroutine-asio VERSION 0.0.1 LANGUAGES CXX)
IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wall -Wextra -pedantic -Wold-style-cast -Wuninitialized -Wunreachable-code -Wstrict-overflow=3 -D_FORTIFY_SOURCE=2 -ffunction-sections -fdata-sections")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-O1 -Wl,--hash-style=gnu -Wl,--sort-common -Wl,--gc-sections")
IF(${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fmax-errors=1")
@daniel-j-h
daniel-j-h / coroutine.cc
Created January 18, 2016 13:46
Boost.Coroutine meets Boost.Graph
#include <vector>
#include <iostream>
#include <iterator>
#include <boost/graph/compressed_sparse_row_graph.hpp>
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/graph_utility.hpp>
#include <boost/graph/breadth_first_search.hpp>
#include <boost/coroutine/all.hpp>