Skip to content

Instantly share code, notes, and snippets.

View artisonian's full-sized avatar

Leroy Campbell artisonian

View GitHub Profile
export default function trampoline (fn) {
return (...args) => {
let result = fn(...args);
while (result instanceof Function) {
result = result();
}
return result;
};
}
@artisonian
artisonian / Manifest.elm
Created December 3, 2016 03:44
JSON decoding example in Elm
module Manifest exposing (..) -- remove this line to run in http://elm-lang.org/try
import Html exposing (Html, node, div, h2, text, table, thead, tbody, tr, th, td)
import Html.Attributes exposing (class)
import Json.Decode as Json exposing (Decoder)
main : Html msg
main =
@artisonian
artisonian / ZipList.elm
Last active October 13, 2017 12:48
A simple list zipper data structure for maintaining a selection in a list of values
module ZipList exposing
( ZipList
, init, singleton
, toList, toSelectionList
, get, forward, back
, select
)
type ZipList a =
@artisonian
artisonian / index.js
Created July 27, 2016 19:22
requirebin sketch
// Welcome! require() some modules from npm (like you were using browserify)
// and then hit Run Code to run your code on the right side.
// Modules get downloaded from browserify-cdn and bundled in your browser.
var escape = require('escape-string-regexp');
var expr = '^https?://(www.)?example.com';
var input = 'http://example.com';
log(['w/o escape', expr, (new RegExp(expr, 'i')).test(input)]);
log(['w/ escape', escape(expr), (new RegExp(escape(expr), 'i')).test(input)]);
@artisonian
artisonian / Main.elm
Last active July 18, 2016 21:39 — forked from zkessin/command.js
port module Main exposing (..)
import Html exposing (..)
import Html.App as App
import Html.Attributes exposing (class)
main =
App.program
@artisonian
artisonian / stuck_on_decoders.elm
Last active July 8, 2016 21:43 — forked from AWaselnuk/stuck_on_decoders.elm
I don't understand custom event handlers and decoders in Elm
import Html exposing (..)
import Html.App as App
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import Json.Decode as Json
import String
main =
App.beginnerProgram
@artisonian
artisonian / Main.elm
Created May 27, 2016 00:26
Responding to change events in Elm 0.17
import Dict exposing (Dict)
import Html exposing (..)
import Html.App as App
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import Json.Decode as Json
main =
App.beginnerProgram
@artisonian
artisonian / Debounce.elm
Created October 31, 2015 20:28
Delay the value of a signal for a specified period of time
-- Maybe this should use a `foldp`?
import Graphics.Element exposing (..)
import Mouse
import Time
debounce : Time.Time -> a -> Signal a -> Signal a
debounce after initialValue signal =
let
@artisonian
artisonian / self-ref-funcs.md
Last active September 4, 2015 01:08
Self-Referential Functions

Self-referential functions in JavaScript

Rob Pike describes a way of encoding options using functions. Let's see if we can do something similar in JavaScript.

NOTE: To execute this document as code, try erudite.

We'll need a "Foo" type to follow along with the blog post. We'll use a constructor: