Skip to content

Instantly share code, notes, and snippets.

View W4RH4WK's full-sized avatar
🛠️
Technomancer

Alex Hirsch W4RH4WK

🛠️
Technomancer
View GitHub Profile
// The UnmanagedStorage wrapper is used to disable dynamic initialization and
// destructor calls for global variables. The wrapped object is stored inline
// and needs to be created and destroyed manually.
template <typename T>
class UnmanagedStorage {
public:
template <typename... Args>
T* emplace(Args&&... args) noexcept
{
reset();
@W4RH4WK
W4RH4WK / arena.cpp
Last active January 1, 2025 14:49
C++ Memory Arena (w/ destructor support)
#include <cassert>
#include <cstdint>
#include <cstdlib>
#include <iostream>
#include <type_traits>
using u8 = uint8_t;
using u32 = uint32_t;
using usize = size_t;
@W4RH4WK
W4RH4WK / main.cpp
Created November 7, 2024 12:04
Win11 SDK Debug Configuration Crash
// Build this program with a Windows 11 SDK (e.g. 10.0.22621.0) in debug
// configuration, using Multi-threaded Debug DLL (/MDd).
#include <Windows.h>
#include <fcntl.h>
#include <io.h>
#include <stdio.h>
// This causes ucrtbase.dll (release version) to be loaded, which might cause
@W4RH4WK
W4RH4WK / binary_io.hpp
Created December 2, 2023 13:14
binary io
#pragma once
#include <algorithm>
#include <cassert>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <filesystem>
#include <string>
////////////////////////////////////////////////////////////
// Vector 2D
template <typename T>
struct Vec2T {
constexpr Vec2T() = default;
constexpr Vec2T(T v) : x(v), y(v) {}
constexpr Vec2T(T x, T y) : x(x), y(y) {}
constexpr Vec2T(const Vec2T&) = default;
@W4RH4WK
W4RH4WK / CMakeLists.txt
Created March 19, 2023 20:57
SDL Game Controller RT/LT RB/LB
cmake_minimum_required(VERSION 3.25)
project(sdlinputtest LANGUAGES CXX)
find_package(SDL2 REQUIRED)
add_executable(sdlinputtest sdlinputtest.cpp)
target_link_libraries(sdlinputtest PRIVATE SDL2::SDL2 SDL2::SDL2main)
if(WIN32)
add_custom_command(TARGET sdlinputtest POST_BUILD
@W4RH4WK
W4RH4WK / parallel_sh.py
Last active October 22, 2022 15:40
Python run shell command shorthand
import subprocess
import sys
from asyncio import Future
from contextlib import contextmanager
@contextmanager
def ParallelSh():
"""
void copyOver(std::ofstream& dst, std::ifstream& src, std::uint64_t length)
{
// This seems to be broken, we are skipping bytes at some point. Apparently
// istream_iterator shouldn't be used for binary files, despite the
// underlying stream being opened in binary mode. istreambuf_iterator was
// suggested, but is not applicable here as it fills an internal buffer with
// more than we read and therefore advances the file cursor too far.
//
// std::copy_n(std::istream_iterator<uint8_t>(src), length,
// std::ostream_iterator<uint8_t>(dst));
from datetime import datetime
from typing import List
class DatetimeInterval:
def __init__(self, start, end):
self.start = start
self.end = end
def __lt__(self, other):
@W4RH4WK
W4RH4WK / bimap.hpp
Last active May 16, 2021 21:57
bimap
#pragma once
#include <cassert>
#include <map>
#include <memory>
#include <utility>
template <class L, class R, class CompareLeft = std::less<L>, class CompareRight = std::less<R>,
class AllocatorLeft = std::allocator<std::pair<const L, const R *>>,
class AllocatorRight = std::allocator<std::pair<const R, const L *>>>