Skip to content

Instantly share code, notes, and snippets.

View StoneCypher's full-sized avatar

John Haugeland StoneCypher

View GitHub Profile
-module(dumb_math).
-export([
square/1
]).
-module(dumb_math_tests).
-compile(export_all).
-include_lib("eunit/include/eunit.hrl").
square_test_() ->
{ "Square tests", [
-module(dumb_math).
-export([
square/1
]).
-module(dumb_math_tests).
-compile(export_all).
-include_lib("proper/include/proper.hrl").
-include_lib("eunit/include/eunit.hrl").
prop_square_never_negative() ->
@StoneCypher
StoneCypher / gist:9015456
Created February 15, 2014 06:45
Explanation of how to count words in PHP (MIT License)
<html><body>
<?php
// normally i'd write this more densely, but you said you wanted some exposure
// so i'm writing it in single concepts per line and annotating it for reference :)
// config
@StoneCypher
StoneCypher / Eng10Trie.js
Created February 15, 2014 09:10
A trie of English words from ten sources. MIT license.
var Eng10Trie = '0:4JH
1:4JM
2:4JO
3:4H5
4:498
5:4IP
6:4J1
7:4J6
8:4HN
9:4HU
@StoneCypher
StoneCypher / levenshtein.js
Created February 15, 2014 09:22
Javascript Levenshtein
function levenshtein (s, t) {
if (!s.length) { return t.length; }
if (!t.length) { return s.length; }
return Math.min(
levenshtein(s.substr(1), t) + 1,
levenshtein(t.substr(1), s) + 1,
levenshtein(s.substr(1), t.substr(1)) + (s[0] !== t[0] ? 1 : 0)
);
@StoneCypher
StoneCypher / reporters.thanks
Last active August 29, 2015 13:56
Example DSL for error reporting
// spaces/tabs separate unless preceded with a comma, which makes list members, or surrounded by '', which makes js string notation
// first is operator; after that are expected-length varargs like irc
// 2nd argument to thanks is list of front of string matches for things raised by keyword report
upstring( [], Accumulator ) ->
lists:reverse(Accumulator);
upstring( [Letter | StringRemainder], Accumulator) ->
@StoneCypher
StoneCypher / gist:11097913
Created April 19, 2014 21:23
general structure of receive
receive
case ->
handler;
case ->
handler;
case ->
handler