Skip to content

Instantly share code, notes, and snippets.

@wernsey
wernsey / JProlog.java
Last active September 21, 2015 08:42
A Java port of Chris Meyers' Prolog interpreter
/*
Simple Java Prolog engine.
This is basically a Java port of Chris Meyers' Python Prolog interpreter [1].
This currently only contains the first part, but maybe I'll port the remainder at
a later stage.
I actually wanted a Datalog [5] engine, but ended up going with the Prolog engine
since Datalog is a Prolog subset.
@wernsey
wernsey / quine.c
Created July 26, 2016 18:48
My first (only) attempt at a quine, in C
/*
* This is the annotated version of my first attempt at a Quine
*
* I wonder if it is still considered a quine if it is annotated? :)
* You'll find that if you compile and run this, the output is equivalent
* to this code, so I'm still calling it a quine.
*
* Anyway, if you don't know what a Quine is, enlighten yourself at
* the wikipedia: http://en.wikipedia.org/wiki/Quine_(computing)
*/
@wernsey
wernsey / ms3d.c
Created December 30, 2017 12:07
Milkshape 3D model loading in C
/*
http://paulbourke.net/dataformats/ms3d/ms3dspec.h
http://www.chumba.ch/chumbalum-soft/files/ms3dsdk184.zip
http://sappersblog.blogspot.co.za/2014/08/milkshape-3d-185-ms3d-file-format.html
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
@wernsey
wernsey / validate SA ID.java
Last active April 17, 2019 12:35
Validates a South African ID number
/**
* Validates a South African ID number
*
* See http://geekswithblogs.net/willemf/archive/2005/10/30/58561.aspx and
* https://www.westerncape.gov.za/general-publication/decoding-your-south-african-id-number-0
*
* @param id
* @return
*/
@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>
@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 / 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 / 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 / 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 / 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