Instantly share code, notes, and snippets.

View webapp.config.json
{
"builds": [{
"input": "lib/**/*.js",
"output": "dist/esm",
"outputType": "module",
"debug": true
}, {
"input": "lib/**/*.js",
"output": "dist/cjs",
"outputType": "commonjs",
View events.js
const bus = {};
const get = e => (bus[e] = bus[e] || new Set());
export const listeners = new Proxy(bus, { get });
export const emit = (e, ...args) => listeners[e].forEach(fn => fn(...args));
View cjs-treeshake.js
it('will treekshake a static named import', async () => {
const input = register('./a')`
const { a } = require('./b');
console.log(a);
`;
register('./b')`
function b() {}
exports.a = 'hello world';
View cjs.js
const something = require('something');
const { somethingElse } = require('something-else');
const { exports } = module;
exports.somethingElse = somethingElse;
module.exports = something;
Object.assign(module.exports, exports);
View webapp-node-api.js
const { webapp, register } = require('webapp');
async function main() {
const input = register('./input.js')`
const msg = 'Hello world!';
console.log(msg);
`;
const { source } = await webapp({
input,
View promise-getters.md

Functions rescue us in this case because functions are lazy. But now, we can’t chain these things with .then() anymore.

function lazyPromise() {
  return new Promise(resolve => setTimeout(resolve, 1000))
    .then(() => console.log('Chain off all'));
}
// The only location you can't chain off is the function

// Chains just fine this way
View concept.js
// Create virtual document and documentElement.
const vdoc = document.createVirtualDocument();
const root = vdoc.createDocumentElement('html');
// <template/> tags should be able to be converted as well.
const someTemplate = document.querySelector('template#some-template');
// Add some SVG.
root.appendChild(vdoc.createElement({
nodeName: 'svg',
namespaceURI: 'http://www.w3.org/2000/svg',
View acceleration.sh
touchpad_id=$(xinput --list | grep "TouchPad" | xargs -n 1 | grep "id=" | sed 's/id=//g')
accel_speed_code=$(xinput --list-props $touchpad_id | awk '/Accel Speed \(/ {print $4}' | grep -o '[0-9]\+')
# Default acceleration is too slow (non-existent)
xinput --set-prop $touchpad_id $accel_speed_code .75
View fixture.js
const { render } = require('react-dom');
const mount = document.querySelector('main');
class Root {
render() {
return (
<div>Hello world</div>
);
}
}
View example.js
import { innerHTML } from 'diffhtml'
// Start simple...
innerHTML(document.body, `
<marquee>Go for it!</marquee>
`)
// Move to template engine if you want
innerHTML(document.body, mustache.render(`
<div>