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 / split2.sh
Created May 21, 2020
Use spleeter to split an input MP3 into separate vocal and accompaniment WAV files
View split2.sh
#!/usr/bin/env bash
DIR=$(dirname `readlink -e $1`)
FILE=$(basename `readlink -e $1`)
OUT_DIR=`basename ${FILE} .mp3`
MODEL_DIRECTORY="${HOME}/.cache/spleeter"
mkdir -p ${MODEL_DIRECTORY}
docker run \
-v ${DIR}:/work \
@jhurliman
jhurliman / circular_array.h
Created Apr 5, 2020
CircularArray - Wraps std::array and provides a circular iterator in C++
View circular_array.h
#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); }
@jhurliman
jhurliman / HexArrayToStr.cpp
Created Feb 29, 2020
C++ Print a char* out as a hex dump
View HexArrayToStr.cpp
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 / color.h
Last active Feb 8, 2020
COLOR macro for C/C++ ANSI color code printing
View color.h
// 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 / Dockerfile-cppgraphicsdev
Created Jan 27, 2020
Dockerfile for C++ graphics development
View Dockerfile-cppgraphicsdev
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 / 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
You can’t perform that action at this time.