Skip to content

Instantly share code, notes, and snippets.

@lasarus
lasarus / ascii-raycasting.c
Created August 25, 2012 17:40
ASCII Raycasting
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include <math.h>
int quit = 0;
/*int screen_width = 640, screen_height = 480, screen_bpp = 32;*/
int screen_width = 1280, screen_height = 720, screen_bpp = 32;
int char_width = 8, char_height = 12;
int text_width = 80;
@darccio
darccio / pearson-hashing.c
Last active April 11, 2023 13:14
Pearson hashing (just for fun). Includes Ruby and Golang versions for RFC 3074 and original variants.
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
/*
* Pearson hashing (from Wikipedia)
*
* Pearson hashing is a hash function designed for fast execution on processors with 8-bit registers.
* Given an input consisting of any number of bytes, it produces as output a single byte that is strongly
* dependent on every byte of the input. Its implementation requires only a few instructions, plus a
anonymous
anonymous / udpnet.c
Created April 5, 2013 22:47
Simple UDP wrapper
#include "udpnet.h"
#if defined WIN32
typedef int socklen_t;
#else
#define closesocket(s) close(s)
#endif
static int udp_err_ = 0;
@koute
koute / opengl3_hello.c
Created November 9, 2013 23:16
Minimal SDL2 + OpenGL3 example.
/*
Minimal SDL2 + OpenGL3 example.
Author: https://github.com/koute
This file is in the public domain; you can do whatever you want with it.
In case the concept of public domain doesn't exist in your jurisdiction
you can also use this code under the terms of Creative Commons CC0 license,
either version 1.0 or (at your option) any later version; for details see:
http://creativecommons.org/publicdomain/zero/1.0/
@lbruder
lbruder / lbForth.c
Created April 6, 2014 15:21
A minimal Forth compiler in ANSI C
/*******************************************************************************
*
* A minimal Forth compiler in C
* By Leif Bruder <leifbruder@gmail.com> http://defineanswer42.wordpress.com
* Release 2014-04-04
*
* Based on Richard W.M. Jones' excellent Jonesforth sources/tutorial
*
* PUBLIC DOMAIN
*
@Khaledgarbaya
Khaledgarbaya / Hello_Triangle.cpp
Created October 4, 2014 22:28
Hello Triangle Sample With SDL in OpenGL ES 2 (IOS)
#include "SDL.h"
#include <OpenGLES/ES2/gl.h>
#include <OpenGLES/ES2/glext.h>
#include <iostream>
#include <string>
#include <memory>
using namespace std;
GLuint programObject;
class Graphics
@r-lyeh-archived
r-lyeh-archived / pcode.c
Last active February 23, 2022 00:01
pcode interpreter
/*
P-code for PL/0 machine
[ref] https://en.wikipedia.org/wiki/P-code_machine
[ref] http://blackmesatech.com/2011/12/pl0/pl0.xhtml
The PL/0 virtual machine was originally specified by Nicklaus Wirth in his book
Algorithms + Data Structures = Programs; it's used as the target machine for a
PL/0 compiler.
@baines
baines / freetype-atlas.c
Created July 15, 2016 13:32
minimal freetype texture atlas example
#include <stdio.h>
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "stb_image_write.h"
#include <ft2build.h>
#include FT_FREETYPE_H
#define NUM_GLYPHS 128
struct glyph_info {
int x0, y0, x1, y1; // coords of glyph in the texture atlas
@RickCarlino
RickCarlino / 00_forth.js
Last active February 23, 2022 00:25
Web Assembly Forth VM
var wasmCode = new Uint8Array([0,97,115,109,1,0,0,0,1,177,128,128,128,0,9,96,0,0,96,1,127,1,127,96,0,1,127,96,1,127,0,96,2,127,127,0,96,2,127,127,1,127,96,5,127,127,127,127,127,0,96,3,127,127,127,0,96,4,127,127,127,127,0,2,157,128,128,128,0,2,3,101,110,118,7,103,101,116,99,104,97,114,0,2,3,101,110,118,7,112,117,116,99,104,97,114,0,1,3,224,128,128,128,0,95,3,2,2,2,3,2,2,3,2,3,2,3,1,4,2,1,5,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,8,2,0,4,133,128,128,128,0,1,112,1,72,72,5,131,128,128,128,0,1,0,2,6,129,128,128,128,0,0,7,216,134,128,128,0,95,6,109,101,109,111,114,121,2,0,6,112,117,116,107,101,121,0,2,5,108,108,107,101,121,0,3,10,107,101,121,87,97,105,116,105,110,103,0,4,6,103,101,116,107,101,121,0,5,4,116,101,108,108,0,6,3,112,111,112,0,7,3,116,111,115,0,8,4,112,117,115,104,0,9,4,100,112,111,112,0,10,5,100,112,117,115,104,0,11,4,114,112,111,112,0,12,5,114,112,117,115,104,0,13,7,114,101,97,100,77,101,109,0
@tommyettinger
tommyettinger / mulberry32.c
Last active June 8, 2024 09:35
Mulberry32 PRNG
/* Written in 2017 by Tommy Ettinger (tommy.ettinger@gmail.com)
To the extent possible under law, the author has dedicated all copyright
and related and neighboring rights to this software to the public domain
worldwide. This software is distributed without any warranty.
See <http://creativecommons.org/publicdomain/zero/1.0/>. */
#include <stdint.h>