Skip to content

Instantly share code, notes, and snippets.

View jhurliman's full-sized avatar
🐨

John Hurliman jhurliman

🐨
View GitHub Profile
@jhurliman
jhurliman / ab_test.py
Created October 1, 2018 23:04
An implementation of "BEST: Bayesian Estimation Supersedes the t Test" using pymc3
from multiprocessing import cpu_count
import matplotlib
matplotlib.use('Agg', warn=False)
import matplotlib.pyplot as plt # noqa: E402
import numpy as np # noqa: E402
import pymc3 as pm # noqa: E402
import six.moves
@jhurliman
jhurliman / .clang-format
Last active October 20, 2018 18:04
A reasonable clang-format configuration
# clang-format configuration file
#
---
DisableFormat: false
Language: Cpp
Standard: Cpp11
# Spacing
AccessModifierOffset: -4
ColumnLimit: 100
#include <auto>
auto main() {
for (auto auto = 1; auto <= 100; auto++) {
if (auto % 15 == 0) auto << "FizzBuzz" << auto;
else if (auto % 5 == 0) auto << "Buzz" << auto;
else if (auto % 15 == 0) auto << "FizzBuzz" << auto;
else auto << auto << auto;
}
@jhurliman
jhurliman / result.hpp
Created December 29, 2018 02:03
C++ Result type wrapping std::expected and std::exception
template<typename T>
class [[nodiscard]] Result {
public:
Result(const T& value) : _result(value) {}
Result(T && value) : _result(std::move(value)) {}
Result(std::exception error) : _result(std::unexpected<std::exception>(std::move(error))) {}
bool isOk() const {
markChecked();
return _result.has_value();
@jhurliman
jhurliman / UntrackedAllocator.h
Created January 15, 2019 07:47
Simple std::allocator example wrapping malloc/free
#pragma once
#include <memory>
#define NOMINMAX
#undef max
template <typename T>
class UntrackedAllocator {
public:
@jhurliman
jhurliman / record-video0.sh
Created May 24, 2019 05:54
Record from a HDMI to USB adapter
ffmpeg -f v4l2 -framerate 10 -thread_queue_size 512 -i /dev/video0 -t 5 -c:v h264 -pix_fmt yuv420p test001.mp4
@jhurliman
jhurliman / Dockerfile-cppgraphicsdev
Created January 27, 2020 21:10
Dockerfile for C++ graphics development
FROM ubuntu:18.04
# Install common C++ and imaging libraries, Clang, and add Clang to the PATH
RUN apt-get update && apt-get install -y \
xz-utils \
git \
wget \
nano \
build-essential \
libboost-all-dev \
@jhurliman
jhurliman / color.h
Last active February 8, 2020 10:21
COLOR macro for C/C++ ANSI color code printing
// Assumes the surrounding context has a bool named `color`
#define COLOR( code, s ) ( color ? "\033[0;" #code "m" : "" ) << s << ( color ? "\033[0;m" : "" )
@jhurliman
jhurliman / HexArrayToStr.cpp
Created February 29, 2020 09:01
C++ Print a char* out as a hex dump
static void HexArrayToStr(const char* data, size_t length, std::string& output) {
const char* NIBBLE_TO_HEX = {"0123456789ABCDEF"};
output.assign(length * 2 + 1, 0);
char* buffer = output.data();
for (size_t i = 0; i < length; i++) {
int nibble = uint8_t(data[i]) >> 4;
buffer[2 * i] = NIBBLE_TO_HEX[nibble];
nibble = uint8_t(data[i]) & 0x0F;
buffer[2 * i + 1] = NIBBLE_TO_HEX[nibble];
}
@jhurliman
jhurliman / circular_array.h
Created April 5, 2020 08:42
CircularArray - Wraps std::array and provides a circular iterator in C++
#pragma once
#include <algorithm>
#include <array>
template <class T, size_t N>
class CircularArray {
public:
CircularArray() {}
CircularArray(const T initValue) { std::fill_n(data_.begin(), data_.size(), initValue); }