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 / bk.cc
Last active May 1, 2017 09:17
BK-Tree for nearest neighbor queries in metric spaces
#include <climits>
#include <cstdint>
#include <cstdlib>
#include <algorithm>
#include <bitset>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
@daniel-j-h
daniel-j-h / app.py
Created March 5, 2017 18:03
q-gram inverted lists index for fuzzy autocompletion - works surprisingly well already
#!/usr/bin/env python3
import sys
import argparse
import collections
import curses
import curses.textpad
#python3 -m venv --system-site-packages venv
@daniel-j-h
daniel-j-h / newtype.h
Created February 20, 2017 14:33
Newtypes
#include <type_traits>
template <typename T, typename Tag> struct NewType {
struct Type : T { using T::T; };
};
using CostMatrix = NewType<Matrix<std::int64_t>, struct CostMatrixTag>::Type;
using TimeMatrix = NewType<Matrix<std::int64_t>, struct TimeMatrixTag>::Type;
static_assert(!std::is_same<CostMatrix, TimeMatrix>::value, "NewType not working");
@daniel-j-h
daniel-j-h / clang38-boost162.txt
Created December 1, 2016 22:50
crashing gcc 6.2 boost 1.62
crash.cc:16:27: warning: unused parameter 'first' [-Wunused-parameter]
static Tree Create(Iter first, Iter last) { return Leaf{}; }
^
crash.cc:16:39: warning: unused parameter 'last' [-Wunused-parameter]
static Tree Create(Iter first, Iter last) { return Leaf{}; }
^
In file included from crash.cc:4:
In file included from /home/daniel/llvm-dev-3.8-env/boost-dev-1-60/include/boost/variant.hpp:17:
/home/daniel/llvm-dev-3.8-env/boost-dev-1-60/include/boost/variant/variant.hpp:1732:52: error: no type named 'type' in 'boost::enable_if<boost::is_rvalue_reference<const Tree &>, void>'; 'enable_if' cannot be used to disable this declaration
variant(T&& operand, typename boost::enable_if<boost::is_rvalue_reference<T&&> >::type* = 0,
@daniel-j-h
daniel-j-h / wavelet.cc
Created November 30, 2016 02:28
Simple Wavelet Tree Experiments - https://en.wikipedia.org/wiki/Wavelet_Tree
#include <string>
#include <vector>
#include <iterator>
#include <algorithm>
#include <unordered_set>
#include <iostream>
#include <ostream>
#include <sstream>
#include <mapbox/variant.hpp>
@daniel-j-h
daniel-j-h / small_components.cc
Created October 13, 2016 10:33
For http://lists.boost.org/boost-users/2016/10/86809.php [Boost-users] boost graph pruning vertices (nodes)
#include <iostream>
#include <iterator>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <boost/graph/compressed_sparse_row_graph.hpp>
#include <boost/graph/filtered_graph.hpp>
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/graph_utility.hpp>
@daniel-j-h
daniel-j-h / xform.cc
Created September 22, 2016 15:57
Transform Iterator Lazy View for @jakepruitt
#include <iostream>
#include <vector>
#include <utility>
#include <boost/iterator/transform_iterator.hpp>
// Takes arbitrary [first,last) iterator range, returns pair of [first,last)-transform iterators applying fn on the fly
template <typename Iter>
auto xform(Iter first, Iter last) {
// dummy function requiring values in the range to be convertible with to_string
@daniel-j-h
daniel-j-h / KahanSum.cc
Created August 24, 2016 11:23
Kahan Summation: more accurate summation of floating point numbers (https://en.wikipedia.org/wiki/Kahan_summation_algorithm)
#include <iterator>
template <typename Iter>
typename std::iterator_traits<Iter>::value_type KahanSum(Iter first, Iter last) {
using T = typename std::iterator_traits<Iter>::value_type;
T sum(0);
T compensation(0);
for (; first != last; ++first) {
@daniel-j-h
daniel-j-h / inserter.cc
Created August 10, 2016 09:52
For Karen: OutputIterator example for unordered_map
#include <unordered_map>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
int main() {
// Empty int,string map
std::unordered_map<int, std::string> m;
@daniel-j-h
daniel-j-h / cut.sh
Created August 9, 2016 10:58
1/ go to geojson.io draw bounding box, save as bbox.geojson 2/ cut.sh big.pbf bbox.geojson small.pbf
#!/usr/bin/env bash
set -o errexit
set -o pipefail
set -o nounset
if [ $# -ne 3 ]; then
echo "Usage: cut.sh planet.pbf bbox.geojson outfile"
exit 1