This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 \ | |
{ \ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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__))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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"); |