Skip to content

Instantly share code, notes, and snippets.

View JettMonstersGoBoom's full-sized avatar
💭
I may be slow to respond.

Jett JettMonstersGoBoom

💭
I may be slow to respond.
View GitHub Profile
@theabbie
theabbie / Dijkstra.c
Last active April 15, 2024 02:27
Dijkstra's Shortest path algorithm in C
#include <stdio.h>
#define MAX 20
#define INF 1000
typedef struct {
int predecessor;
int distance;
int status;
int neighbours[MAX];
} Node;
@munificent
munificent / generate.c
Last active September 15, 2024 03:16
A random dungeon generator that fits on a business card
#include <time.h> // Robert Nystrom
#include <stdio.h> // @munificentbob
#include <stdlib.h> // for Ginny
#define r return // 2008-2019
#define l(a, b, c, d) for (i y=a;y\
<b; y++) for (int x = c; x < d; x++)
typedef int i;const i H=40;const i W
=80;i m[40][80];i g(i x){r rand()%x;
}void cave(i s){i w=g(10)+5;i h=g(6)
+3;i t=g(W-w-2)+1;i u=g(H-h-2)+1;l(u
@newlawrence
newlawrence / vagenc.c
Last active January 26, 2024 16:40
A "not too much elegant" (and the only) way to get a templated, variadic and type-safe function in pure C
#include <stdio.h>
#define COUNT(...) (sizeof((int[]){ __VA_ARGS__ })/sizeof(int))
#define __eval(x0, x1, x2, x3, ...) _Generic((x0), \
void*: _Generic((x1), int: _evali, double: _evald), \
int: _evali, \
double: _evald \
)( \
COUNT(__VA_ARGS__) - _Generic((x0), void *: 1, default: 0), \
@nickrolfe
nickrolfe / windows_modern_opengl_context.c
Last active October 13, 2024 00:03
Sample code showing how to create a window using a modern OpenGL core profile context without any libraries other than the standard Win32 wglXXX calls.
// Sample code showing how to create a modern OpenGL window and rendering context on Win32.
#include <windows.h>
#include <gl/gl.h>
#include <stdbool.h>
typedef HGLRC WINAPI wglCreateContextAttribsARB_type(HDC hdc, HGLRC hShareContext,
const int *attribList);
wglCreateContextAttribsARB_type *wglCreateContextAttribsARB;