Skip to content

Instantly share code, notes, and snippets.

function compile(o, cx) {
// initial evaluation context inherits from external cx or configuration object
cx = new Context(cx);
// track initial evaluation context in quotation scope
const quots = [cx];
// this is a reduction into a single result (a callable context)
return o.reduce((cx, node) => {
const type = node.type;
if (isClose(type)) {
// handle node close:
// when applied, this function should check each of the items in s against the input arguments,
// and the result to r
// when the original is applied, this will simply return the input if valid, or throw if invalid
// for higher-order functions
// the function is not yet evaluated, but we pass a validator and wrap the function
// this will be inspected when provided function is called
const func = (s,r) => fn => {
const f = (...args) => {
const ret = fn(...args.map((a,i) => {
@wshager
wshager / tree-walker-x.js
Created April 19, 2018 11:13
TreeWalkerX
const t = document.createTreeWalker(document.body);
const closers = new WeakMap();
const emit = (type,n) => {
console.log(type,n);
};
const isBranch = n => n.nodeType == 1 || n.nodeType == 9 || n.nodeType == 10 || n.nodeType == 11;
const close = n => {
emit("close",n);
if(closers.has(n)) {
const parent = closers.get(n);
function reduceAhead(arr,fn,seed,nextSeed) {
const l = arguments.length;
seed = l < 3 ? arr.shift() : seed;
let tmp = {
out:seed,
entry:arr.shift(),
at: l < 3 ? 1 : 0
};
tmp = arr.reduce(function(tmp,next){
tmp.out = fn.call(arr,tmp.out,tmp.entry,next,tmp.at,arr);
@wshager
wshager / ups.js
Last active March 30, 2017 14:53
"use strict";
var ffi = require('ffi');
var ref = require('ref');
var Struct = require('ref-struct');
var util = require("util");
var ups_status_t = ref.types.int;
var ups_env_t = Struct();
var ups_db_t = Struct();
var input = document.createElement("input");
input.id = "path";
input.value = "/db/file.xml";
var eXideButton = document.createElement("button");
eXideButton.innerHTML = "Open in eXide";
eXideButton.title = "Open in eXide Code Editor";
eXideButton.addEventListener("click", function() {
var path = input.value;
window.eXide_onload = function(app){
// getEditor() needs patch eXide.js
.box {
position: relative;
width: 300px;
height: 200px;
border: 1px solid #cfcfcf;
background: #fafafa;
margin: 50px 5px;
float: left;
}
@wshager
wshager / settings.json
Created April 26, 2013 15:26
Untitled
{"view":"split","fontsize":"100","seethrough":"","prefixfree":"1","page":"css"}
@wshager
wshager / mysql-native-utf8-test.js
Created March 2, 2012 09:52
basic test for utf8 chars in mysql-native using execute
// adapted from https://github.com/persvr/perstore/blob/master/engines/node/store-engine/sql.js
function MysqlWrapper(params) {
var currentConnection;
return {
executeSql: function(query, args, callback, errback) {
var conn = currentConnection;
if(!conn) {
errback(new Error("No transactional context has been created"));
return;
}