Skip to content

Instantly share code, notes, and snippets.

View Johnicholas's full-sized avatar
💭
I may be slow to respond.

Johnicholas Hines Johnicholas

💭
I may be slow to respond.
View GitHub Profile
@Johnicholas
Johnicholas / styling_architecture.js
Created February 25, 2012 17:57
Idea regarding styling architecture like CSS
// This is an example of a possible large-scale design idiom.
// (Basically the idea is to imitate cascading stylesheets).
//
// It's hard to give a small, comprehensible example of an
// idea intended to be useful at (medium to) large scale.
// No matter what you do, it's definitely overengineered.
// Sigh.
//
// Often, at the top of an app, or a big component,
// there is a wiring-things-together entity; it might be
@Johnicholas
Johnicholas / shift-reset.soar
Created April 7, 2012 19:08
Delimited Continuations in Lambda Calculus in Soar
# This is a lambda-calculus interpreter with shift and reset,
# an implementation of BRICS-RS-3-41 "An Operational Foundation for Delimited Continuations",
# by Biernacka, Biernacki, and Danvy.
#
# Mistakes, misunderstandings and terrible un-idiomatic Soar style by Johnicholas
#
#
# This is the grammar:
#
# A term can have a single outgoing ^reset leading to a reset.
@Johnicholas
Johnicholas / validity_one.cpp
Created May 25, 2012 16:38
Cleanest C++ code I've ever written is still verbose and ugly
// Based on validity.py which is copyright (c) Feb 2000, by Denys
// Duchier, Universitaet des Saarlandes
//
// Transliterated (badly) from Python to C++ by Johnicholas Hines,
// but with the two-continuation model changed to the one-continuation model.
// (The failure continuation is the C++ stack.)
#include <string>
#include <tr1/memory>
using std::tr1::shared_ptr;
@Johnicholas
Johnicholas / doran_parberry.lua
Created October 8, 2014 00:13
Transliteration perl->lua of thgie's implementation of Doran and Parberry's procedural quest system
-- procedural quest generation
math.randomseed(os.time())
local DEPTH = 3
actions = {
goto = {
{ description = 'Just wander around and look',
sequence = { '>explore' }
},
@Johnicholas
Johnicholas / mark_and_recapture.js
Created April 13, 2015 12:38
mark and recapture for generative text
// This is using the "Bayesian" formula taken from
// http://en.wikipedia.org/wiki/Mark_and_recapture
// to provide a crude estimate of "how many" outputs the grammar might generate.
//
// As I understand it, it is quite easy to technically have infinite outputs,
// and this technique "wrongly" will always give a finite answer.
// However, informally, we want a lot of visible variety,
// and technically-infinite doesn't provide guidance towards
// more visible variety, but abundance will.
//
// a hub world corresponds to a partial order on levels
//
// an example play sequence is:
// 1. the player starts in the hub world,
// - which several open (or unlocked) doors and several closed (or locked) doors
// 2. the player chooses an open door, and plays through a level, and fails
// 3. the player is returned to the hub world
// 4. the player chooses the same open door, plays through the same level, and succeeds
// 5. the player is returned to the hub world, but there is a change:
<?php
// a is not optional, b is optional, c is optional
function foo($a, $b = "b", $c = "c")
{
// does something complicated
}
// I want to call foo with a set to "x", b set to default, and c set to "y", but foo("x", "y") isn't the right syntax.
// so I wrap foo, like this:
function bar($a, $c = "c")
{
#lang racket
(require rackunit
"prover.rkt")
(check-equal? (resolve '(or P) '(or Q)) 'no-resolvent)
(check-equal? (resolve '(or P) '(or (not P))) '(or))
(check-equal? (resolve '(or P (not Q)) '(or Q (not R))) '(or P (not R)))
(test-case
def helper(a):
if len(a) == 0
# base case
return 0, 0
else:
# recursive case
best_prefix_total, best_span_total = helper(a[1:])
# TODO
return foo, bar
@Johnicholas
Johnicholas / index.js
Created August 5, 2017 18:52
Example of simple AI
// utility functions
function dist(a, b) {
let dx = a.x - b.x;
let dy = a.y - b.y;
return Math.sqrt(dx * dx + dy * dy);
}
// GLOBALS GLOBALS GLOBALS
var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");