Skip to content

Instantly share code, notes, and snippets.

John Hurliman jhurliman

Block or report user

Report or block jhurliman

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@jhurliman
jhurliman / record-video0.sh
Created May 24, 2019
Record from a HDMI to USB adapter
View record-video0.sh
ffmpeg -f v4l2 -framerate 10 -thread_queue_size 512 -i /dev/video0 -t 5 -c:v h264 -pix_fmt yuv420p test001.mp4
@jhurliman
jhurliman / UntrackedAllocator.h
Created Jan 15, 2019
Simple std::allocator example wrapping malloc/free
View UntrackedAllocator.h
#pragma once
#include <memory>
#define NOMINMAX
#undef max
template <typename T>
class UntrackedAllocator {
public:
@jhurliman
jhurliman / result.hpp
Created Dec 29, 2018
C++ Result type wrapping std::expected and std::exception
View result.hpp
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();
View fizzbuzz.cpp
#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 / .clang-format
Last active Oct 20, 2018
A reasonable clang-format configuration
View .clang-format
# clang-format configuration file
#
---
DisableFormat: false
Language: Cpp
Standard: Cpp11
# Spacing
AccessModifierOffset: -4
ColumnLimit: 100
@jhurliman
jhurliman / ab_test.py
Created Oct 1, 2018
An implementation of "BEST: Bayesian Estimation Supersedes the t Test" using pymc3
View ab_test.py
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 / tls_guardvar.cpp
Created May 8, 2018
Directly access a compiler-generated Thread Local Storage guard variable
View tls_guardvar.cpp
// Tested with clang-6.0 on Ubuntu 14.04 using:
// clang --std=c++14 -stdlib=libstdc++ -lstcd++ -fasm-blocks -O3 tls_guardvar.cpp -o tls_guardvar
// I will be genuinely surprised if this works in any other circumstance.
#include <iostream>
struct S {
int x;
S() { x = 42; }
};
@jhurliman
jhurliman / allWithProgress.js
Created May 5, 2017
Wrapper for Promise.all() that adds a progress callback
View allWithProgress.js
function allWithProgress(promises, callback) {
let completed = 0
callback(0, promises.length)
promises.forEach(p => {
p.then(() => callback(++completed, promises.length))
})
return Promise.all(promises)
}
@jhurliman
jhurliman / valueAtPath.js
Created Apr 22, 2017
Safely retrieve a value from a nested object with a path like 'a.b.c'
View valueAtPath.js
/**
* Safely retrieve a value from a nested object using a string path such as
* 'a.b.c' or an array ['a', 'b', 'c'].
*/
function valueAtPath (obj, path) {
if (!Array.isArray(path)) {
if (!path) return obj
path = path.split('.')
}
@jhurliman
jhurliman / binaryninja-dijkstra.cpp
Created Dec 13, 2016
Find the shortest distance between source and target basic blocks in Binary Ninja
View binaryninja-dijkstra.cpp
namespace BN = BinaryNinja;
using std::map;
using std::pair;
using std::priority_queue;
using std::vector;
int32_t dijkstra(vector<BN::Ref<BN::BasicBlock>> blocks, BN::Ref<BN::BasicBlock> source, BN::Ref<BN::BasicBlock> target) {
using path = pair<int32_t, uint64_t>;
You can’t perform that action at this time.