Skip to content

Instantly share code, notes, and snippets.

View StoneCypher's full-sized avatar

John Haugeland StoneCypher

View GitHub Profile
@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 / repeater.html
Created April 16, 2014 18:44
React repeater control housing HTML (js impl at https://gist.github.com/StoneCypher/10919150 )
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="build/react.js"></script>
<script src="build/JSXTransformer.js"></script>
<script type="text/jsx" src="repeater.jsx"></script>
</head>
<body></body>
</html>
@StoneCypher
StoneCypher / repeater.jsx
Created April 16, 2014 18:44
This is how a React repeater control is made (housing html at https://gist.github.com/StoneCypher/10919111 )
/** @jsx React.DOM */
'use strict';
var RepeaterRow = React.createClass({
render: function() {
return <div>Repeater Row {this.props['data-ex']}</div>;
}
@StoneCypher
StoneCypher / gist:11097913
Created April 19, 2014 21:23
general structure of receive
receive
case ->
handler;
case ->
handler;
case ->
handler
@StoneCypher
StoneCypher / gist:11097999
Last active August 29, 2015 14:00
general structure of a receive driven process
some_loop() ->
receive
case ->
handle,
some_loop();
case ->
handle,
@StoneCypher
StoneCypher / gist:11187594
Created April 22, 2014 17:25
found this cleaning up editor windows, huhu
chunk(List) ->
part(List, []).
chunk([], Acc) ->
lists:reverse(Acc);
chunk([H], Acc) ->
@StoneCypher
StoneCypher / gist:11362556
Created April 28, 2014 05:37
san francisco box old version text

Unexpected San Francisco Box!

Welcome to your very own Unexpected San Francisco Box ™. This is something your idiot engineer friend made up. Sharing culture with deep PA. Play along.

Contents

  • Four CA local cheeses
@StoneCypher
StoneCypher / chicken.js
Last active August 29, 2015 14:00
I STOLED THIS CODE lul
/* code blatantly stolen from @asterick */
(function chicken() {
function textNodesUnder(el, transform){
var n, a = [], walk = document.createTreeWalker(el,NodeFilter.SHOW_TEXT,null,false);
while (n=walk.nextNode()) { transform(n); }
}
textNodesUnder(document.body, function (el) {