Skip to content

Instantly share code, notes, and snippets.

View benchristel's full-sized avatar

Ben Christel benchristel

View GitHub Profile
@benchristel
benchristel / README.txt
Created August 6, 2017 23:50
Basic English LSTM
This is a language model for http://cs.stanford.edu/people/karpathy/recurrentjs/
It is trained on the Basic English word list from https://simple.wikipedia.org/wiki/Wikipedia:Basic_English_alphabetical_wordlist
var currentApp
function main(event, records) {
if (currentApp) {
return currentApp(event, records)
}
if (event.type === 'startup') {
return 'Press A or B'
}
@benchristel
benchristel / index.foo
Last active July 9, 2017 19:39
Programming language design
-- a comment begins with two dashes
-- and ends at the end of the line.
-- variable declarations use the `let` keyword
let number_of_bikes 1
-- functions start with a colon,
-- followed by an argument
-- and the function body.
for (var i = 0; i < 20; i++) {
console.log(generateName())
}
function generateName() {
var v = Bag('aeio')
var c = Bag('rtysdfgklzxvbnm')
return c.draw()
+ v.draw()
+ c.draw()
@benchristel
benchristel / README.md
Created July 2, 2017 21:13
Validator spec

TODO: Possibly rename to Vladiator? (an anagram of Validator)

Validity

Validity is a JavaScript library for validating the conformance of complex objects to schemas. It's intended to be used in functional-programming-like environments where all of your program's state is wrapped up in one big immutable value object.

Validity comes with a rich suite of validator functions, but

@benchristel
benchristel / objects.js
Last active October 1, 2017 00:04
Functional object traversal
// Test-driven with Ji (benchristel.github.io/ji)
/**
* This file provides APIs for "updating" immutable objects by creating a copy.
* The apply() function traverses an object and updates the value at a given path
* by the given function.
*/
// tests go here
// hint: open the javascript console for better failure messages
@benchristel
benchristel / fiddle.js
Created May 3, 2017 14:51
DOM rendering perf test
var body = document.getElementById('container')
var lastFrame = +new Date()
function test2() {
var nParagraphs = 320
for (var j = 0; j < nParagraphs; j++) {
body.appendChild(document.createElement('p'))
}
var paragraphs = document.querySelectorAll('p')
@benchristel
benchristel / framework-speculation.js
Created April 16, 2017 22:54
A demo app for an imaginary frontend framework
/* Apps are divided into "screens". A typical game might have
* a splash screen, a menu screen, and a loading screen, plus any number
* of screens for the gameplay itself.
*
* Concretely, screens are functions that reconfigure the `state` object
* with event handlers and view renderers that define the behavior and
* appearance of that screen.
*
* Here is a definition of a basic splash screen that counts down 5 seconds
@benchristel
benchristel / stack-demo.js
Created March 22, 2017 15:12
get stacktrace from eval in the browser
// Tested in Chrome and Firefox.
// Note that each browser has its own format for the stack, which is kind of annoying but not insurmountable.
var e
function kaboom() {
eval('function inEval() {\ntry {\nthrow new Error("foo")\n} catch(_e) {\ne = _e\n}\n}\n inEval()')
}
kaboom()
@benchristel
benchristel / functional-stuff.js
Created February 5, 2017 16:34
Functional stuff (pipeline, autocurry)
// test-driven with Ji (benchristel.github.com/ji)
// tests go here
// hint: open the javascript console for better failure messages
expect(start(1).done, eq, 1)
expect(start(2).done, eq, 2)
expect(
start(2)