Skip to content

Instantly share code, notes, and snippets.

@spocke
spocke / adt.ts
Created August 2, 2019 06:26
adt.ts
// -------------------- Experiment A
// Adt module
interface Matcher<A> {
match<T>(a: { [P in keyof A]: (...x: any[]) => T }): T; // Can't put a constraint on arguments of x
fold<T>(...x: Array<(...x: any[]) => T>): T // Can't put a constraint on the arguments
}
const Adt: any = {
@spocke
spocke / tree.md
Created December 4, 2017 10:58
TinyMCE tree structure

TinyMCE tree structure

The tinymce tree structure is a linked rose tree where each node has a reference to it's possible siblings and parents. It has also a few mutation methods that can be used to alter the structure in place. It's very similar to the browsers dom structure except that it doesn't have a children NodeList and it's completely virtual in that it doesn't rely on the dom in any way.

Node interface

Properties

 type: Number                                     // Node type 1=element, 3=text ...
@spocke
spocke / FreeDom.purs
Last active January 19, 2018 09:23
Free monads dom experiment
module FreeDom where
import Control.Monad.Free
import Control.Monad.Free.Trans
import DOM
import DOM.HTML
import DOM.HTML.Window
import DOM.Node.Node
import DOM.Node.Types
import Data.Array
@spocke
spocke / gist:1217517
Created September 14, 2011 19:24
Small and fast template engine
(function(namespace) {
function template(template) {
var index = 0, depth = 0, source = "var o = '', e = encode;", matches, token, value, tokenRe = /{(\/)?(if|each|\$+|%+)\s*(?:([^}]+)|)?\}/g;
template = template.replace(/'/g, "\\'");
while (matches = tokenRe.exec(template)) {
if (index < matches.index) {
source += "o += '" + template.substr(index, matches.index - index) + "';";
}