Skip to content

Instantly share code, notes, and snippets.

@RandyGaul
RandyGaul / curriculum.txt
Last active August 16, 2023 20:13
Learn Software Engineering - Self Paced
WHAT IS THIS?
I get asked a lot about recommendations for self-taught or self-learning to become professional developer, so I
am slowly working on a curriculum someone could follow. If finished in earnest, you'd be at roughly bachelor degree
level of competence without any holes in your education. If anyone is interested, please do take a look and provide
feedback! The format is to collate really high quality links to references organized by major topic and sub-categories.
By design this is C/C++ centric. This encourages the learning of low level details and fundamental knowledge that
transcends technological fads, ensuring the knowledge won't ever go out of date, easily translatable to other higher
level languages, frameworks, granting sustainable flexibility in career potential.
@RandyGaul
RandyGaul / lines_2d_intersect.cpp
Last active January 6, 2023 01:20
2D halfspace intersection via cramer's rule
#ifndef _CRT_SECURE_NO_WARNINGS
# define _CRT_SECURE_NO_WARNINGS
#endif
#ifndef _CRT_NONSTDC_NO_DEPRECATE
# define _CRT_NONSTDC_NO_DEPRECATE
#endif
#include <vector>
// -------------------------------------------------------------------------------------------------
@RandyGaul
RandyGaul / wrap_triangle_in_minimal_bound_box.cpp
Last active January 7, 2023 23:37
Wrap a triangle in a minimal bounding box, optionally inflated by a radius factor
#ifndef _CRT_SECURE_NO_WARNINGS
# define _CRT_SECURE_NO_WARNINGS
#endif
#ifndef _CRT_NONSTDC_NO_DEPRECATE
# define _CRT_NONSTDC_NO_DEPRECATE
#endif
#include <vector>
// -------------------------------------------------------------------------------------------------
@RandyGaul
RandyGaul / htable.h
Last active November 6, 2022 05:31
Polymorphic C hash table macros
// Polymorphic hashtable API in C
//
// We get value semantics here for hset and hget (see comments below).
// An extra layer of indirection is internally used so we can sort {k,v} pairs, e.g. for priority queue.
// The main trick is the use of comma in C. Any statement in C takes on the value of the expression
// in the final comma, not any of the prior. We can use that to "return" a value in `hget` while running
// a few expressions beforehand. Since the user type is a pointer to a value we get polymorphism by
// the indirection or array operator `*h` or `h[0]`.
//
// Original inspired from these resources by Per Vognsen and Micha Mettke
@RandyGaul
RandyGaul / embed.c
Created September 25, 2022 20:17
Create an array of binary data to embed files into your program directly
// Embedded some small file here.
int g_some_file_sz = 64;
unsigned char g_some_file_data[64] = {
0x10,0xaa,0x98,0xe0,0x10,0x5a,0x3e,0x63,0xe5,0xdf,0xa4,0xb5,0x5d,0xf3,0x3c,0x0a,
0x31,0x5d,0x6e,0x58,0x1e,0xb8,0x5b,0xa4,0x4e,0xa3,0xf8,0xe7,0x55,0x53,0xaf,0x7a,
0x4a,0xc5,0x56,0x47,0x30,0xbf,0xdc,0x22,0xc7,0x67,0x3b,0x23,0xc5,0x00,0x21,0x7e,
0x19,0x3e,0xa4,0xed,0xbc,0x0f,0x87,0x98,0x80,0xac,0x89,0x82,0x30,0xe9,0x95,0x6c
};
// Creates an array like the one above.
@RandyGaul
RandyGaul / routine.h
Last active November 6, 2022 15:33
Portable "coroutine"-like thing for implementing FSM and behavior-cycles
#ifndef ROUTINE_H
#define ROUTINE_H
#include <stdint.h>
// A portable "coroutine"-like thing for implementing FSM and behavior-cycles.
//
// Original implementation by Noel Berry.
// See: https://gist.github.com/NoelFB/7a5fa66fc29dd7ed1c11042c30f1b00e
//
@RandyGaul
RandyGaul / edge_interesections.cpp
Last active November 15, 2022 15:18
Calculate edge-edge intersections of convex polygons via Sutherland-Hodgman in 2D
#ifndef _CRT_SECURE_NO_WARNINGS
# define _CRT_SECURE_NO_WARNINGS
#endif
#ifndef _CRT_NONSTDC_NO_DEPRECATE
# define _CRT_NONSTDC_NO_DEPRECATE
#endif
#include <vector>
// -------------------------------------------------------------------------------------------------
#include <stdio.h>
#include <assert.h>
struct item_t
{
int key;
int val;
};
int get_byte(int val, int byte_index)
@RandyGaul
RandyGaul / tiles_to_frames.lua
Created January 13, 2021 22:43
Aseprite Script for converting a square grid of tiles into individual Aseprite frames
-- Splits a sprite upon a grid into individual frames.
-- This file should go into your Aseprite scripts folder.
-- Aseprite -> File -> Scripts -> Open Scripts Folder
local dialog = Dialog("Split Tiles to Layers")
dialog:label{ id="help", label="", text="Set the width and height to split tiles by:" }
dialog:number{ id="tile_w", label="Tile Width:", text="8", focus=true }
dialog:number{ id="tile_h", label="Tile Height:", text="8" }
dialog:button{ id="ok", text="&OK", focus=true }
dialog:button{ text="&Cancel" }
@RandyGaul
RandyGaul / embed.c
Last active September 26, 2022 22:09
Embeds a file as a byte array in C
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
if (argc < 3) {
printf("Usage: embed <filename> <symbol>\n"); return -1;
}
const char* path = argv[1];