Skip to content

Instantly share code, notes, and snippets.

@wernsey
wernsey / lzss.c
Last active August 20, 2022 10:25
LZSS.C -- A Data Compression Program
/**************************************************************
LZSS.C -- A Data Compression Program
(tab = 4 spaces)
***************************************************************
4/6/1989 Haruhiko Okumura
Use, distribute, and modify this program freely.
Please send me your improved versions.
PC-VAN SCIENCE
NIFTY-Serve PAF01022
CompuServe 74050,1022
// Test program for miniz (https://github.com/richgel999/miniz)
#include <stdio.h>
#include "../miniz.h"
int main(int argc, char *argv[]) {
mz_zip_archive zip;
int i;
@wernsey
wernsey / editor.c
Created April 28, 2021 10:34
stb_tilemap_editor.h implementation in SDL
/*
gcc -Wall `sdl2-config --cflags` -O0 -g -o editor.o -c editor.c
gcc editor.o -lm `sdl2-config --libs` -o editor
*/
#include <SDL.h>
SDL_Renderer *renderer = NULL;
#define STB_TILEMAP_EDITOR_IMPLEMENTATION
@wernsey
wernsey / picol.h
Created December 16, 2020 12:51
Antirez' Picol Tcl interpreter, as an STB-style single header library
/**
* This is a modified version of [Picol][],
* Salvatore Sanfilippo ("antirez")'s Tcl interpreter in ~500 lines.
*
* This version turns it into a [STB][]-style single header library, so
* that it can be embedded into another program as a command interpreter.
*
* To use it, add a `#define PICOL_IMPLEMENTATION` above the
* `#include "picol.h"` in _one_ of your source files.
*
@wernsey
wernsey / Makefile
Created November 27, 2020 19:56
a Gap Buffer, in C
CC=gcc
CFLAGS=-c -Wall -DTEST
LDFLAGS=-lm
EXECUTABLE=gap
BUILD=debug
# Detect operating system:
# More info: http://stackoverflow.com/q/714100
@wernsey
wernsey / json.c
Last active October 28, 2020 11:01
Over-engineered C JSON module
/*
* JSON Parser and serializer.
*
* https://www.json.org/json-en.html
* https://tools.ietf.org/id/draft-ietf-json-rfc4627bis-09.html
*
*
* TODO: I came across this test suite for JSON parsers:
* [Parsing JSON is a Minefield](http://seriot.ch/parsing_json.php);
* I should maybe try running this parser through it one day.
@wernsey
wernsey / intern.c
Created September 13, 2020 10:49
String interning snippet
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
typedef struct internTreeNode ITNode;
/* =============================================================
String Interning
@wernsey
wernsey / datalog-naive v1.py
Last active August 14, 2019 19:27
Python Datalog
#! python
# Version 1.0
# Naive, with no negation.
# Also, no parser
class DatalogException(Exception):
pass
class Expr:
@wernsey
wernsey / luaone.c
Created June 13, 2019 08:41
Compile all the lua source in one go.
/*
Compile all the lua source in one go.
Put this in the `lua-5.3.5/src` directory, then compile like so:
$ cc lua.c luaone.c
$ cc luac.c luaone.c
Or compile to an object file like so:
@wernsey
wernsey / mdedit.html
Created April 18, 2019 11:45
In browser Markdown editor
<html>
<head>
<title>Markdown Editor</title>
<!--
It uses showdownjs to render the Markdown https://github.com/showdownjs/showdown
-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/showdown/1.9.0/showdown.min.js"></script>