Skip to content

Instantly share code, notes, and snippets.

View benchristel's full-sized avatar

Ben Christel benchristel

  • Khan Academy
  • Palo Alto, CA
View GitHub Profile
@benchristel
benchristel / internet-the-good-parts.md
Created August 25, 2016 03:46
Embryonic blog post about the internet

Internet: The Bad Parts

  • security
    • people don't understand security / crypto
    • engineers don't even understand crypto
    • even the people who dedicate their lives to crypto make mistakes
    • no matter how good the technical solution is, humans will still choose "password" as their password.
  • time is local
    • my system clock time is not the same as yours
  • it never will be
@benchristel
benchristel / diy-elm-architecture.html
Created September 10, 2016 18:21
An example of how to adapt the Elm architecture to vanilla JS
<!DOCTYPE html>
<html>
<head>
<title>Working Title</title>
<style type="text/css">
body {
margin: 0;
padding: 10px;
background-color: black;
color: goldenrod;
@benchristel
benchristel / boot.js
Created September 18, 2016 17:10
Trivial boot.js
alert('boot.js is running!')
@benchristel
benchristel / Test.elm
Created December 24, 2016 16:30
Simple test framework in Elm
module Test exposing
( should
, shouldNot
, be
, passed
, test
, Test
, TestResult(..)
, viewTestResults
)
@benchristel
benchristel / post.md
Last active July 9, 2023 10:26
How to write a while loop in a functional language

How to write a while loop in a functional language

The official version of this post is on my blog!

I've been on an Elm kick recently. I'm trying to learn the language by writing a multiplayer Go game, which, in retrospect, might have been slightly too ambitious. Ah, well.

Learning a functional language is a mind-bending experience if you're used to imperative code. Functional languages have no loops, because changing values is verboten—instead of assigning a new value to a local variable you have to make a recursive call and pass the new value as an argument. In exchange for putting up with such restrictions, functional programs gain a wonderful property, called referential transparency, which can make them easier to reason about and test than equivalent imperative programs. However, my brain is still a citizen of imperative-land, and so when thinking about algorithms for my Go

@benchristel
benchristel / hello.c
Last active January 7, 2017 01:59
Unit tests in C
#include <stdio.h>
#include "hello.h"
#include "log.h"
void hello() {
for (int i = 0; i < 10; i++) {
log_printf("Hello, world!\n");
}
}
@benchristel
benchristel / words.txt
Created January 30, 2017 06:30
Some words that exist, and some that don't
& 1 1/20 100% a able about acconce accountract accounts ace active acts ad advantage age agnostic alterals alterica alternatives america americal ameritation amount amounts and anonymous any aphy aplay appears are around as assume at authentication authorance bacebost back balism bantage be been before beforgan behave behavior beyond bites bot both bots boys buffer bufferica build but call cancer cantionistic cascular cascurity cash cassile cassion cassive cast casty catholic chimeaday chimed chistion claim claiming claimonial clay clim climate come commanal commanalisting command commendative community conceding concertunement cons conservative correct could country coward cryptography cryptosanding cryptosaurity cryptosaurus day de-employ decent deening deflecting degree desile desired destic digit digital dignity discur discurity discussed discussions dism disquotic disqus do down easyvpn ecover effect either emails emploma emplomanic employ employing erassive ersonian especially especord etc eveldic even
// This code was test-driven with Ji (benchristel.github.io/ji)
// tests
function equal(a, b) {
expect(equals(a, b), eq, true)
}
function notEqual(a, b) {
expect(equals(a, b), eq, false)
@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)
@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()