Skip to content

Instantly share code, notes, and snippets.

@rioki
rioki / latch.h
Last active May 9, 2024 12:58
sthread, like jthread, just simpler.
// latch
// Copyright 2017-2024 Sean Farrell <sean.farrell@rioki.org>
//
// This program is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it
// and/or modify it under the terms of the Do What The Fuck You Want
// To Public License, Version 2, as published by Sam Hocevar. See
// http://www.wtfpl.net/ for more details.
#pragma once
@rioki
rioki / StateMachine.h
Created April 6, 2024 15:58
State Machine
// State Machine
// Copyright 2022 Sean Farrell <sean.farrell@rioki.org>
//
// This program is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it
// and/or modify it under the terms of the Do What The Fuck You Want
// To Public License, Version 2, as published by Sam Hocevar. See
// http://www.wtfpl.net/ for more details.
#pragma once
@rioki
rioki / dbg.h
Created January 9, 2017 10:51
Debug Helpers
//
// Debug Helpers
//
// Copyright (c) 2015 - 2017 Sean Farrell <sean.farrell@rioki.org>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
@rioki
rioki / autosync.js
Last active October 26, 2023 17:58
Automatically sync two directories with node.js.
var fs = require("fs");
var path = require("path");
var configFile = "autosync.json";
if (process.argv.length == 3) {
configFile = process.argv[2];
}
var config = JSON.parse(fs.readFileSync(configFile, "UTF-8"));
//
// Copyright (c) 2014 Sean Farrell
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
@rioki
rioki / CrashWatchdog.cpp
Created April 4, 2023 07:48
CrashWatchdog
// This program is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it
// and/or modify it under the terms of the Do What The Fuck You Want
// To Public License, Version 2, as published by Sam Hocevar. See
// http://www.wtfpl.net/ for more details.
#include "CrashWatchdog.h"
#include <stdexcept>
#include <array>
name: Auto approve
on:
issue_comment:
types:
- created
jobs:
auto-approve:
runs-on: ubuntu-latest
@rioki
rioki / opt-gtest.h
Created June 6, 2022 18:08
Better Google Test Support for std::optional.
// std gtest comparators
// Copyright 2022 Sean Farrell <sean.farrell@rioki.org>
//
// This program is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it
// and/or modify it under the terms of the Do What The Fuck You Want
// To Public License, Version 2, as published by Sam Hocevar. See
// http://www.wtfpl.net/ for more details.
#pragma once
@rioki
rioki / one_of.h
Created April 26, 2022 07:39
one_of: a small piece of code that removes switch on enum statements.
template <typename EnumT> constexpr
bool one_of(EnumT value, const std::initializer_list<EnumT>& checkValues)
{
for (const auto& cv : checkValues)
{
if (value == cv)
{
return true;
}
}
@rioki
rioki / iterator_wrapper.h
Created April 25, 2022 13:24
Iterator wrapper that allows to use two iterators in range based for loop.
template <typename T>
struct iterator_wrapper
{
iterator_wrapper(T&& begin, T&& end) noexcept
: m_begin{std::forward<T>(begin)}, m_end{std::forward<T>(end)} {}
const T& begin() const noexcept
{
return m_begin;
}