Skip to content

Instantly share code, notes, and snippets.

View takeiteasy's full-sized avatar
🧙‍♂️
We conjure the spirits of the computer with our spells

George Watson takeiteasy

🧙‍♂️
We conjure the spirits of the computer with our spells
  • /dev/null
  • 11:17 (UTC +01:00)
View GitHub Profile
@takeiteasy
takeiteasy / objc.h
Created July 10, 2025 21:54
objective-C runtime macros
#include <objc/objc.h>
#include <objc/runtime.h>
#include <objc/message.h>
#include <objc/NSObjCRuntime.h>
// maybe this is available somewhere in objc runtime?
#if __LP64__ || (TARGET_OS_EMBEDDED && !TARGET_OS_IPHONE) || TARGET_OS_WIN32 || NS_BUILD_32_LIKE_64
#define NSIntegerEncoding "q"
#define NSUIntegerEncoding "L"
#else
@takeiteasy
takeiteasy / generic_callback.c
Last active August 9, 2025 23:37
using _Generic to unify function pointers + blocks
#if __has_extension(blocks) && __has_include(<Block.h>)
#include <Block.h>
#endif
#include <stdio.h>
#include <stdbool.h>
#define _BLOCK_WRAPPER_STRUCT(NAME, RETURN, PARAM_TYPE, PARAM_NAME) \
typedef struct \
{ \
@takeiteasy
takeiteasy / defer.c
Last active July 10, 2025 21:38
go-like defer in C
#include <stdio.h>
#include <stdlib.h>
#define defer_merge(a,b) a##b
#define defer_varname(a) defer_merge(defer_scopevar_, a)
#define defer __attribute__((unused)) __attribute__((__cleanup__(defer_cleanup))) void (^defer_varname(__COUNTER__))(void) = ^
#define dtor(destructor) __attribute__((__cleanup__(destructor)))
static inline void defer_cleanup(void *ptr) {
@takeiteasy
takeiteasy / swizzle.h
Last active August 14, 2023 10:51
Vector swizzling in C
// Based off: https://github.com/swansontec/map-macro
// Generated by swizzle.rb
// https://github.com/takeiteasy
#define EVAL0(...) __VA_ARGS__
#define EVAL1(...) EVAL0(EVAL0(EVAL0(__VA_ARGS__)))
#define EVAL2(...) EVAL1(EVAL1(EVAL1(__VA_ARGS__)))
#define EVAL3(...) EVAL2(EVAL2(EVAL2(__VA_ARGS__)))
#define EVAL4(...) EVAL3(EVAL3(EVAL3(__VA_ARGS__)))
#define EVAL(...) EVAL4(EVAL4(EVAL4(__VA_ARGS__)))
@takeiteasy
takeiteasy / rnduni.c
Created August 11, 2023 18:43
random unicode string
#include <stdio.h>
#include <stdlib.h>
#define RAND_RANGE(x, y) (rand() % (y - x + 1) + x)
typedef struct {
unsigned short min, max;
} range_t;
static range_t ranges[] = {
// This is a modified C version of https://github.com/TylerGlaiel/FrameTimingControl
// See https://medium.com/@tglaiel/how-to-make-your-game-run-at-60fps-24c61210fe75 for more info
#if defined(macintosh) || defined(Macintosh) || (defined(__APPLE__) && defined(__MACH__))
#include <mach/mach_time.h>
#define ON_MAC
#elif defined(_WIN32) || defined(_WIN64) || defined(__WIN32__) || defined(__WINDOWS__)
#include <windows.h>
#define ON_WINDOWS
#else
@takeiteasy
takeiteasy / chinchirorin.cpp
Created April 28, 2022 15:44
the first game I made, circa 2008 or 9
#include <stdio.h>
#include <time.h>
#if (__WIN32__ || _WIN32 || _WIN64 || __WINDOWS__)
# define USING_WINDOWS
#endif
#if defined USING_WINDOWS
# include <windows.h>
#else // Assume POSIX
#include <cstdio>
constexpr unsigned int hash(const char* s, int off = 0) {
return !s[off] ? 5381 : (hash(s, off + 1) * 33) ^ s[off];
}
int main(int argc, const char* argv[]) {
int one = hash("one");
int two = hash("two");
int three = hash("three");