Skip to content

Instantly share code, notes, and snippets.

View artisonian's full-sized avatar

Leroy Campbell artisonian

View GitHub Profile
@artisonian
artisonian / async-iterator.js
Last active March 1, 2019 00:08
Async Iterator Example
main().catch(console.error);
async function main() {
const clicks = streamify(document, "click");
let clickCount = 0;
for await (const event of clicks) {
console.log("click", event, clickCount);
if (clickCount++ > 2) {
clicks.return();
}
main().catch(console.error);
async function main() {
const clicks = streamify(document, "click");
let clickCount = 0;
for await (const event of clicks) {
console.log("click", event, clickCount);
if (clickCount++ > 2) {
clicks.return();
}
#lang racket
(module+ test
(require rackunit))
(define state-machine
'((init (c more))
(more (a more)
(d more)
(r end))
export default function trampoline (fn) {
return (...args) => {
let result = fn(...args);
while (result instanceof Function) {
result = result();
}
return result;
};
}
@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 / example.js
Last active January 7, 2016 03:36
Hash it, then compress it!
'use strict';
var hashpress = require('./hashpress');
var obj = {
username: 'foo',
likes: ['cats', 'candy'],
quote: "I don't always program JavaScript...but when I do, I use Node.js"
};