Skip to content

Instantly share code, notes, and snippets.

@johnmcfarlane
johnmcfarlane / cnl_complete_11.h
Last active March 29, 2018 16:52
single-header versions of the CNL library
// Copyright John McFarlane 2017.
// 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)
// mechanically retrieved, single-header version of CNL library
// https://github.com/johnmcfarlane/cnl
#if ! defined(CNL_COMPLETE_H)
@johnmcfarlane
johnmcfarlane / functional.h
Created July 14, 2017 20:35
Fixing `std::functional`.
#include <functional>
#include <memory>
#include <stdlib.h>
#if defined(USE_ALTERNATIVE)
template<class FunctionSignature>
class function;
template<class Result, class...Args>
@johnmcfarlane
johnmcfarlane / broken_header.h
Last active July 8, 2017 01:19
A broken header
#include <stdlib.h>
namespace a_namespace{
constexpr int x = 6;
#if defined TEST
#error The test passed (ironically)
#endif
}
@johnmcfarlane
johnmcfarlane / jmcf.xml
Last active July 3, 2017 19:55
some CLion formatting settings that I think I might be able to tollerate
<code_scheme name="jmcf">
<Objective-C>
<option name="INDENT_NAMESPACE_MEMBERS" value="0" />
<option name="INDENT_C_STRUCT_MEMBERS" value="2" />
<option name="INDENT_CLASS_MEMBERS" value="2" />
<option name="INDENT_INSIDE_CODE_BLOCK" value="2" />
<option name="KEEP_STRUCTURES_IN_ONE_LINE" value="true" />
<option name="KEEP_CASE_EXPRESSIONS_IN_ONE_LINE" value="true" />
<option name="FUNCTION_NON_TOP_AFTER_RETURN_TYPE_WRAP" value="0" />
<option name="FUNCTION_TOP_AFTER_RETURN_TYPE_WRAP" value="0" />
@johnmcfarlane
johnmcfarlane / test.h
Created June 29, 2017 06:47
A very small header
// here is a very small header
@johnmcfarlane
johnmcfarlane / fixed_point.h
Last active June 28, 2017 14:47
Single-header version of fixed_point library
// Copyright John McFarlane 2017.
// 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)
// mechanically retrieved, single-header version of fixed_point library
// https://github.com/johnmcfarlane/fixed_point
#if ! defined(SG14_FIXED_POINT_SINGLE_HEADER)
@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

@johnmcfarlane
johnmcfarlane / kristerw.cpp
Last active November 26, 2025 08:32
Examples from Krister Walfridsson's [How undefined signed overflow enables optimizations in GCC](https://kristerw.blogspot.com/2016/02/how-undefined-signed-overflow-enables.html).
// examples from Krister Walfridsson's "How undefined signed overflow enables optimizations in GCC":
// https://kristerw.blogspot.com/2016/02/how-undefined-signed-overflow-enables.html
// https://godbolt.org/g/Hw797e
// Other relevant material:
// [CppCon 2016: Jon Kalb “unsigned: A Guideline for Better Code"](https://www.youtube.com/watch?v=wvtFGa6XJDU)
// [CppCon 2016: Chandler Carruth “Garbage In, Garbage Out: Arguing about Undefined Behavior..."](https://www.youtube.com/watch?v=yG1OZ69H_-o&t=2542s)
#include <algorithm>
#!/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 / 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;