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 / doc.awk
Last active July 18, 2023 12:29
An Awk script to generate HTML documentation from source code with /* */ style comments
BEGIN {
if(!title) title = "Documentation"
print "<!DOCTYPE html>\n<html>\n<head>\n<title>" title "</title>";
print "<style><!--";
print "body {font-family:Arial, Verdana, Helvetica, sans-serif;margin-left:20px;margin-right:20px;}";
print "h1 {color:#575c91;border:none;padding:5px;}";
print "h2 {color:#575c91;border:none;padding:5px;}";
print "h3 {color:#9191c1;border:none;padding:5px;}";
print "a{padding:2px;border-radius:2px;}";
print "a:link {color: #575c91;}";
@wernsey
wernsey / JDatalog.java
Last active May 15, 2024 19:22
Java Datalog Engine and Interpreter
/*
Java Datalog Engine with Stratified Negation
Copyright 2016 Werner Stoop
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
@wernsey
wernsey / comdown.awk
Last active January 13, 2022 09:02
Awk script to generate HTML documentation from markdown text in source code comments.
#! /usr/bin/awk -f
#
# Purpose: Either converts markdown in code comments
# to HTML, or is a poem about Hastur. I forget.
#
# The comments must have the /** */ pattern. Every line in the comment
# must start with a *. Like so:
#
# /**
# * Markdown here...
@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 / xdmp.c
Last active June 11, 2022 17:26
A small program to dump the contents of a binary file in hex or to a C header
/*
* $ gcc -o xdmp.exe xdmp.c
*/
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <unistd.h>
unsigned char *read_file(const char *fname, size_t *plen) {
FILE *f;
@wernsey
wernsey / bsbingo.html
Created July 26, 2016 18:51
A buzzword bingo game in HTML
<!--
Author: Werner Stoop, 2012
This is free and unencumbered software released into the public domain.
http://unlicense.org/
-->
<html>
<head>
<title>Buzzword Bingo 2.0</title>
<style>
@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 / wav.c
Last active June 11, 2022 13:39
C code for manipulating WAV files
/*
gcc -Wall -DWAV_TEST wav.c
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <errno.h>
#include "wav.h"
@wernsey
wernsey / ad-b-gone.js
Last active August 27, 2023 03:15
Ad-B-Gone: Bookmarklet that removes obnoxious ads from pages
javascript:(function(){
/* Ad-B-Gone: Bookmarklet that removes obnoxious ads from pages */
var selectors = [
/* By ID: */
'#sidebar-wrap', '#advert', '#xrail', '#middle-article-advert-container',
'#sponsored-recommendations', '#around-the-web', '#sponsored-recommendations',
'#taboola-content', '#taboola-below-taboola-native-thumbnails', '#inarticle_wrapper_div',
'#rc-row-container', '#ads', '#at-share-dock', '#at4-share', '#at4-follow', '#right-ads-rail',
'div#ad-interstitial', 'div#advert-article', 'div#ac-lre-player-ph',
/* By Class: */