Skip to content

Instantly share code, notes, and snippets.

🌲
lost in the woods

Tim Branyen tbranyen

🌲
lost in the woods
Block or report user

Report or block tbranyen

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@tbranyen
tbranyen / page.js
Created Apr 19, 2013
Creating pages with Backbone and Layout Manager.
View page.js
// Application.
var app = require("app");
// Page specific Views.
var Views = require("modules/page/views");
module.exports = Backbone.Model.extend({
defaults: {
title: "Unknown Page"
},
View awhat.js
function makePromise() {
return new Promise(() => {});
}
async function main() {
console.log('start');
await makePromise();
console.log('end');
}
@tbranyen
tbranyen / acceleration.sh
Created Jul 28, 2017
ThinkPad X1 Carbon 5th Generation libinput acceleration
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
@tbranyen
tbranyen / console-react.jsx
Created Jan 29, 2019
A Console component for React
View console-react.jsx
const Console = props => {
for (let method in console) {
if (method in props) {
console[method](props[method]);
}
}
return <></>;
};
@tbranyen
tbranyen / make-cancellable.js
Last active Dec 11, 2018
Make Cancellable Promise
View make-cancellable.js
Promise.makeCancellable = promise => {
const deferred = {};
const promise = new Promise((resolve, reject) => {
deferred.reject = reject;
// Invoke the fetch argument with the matching args... only resolve if not
// aborted.
promise
.then(resp => !deferred.aborted && resolve(resp))
.catch(ex => !deferred.aborted && reject(ex));
@tbranyen
tbranyen / hook-class.js
Created Dec 7, 2018
React Hooks in a Class
View hook-class.js
import { useState, Component } from 'react';
class MyComponent extends Component {
render() {
const [ count, setCount ] = this.state;
return (
<div>{count}</div>
);
}
@tbranyen
tbranyen / events.js
Last active Nov 2, 2018
Rethinking events using ES6 (https://tbranyen.com/events)
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));
@tbranyen
tbranyen / webapp.config.json
Created Oct 23, 2018
Build out ESM, CJS, UMD, Script, UMD Minified, and Script Minified
View webapp.config.json
{
"builds": [{
"input": "lib/**/*.js",
"output": "dist/esm",
"outputType": "module",
"debug": true
}, {
"input": "lib/**/*.js",
"output": "dist/cjs",
"outputType": "commonjs",
@tbranyen
tbranyen / cjs-treeshake.js
Last active Sep 27, 2018
CommonJS Tree Shaking Test Case
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';
@tbranyen
tbranyen / cjs.js
Last active Aug 30, 2018
CJS to ESM
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);
You can’t perform that action at this time.