Skip to content

Instantly share code, notes, and snippets.

View johnmcfarlane's full-sized avatar

John McFarlane johnmcfarlane

View GitHub Profile
@johnmcfarlane
johnmcfarlane / yaml_deep_compare.hpp
Created November 2, 2015 22:59
For yaml-cpp: `bool isEqual(YAML::Node const &lhs, YAML::Node const &rhs)`
bool isEqual(YAML::Node const &lhs, YAML::Node const &rhs) {
if (lhs == rhs) {
return true;
}
YAML::NodeType::value lhs_type = lhs.Type();
if (lhs_type != rhs.Type()) {
return false;
}
zoox::unique_ptr<FRawMesh> ReadPly(ByteBuffer const & buffer)
{
// read the header
constexpr auto header =
"ply\n\n"
"format binary_little_endian 1.0\n"
"comment This contains a Splatted Point Cloud\n"
"element vertex %d\n"
"property float x\n"
"property float y\n"
@johnmcfarlane
johnmcfarlane / fixed_point.md
Created July 9, 2016 20:41
Result of running fixed_point.h through standardese

Header file fixed_point.h

#define SG14_FIXED_POINT_H 1

#include "type_traits.h"

#include "bits/common.h"

#define SG14_FIXED_POINT_EXCEPTIONS_ENABLED

static auto start = std::chrono::system_clock::now();
auto t = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::system_clock::now() - start).count();
@johnmcfarlane
johnmcfarlane / elastic
Last active November 15, 2016 04:11
single-header version of header, elastic.h, from johnmcfarlane/fixed_point
// Copyright John McFarlane 2015 - 2016.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file ../LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
/// \file
/// \brief essential definitions related to the `sg14::elastic` type
#define SG14_USE_INT128
@johnmcfarlane
johnmcfarlane / value_type.hpp
Created December 12, 2016 07:41
possible implementation of proposed standard library additions, std::value_type and std::value_type_t
#include <array>
#include <atomic>
#include <complex>
#include <cstddef>
#include <functional>
#include <list>
#include <memory>
#include <string>
#include <type_traits>
#include <unordered_map>
@johnmcfarlane
johnmcfarlane / stats.hpp
Created January 6, 2017 21:04
most basic statistics gatherer
#include <algorithm>
#include <limits>
template<typename Number = int, typename Counter = int>
class stats {
public:
void sample(Number const & n) {
_sum += n;
_count ++;
_minimum = std::min(_minimum, n);
@johnmcfarlane
johnmcfarlane / buffer.hpp
Created January 19, 2017 02:22
2-pointer sequence; like a vector without dynamic growth; somewhat standards-compliant
#include <algorithm>
#include <iterator>
#include <memory>
namespace sg14 {
template<typename T>
class buffer : public std::iterator_traits<T*> {
public:
using size_type = typename buffer<T>::difference_type;
#!/usr/bin/env python3
from argparse import ArgumentParser
from io import StringIO
from itertools import chain
from os import chdir, curdir, path
from subprocess import CalledProcessError, check_output, PIPE
from sys import argv, stderr
from report import benchmarks_from_buffer, csv_from_report, table_from_benchmarks
@johnmcfarlane
johnmcfarlane / i like commonmark.md
Last active May 12, 2017 19:25
A very quick demonstration of commonmark

A quick vote for commonmark:

  • it's very easy to read and write - even in as raw text;
  • it's well supported by GitHub;
  • it does 90% of what you need to write technical documentation;
  • it allows you to casually drop snippets of HTML/JSON in for the other 10% and
  • there are plenty of tools for converting it to HTML and other formats (see Pandoc and cmark).

In fact the above rant is commonmark! https://gist.github.com/johnmcfarlane/aec9d1c55d25bbbc086469c0c897b580