Skip to content

Instantly share code, notes, and snippets.

@jemand2001
jemand2001 / signaling.cpp
Created March 31, 2025 17:57
event handling returning collected results of events
#include "signals.hpp"
#include <iostream>
struct MyEvent {
using Signature = void(int);
};
struct OtherEvent {
using Signature = int(int);
};
@jemand2001
jemand2001 / tempfile.cpp
Last active November 18, 2023 12:24
an RAII wrapper around the c mktemp api (cleans up after itself)
#include <cstdlib>
#include <unistd.h>
#include <cerrno>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <stdexcept>
#include <string>
#include <filesystem>
@jemand2001
jemand2001 / threadpool.cpp
Created September 3, 2023 10:20
maybe a correct threadpool implementation in c++
#include <algorithm>
#include <condition_variable>
#include <functional>
#include <mutex>
#include <queue>
#include <thread>
#include <vector>
struct threadpool {
std::vector<std::jthread> threads;
@jemand2001
jemand2001 / memory.cpp
Last active September 14, 2023 16:03
rudimentary shared_ptr implementation
#include <atomic>
#include <concepts>
#include <iostream>
#include <stdexcept>
#include <vector>
template <typename T>
class Badge {
friend T;
Badge() = default;
@jemand2001
jemand2001 / menu.html
Last active August 19, 2023 20:30
radial menu in html
<style>
button {
--size: 75px;
width: var(--size);
height: var(--size);
border-radius: calc(var(--size) / 2);
border: var(--color) 1px solid;
}
#main {
position: absolute;
@jemand2001
jemand2001 / expected_coro.cpp
Last active September 14, 2023 16:02
monadic std::expected using coroutines
#include <coroutine>
#include <expected>
#include <optional>
#include <iostream>
#include "return_object_holder.hpp"
using std::coroutine_traits;
template <typename R, typename E>
@jemand2001
jemand2001 / logging.hpp
Created August 6, 2023 19:45
tiny logging function (colors, source location, no macros)
#include <format>
#include <iostream>
#include <source_location>
#include <string_view>
#include <tuple>
#include <unordered_map>
enum class LogLevel { DEBUG, INFO, WARNING, ERROR, CRITICAL };
namespace CLIColors {
@jemand2001
jemand2001 / bindings.hpp
Last active May 5, 2025 09:21
late binding dynamic libraries
#include <dlfcn.h>
#include <format>
#include <memory>
#include <stdexcept>
#include <unordered_map>
struct dl_exception : std::runtime_error {
using std::runtime_error::runtime_error;
};
@jemand2001
jemand2001 / lazy.cpp
Last active September 14, 2023 16:04
lazy loading of data using initializer and a function to get the actual value
#include <variant>
#include <functional>
#include <iostream>
template <typename Info, typename Actual>
class Lazy {
struct info_holder {
Info x;
};
@jemand2001
jemand2001 / components.cpp
Last active September 16, 2023 23:16
tree-like structures between classes through template inheritance
#include <iostream>
#include <memory>
#include <ranges>
#include <source_location>
#include <vector>
#include "traits.hpp"
class Scene;
class Entity;