Skip to content

Instantly share code, notes, and snippets.

View bit-hack's full-sized avatar

Aidan Dodds bit-hack

View GitHub Profile
@bit-hack
bit-hack / binheap.h
Last active February 16, 2016 08:35
Simple fixed size binary heap implementation, indented for A* applications.
// Simple fixed size binary heap implementation, intended for A* applications.
// Aidan Dodds 15/2/2016.
// Do whatever you want with this...
#pragma once
#include <stdint.h>
#include <array>
#include <cassert>
// Fixed size binary heap implementation
@bit-hack
bit-hack / random.h
Last active August 31, 2016 22:02
random.h is a header only random number generation library.
/* Random Number Generation Library
* Aidan Dodds 2016
*
* This library contains a bunch of random number routines with integer and
* float output and a handful of different weightings. These routines were
* written for use in the context of game development and image processing.
* These routines are in no way suitable for cryptographic purposes, or where
* statistical accuracy is required. Im a programmer, not a mathematician.
*
* I place this library in the public domain.
@bit-hack
bit-hack / gc.cpp
Last active August 16, 2016 11:33
Minimal example mark and sweep garbage collector.
#include <cassert>
#include <list>
#include <set>
#include <functional>
struct object_t {
object_t() : child_(nullptr) {}
virtual ~object_t() {};
object_t * child_;
protected:
@bit-hack
bit-hack / file.h
Last active August 31, 2016 22:39
file reader and writer classes
#pragma once
#include <array>
#include <string>
#include <cassert>
#include <cstdint>
#include <cstdio>
#include <vector>
#include <cstring>
@bit-hack
bit-hack / wav_to_aiff.cpp
Created September 3, 2016 11:50
Simple Wave file to AIFF converter
#include "file.h"
#include <memory>
#if !defined(_MSC_VER)
#define PACK__ __attribute__((__packed__))
#else
#define PACK__
#pragma pack(push, 1)
#endif
@bit-hack
bit-hack / random.md
Last active September 27, 2019 10:52
Be less random with rand()

Be less random with rand()

By Aidan Dodds // twitter

Introduction

It should come as no real surprise that most procedural content generation (PCG) systems are underpinned by a good random number generator. Most programming languages provide a means to generate random numbers; traditionally via a rand() function. This function typically generates uniform random numbers, which is to

@bit-hack
bit-hack / simplesort.cpp
Last active February 12, 2017 10:52
Simple Vector Sort
#include <assert.h>
#include <stdlib.h>
#include <vector>
struct test_t {
bool operator < (const test_t & rhs) const {
return value_<rhs.value_;
}
@bit-hack
bit-hack / vli.c
Created May 30, 2017 16:57
Variable Length Integer
// VARIABLE LENGTH INTEGER encode and decode functions
// Aidan Dodds (c) 2017
#include <assert.h>
#include <stdbool.h>
#include <stdint.h>
#if defined(_MSC_VER)
#define restrict __restrict
#endif
@bit-hack
bit-hack / midi_data.h
Last active June 1, 2017 16:44
General Midi Patch set for Adlib OPL chips.
/*
* Adplug - Replayer for many OPL2/OPL3 audio file formats.
* Copyright (C) 1999, 2000, 2001 Simon Peter, <dn.tlp@gmx.net>, et al.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
@bit-hack
bit-hack / tok.cpp
Created June 14, 2017 15:37
A very small expression tokenizer
#include <assert.h>
#include <string>
#include <vector>
static bool is_operator(const char ch) {
switch (ch) {
case '(':
case ')':
case '+':
case '-':