Skip to content

Instantly share code, notes, and snippets.

View W4RH4WK's full-sized avatar
🔱
A demon, killing demons

Alex Hirsch W4RH4WK

🔱
A demon, killing demons
View GitHub Profile
@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 *>>>
@W4RH4WK
W4RH4WK / .clang-format-cpp
Last active November 4, 2020 09:47
Clang Format
---
Language: Cpp
BasedOnStyle: LLVM
ColumnLimit: 120
IndentWidth: 4
Standard: Latest
TabWidth: 4
UseTab: ForIndentation
AlignEscapedNewlines: Left
@W4RH4WK
W4RH4WK / payload.sh
Created April 17, 2020 12:41
Bash inline text payload
#!/bin/bash
readonly payload='\
foo abc xyz
bar def uvw'
while read one two three ; do
echo $one : $two : $three
done <<< $payload
// Instructions:
// 1) Add NuGet: glfw-net
// 2) Download official GLFW DLL (pre-compiled): https://www.glfw.org/download.html
// 3) Copy DLL to $(TargetDir) so it can be loaded
// 4) Rename DLL to glfw.dll
using GLFW;
using System;
using System.Threading;