Skip to content

Instantly share code, notes, and snippets.

View JohnEarnest's full-sized avatar

John Earnest JohnEarnest

View GitHub Profile
/ the infamous iris dataset
cols:`sepalLength`sepalWidth`petalLength`petalWidth`species
iris:((5.1; 3.5; 1.4; 0.2; `setosa)
(4.9; 3.0; 1.4; 0.2; `setosa)
(4.7; 3.2; 1.3; 0.2; `setosa)
(4.6; 3.1; 1.5; 0.2; `setosa)
(5.0; 3.6; 1.4; 0.2; `setosa)
(5.4; 3.9; 1.7; 0.4; `setosa)
(4.6; 3.4; 1.4; 0.3; `setosa)
@JohnEarnest
JohnEarnest / prog.k
Last active March 24, 2020 17:04
Sandpile Cellular Automaton
/ Sandpiles
/ see: https://www.youtube.com/watch?v=hBdJB-BzudU&t=0s
r: {y(#y)!x+!#y} / rotate y by x places
n: {+/(-1 1r\:x),(-1 1r/:\:x)} / orthogonal neighbor counts
t: {x+(-4*u)+1_+1_n@+0,+0,u:3<x} / toroidal sand collapsing
once: 100 100# 5 / initial board
tick: t / update: just collapse one iteration
draw: {,(;solarized;x)} / draw board as paletted pixels
@JohnEarnest
JohnEarnest / setup.sh
Created February 5, 2020 16:10
OLPC Setup Script
#!/bin/bash
# OLPC setup script
# First, make sure your OS is updated to the latest version:
# http://wiki.laptop.org/go/Release_notes/13.2.11#Installation
# Then ensure you have a WiFi connection.
# fix clock (modify time zone as desired)
sudo ntpdate pool.ntp.org
sudo hwclock --systohc
@JohnEarnest
JohnEarnest / lisparse.js
Created December 13, 2019 21:40
A Lisp(ish) S-Expression parser in ES6, supporting symbols, signed ints, lists, and line comments.
// S-Expression Parser
const token = /^\s*(?:;[^\n]*\n)*\s*(?:(-?\d+)|([a-z\-!?]+|[+\-*\/<>=()]))/
function parse(text) {
const term = _ => {
const x = token.exec(text)
if (!x) throw 'Reached the end of input while parsing!'
text = text.slice(x[0].length)
const here = x[1] ? +x[1] : x[2]
@JohnEarnest
JohnEarnest / eventproposal.md
Created October 31, 2019 01:56
XO-Chip Event Queue Proposal

Input Events

The COSMAC VIP had a 16-key hexadecimal keypad, and while modern computers rarely have a keyboard which directly mimics this arrangement, there are many approaches for adapting the input devices which are available to render Chip8 games playable. Many emulators offer custom keyboard or gamepad mappings for each program, and recently Octo has begun to offer "Adaptive Input" options to allow touch-based devices to play games.

It is often desirable to more directly expose the input capabilities of modern machines. This proposal outlines a pair of new instructions for XO-Chip which would expand it with text and pointer input, with room for future expansion. The instructions are as follows:

8NN8 #  v0 := poll NN
8XY9 #  event vx - vy

As input events occur, the XO-Chip interpreter will store them in a FIFO queue. The poll instruction pops events from this queue, storing the type code of the event in the fixed register v0. A type code of zero indicates that no events are currently

@JohnEarnest
JohnEarnest / bam.py
Created June 9, 2019 20:31
Minimal RSS podcast fetcher
#!/usr/bin/python
# A script for fetching the latest episode of
# the podcast "My Brother, My Brother and Me" automagically
# every podcast hosts the XML RSS feed somewhere different,
# but feedburner appears to be a fairly popular aggregator.
# unfortunately, there's no way to just fetch the most N recent entries;
# for long-running podcasts the rss blob can get big.
print 'fetching rss feed...'
@JohnEarnest
JohnEarnest / peg.js
Created March 31, 2017 03:05
A compact set of PEG parser combinators in ES6.
// PEG parser combinators
const lookup = x => typeof x == 'string' ? eval(x) : x
const match = (x, y, z) => x ? { c:y, v:z } : { e: true }
const eof = s => match(s.length, 0, '')
const char = s => match(s.length, 1, s[0])
const not = g => s => match(g(s).e, 0, '')
const has = g => s => match(!g(s).e, 0, '')
const oneof = t => s => match(t.indexOf(s[0]) >= 0, 1, s[0])
const lit = t => s => match(!s.indexOf(t), t.length, t)
const option = g => choose(g, lit(''))
@JohnEarnest
JohnEarnest / CorsServer.js
Created December 27, 2016 17:47
A CORS-aware read/write HTTP server in Node.js
////////////////////////////////////////////////////////////////////////////
//
// Node.js HTTP file server example.
//
// Serves documents via GET requests with CORS headers and (if enabled)
// additionally permits writes via POST requests.
//
// Before using, PLEASE be aware of the security risks associated with
// running a server like this on publicly accessible machines!
//
@JohnEarnest
JohnEarnest / WAD3.java
Created January 6, 2016 03:28
Quake WAD3 texture unpacker
import java.io.*;
import java.util.*;
import java.awt.image.*;
import javax.imageio.*;
// a very basic texture unpacker for the Quake WAD3 file format
// see http://hlbsp.sourceforge.net/index.php?content=waddef
public class WAD3 {
static int index = 0;
@JohnEarnest
JohnEarnest / HexScape.java
Created February 22, 2014 02:40
Playing with hexagons.
import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;
import java.util.*;
import java.util.List;
import static java.lang.Math.*;
public class HexScape extends JPanel {
public static void main(String[] args) {