Skip to content

Instantly share code, notes, and snippets.

@jcmoore
jcmoore / gist:235f12fe03ec32ed053c90658cb796aa
Created April 30, 2016 22:03
Weakling.js -- abstraction around iterable "WeakMap"s and weak event handling
var Weakling = function iife () {
function weakenRef(ref) {
if (ref instanceof Object) return ref; // replace with real weak-ref support when available
else throw new TypeError("Object expected"); // https://github.com/TooTallNate/node-weak
}
function strengthenRef(ref, sentinal) {
if (ref instanceof Object) return ref; // replace with real weak-ref support when available
@jcmoore
jcmoore / stuntdouble-event.js
Last active November 24, 2015 08:31
stuntdouble.js: standing in for the DOM because the web is full of peril
var sx2Event = (function iife_module () {
// API.sx2 == {} || null
// API.eventDefinitions == {}
// API.uuid == function () { return ""; }
// API.uniqueKeyForValue == function (value, release) { return ""; }
@jcmoore
jcmoore / tube.js
Last active November 21, 2015 15:16
tube.js
// node --harmony --trace_opt --trace_deopt --allow-natives-syntax --trace-inlining tube.js
function crankShaft (method) {
return %OptimizeFunctionOnNextCall(method);
}
function printStatus(fn) {
switch(%GetOptimizationStatus(fn)) {
case 1: console.log("Function is optimized"); break;
@jcmoore
jcmoore / bx.js
Last active November 9, 2015 10:44
bx.js: a javascript native DSL for working with observable data trees
var bx = (function () {
function Box (tree, path, upper, lower, delta) {
this._tree = null;
this._tree = tree;
this._path = null;
this._path = path;
this._upper = null;
this._upper = upper;
/*
Copyright (c) jQuery Foundation, Inc. and Contributors, All Rights Reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
<link rel="import" href="../polymer/polymer.html">
<dom-module id="bower-2">
<template>
<div>This is bower-2</div>
</template>
<script>
HTMLImports.whenReady(function() {
Polymer({
is: "bower-2",
<link rel="import" href="../polymer/polymer.html">
<dom-module id="bower-1">
<template>
<span>This is bower-1</span>
</template>
<script>
HTMLImports.whenReady(function() {
Polymer({
is: "bower-1",
top tier
@jcmoore
jcmoore / index.html
Last active August 29, 2015 14:27
polymer binding problem
<html>
<head>
<script src="https://rawgit.com/webcomponents/webcomponentsjs/master/webcomponents.js"></script>
<link rel="import" href="https://rawgit.com/Polymer/polymer/master/polymer.html">
</head>
<body>
<dom-module id="x-model">
<template>
<span>(</span><span>{{id}}</span><span>)</span>
@jcmoore
jcmoore / main.go
Last active August 29, 2015 14:26
typeof: a go tool
package main
import (
"fmt"
"os"
"go/ast"
"go/token"
"log"
"strings"