Skip to content

Instantly share code, notes, and snippets.

@dead-claudia
dead-claudia / dom-n.js
Created February 22, 2016 03:30
VDOM-like DOM tree construction
function n(type, attrs, children) {
var elem = document.createElement(type)
for (var attr in attrs) {
if ({}.hasOwnProperty.call(attrs, attr)) {
elem[attr] = attrs[attr]
}
}
(function append(e) {
@dead-claudia
dead-claudia / my-deprecate.js
Created April 3, 2016 21:40
Comparison of @silkentrance's vs my proposal featuring some of core-decorators
const DEFAULT_MESSAGE = 'This function will be removed in future versions.'
deprecate[Symbol.decoratorCall] = deprecate
export default function deprecate(message = DEFAULT_MESSAGE, options = {}) {
if (options.url) message += `\n\n See ${options.url} for more details.\n\n`
return (target, prop, descriptor) => {
if (typeof descriptor.value !== 'function') {
throw new SyntaxError('Only functions can be marked as deprecated')
}
@dead-claudia
dead-claudia / check-path-optimized.js
Last active April 29, 2016 19:17
Path list to tree for easy lookup.
// Add and check that a path exists in a tree.
//
// Notes:
// 1. The comparison algorithms assume the paths are already resolved.
// 2. `matchEnd` is a sentinel to mark a leaf end of the cache tree.
// 3. Windows drive letters are intentionally included in the cache.
const path = require("path")
const hasOwn = Object.prototype.hasOwnProperty
@dead-claudia
dead-claudia / mithril-ctrl-compat.js
Created June 30, 2016 05:24
Make Mithril 0.2.x controllers not require `new` (for ES6 support).
/* This is licensed under CC0. */
/**
* Notes:
* 1. This is fully ES3 compatible and works with the ES5 sham, but it leverages
* ES6's `WeakMap` or `Map` where possible.
* 2. This proxies `m`'s properties to Mithril's constructor where possible (in
* modern browsers, it always does). If you use the ES5 shams of
* `Object.defineProperty`, `Object.getOwnPropertyNames`, or
* `Object.getOwnPropertyDescriptor`, it should still properly proxy changes
@dead-claudia
dead-claudia / algorithm.cpp
Last active June 30, 2016 11:36
Tree algorithm for finding sum
// Given a list of M integers, find those whose sum is N
#include <list>
#include <string>
#include <iostream>
#include <cassert> // assert
// This could be anything, and this is the expected sum
#define EXPECTED 72
// This is the general "run things" function. It scales to any number of
@dead-claudia
dead-claudia / composition-proposal.md
Last active June 2, 2017 17:36
Function Composition Strawman
npm-debug.log
node_modules
@dead-claudia
dead-claudia / tap-ee-reporter.js
Last active October 30, 2016 06:28
The TAP reporter example from Thallium, if the API accepted an event emitter or an event handler class. It's here together with the original example.
"use strict"
// This is a basic TAP-generating reporter.
const tty = require("tty")
const inspect = require("util").inspect
const EventEmitter = require("events").EventEmitter
const windowWidth = (() => {
if (tty.isatty(1) && tty.isatty(2)) {
@dead-claudia
dead-claudia / parallelism.md
Last active April 10, 2017 10:56
Module-based parallel JS strawman

Parallel JS Strawman

Yes, this is a very significant departure from web workers, the current browser concurrency model. But I feel the lower level, more tightly integrated nature of it will make it far faster and lighter in practice, while still avoiding some significant footguns and working with the traditional single-threaded nature of JavaScript. Additionally, raw objects are much easier to deal with than pure message passing with workers.

Creating new threads

So here's my idea:

// parent.js
@dead-claudia
dead-claudia / LoaderUtils.java
Created December 23, 2016 01:06
Thallium excerpt (original JS + Java/Kotlin equivalent)
// Possible Java equivalent.
package com.isiahmeadows.thallium.internal.cli;
import java.util.*;
import jscli.interpret.Interpret;
import com.isiahmeadows.thallium.internal.types.*;
import com.isiahmeadows.thallium.Thallium;
public class LoaderUtils {
private LoaderUtils() {}