Skip to content

Instantly share code, notes, and snippets.

View ggoodman's full-sized avatar

Geoff Goodman ggoodman

View GitHub Profile
@ggoodman
ggoodman / graphBuilder.ts
Created April 18, 2021 02:25
Exploration of building a module graph 'quickly' using esbuild and enhanced-resolve
import {
CachedInputFileSystem,
FileSystem,
ResolveContext,
ResolverFactory,
} from 'enhanced-resolve';
import { build, ImportKind, Loader } from 'esbuild';
import * as Fs from 'fs';
import Module from 'module';
import * as Path from 'path';
@ggoodman
ggoodman / README.md
Created February 25, 2021 15:14
Using the concept of defer from golang to simplify resource cleanup in Javascript

The withCleanup helper

Example

const result = await withCleanup(async (defer) => {
  const fileHandle = await getFileHandle();
  defer(() => fileHandle.close());
   
 // Carry on
@ggoodman
ggoodman / luggage.ts
Last active February 19, 2021 18:17
Luggage - Because sometimes your Requests don't pack lightly.
export interface AsyncLuggageFactory<TLuggage, TTraveler extends {}> {
(obj: TTraveler): PromiseLike<TLuggage>;
}
export interface AsyncLuggage<TLuggage, TTraveler extends {}> {
get(obj: TTraveler): Promise<TLuggage>;
}
const swallow = () => undefined;
@ggoodman
ggoodman / styled.ts
Created January 29, 2021 03:04
Experiment making styled-components with twind
import * as React from 'react';
import { tw } from 'twind';
import type { Context } from 'twind';
import { css } from 'twind/css';
import { TwindContext } from './internal';
export type StyledIntrinsicFactories = {
[TIntrinsic in keyof React.ReactHTML]: StyledHTML<TIntrinsic>;
};
@ggoodman
ggoodman / develop.js
Created November 22, 2020 02:37
Bare-bones nodemon + esbuild hybrid for hot-reloading a process
//@ts-check
'use strict';
const ChildProcess = require('child_process');
const Events = require('events');
const Path = require('path');
const { watch } = require('chokidar');
const { startService } = require('esbuild');
const Pino = require('pino');
@ggoodman
ggoodman / README.md
Created May 13, 2020 14:12
Velcro trace output

Velcro bundle tracing

I've found it helpful when hacking on Velcro to be able to trace the different operations performed by the sytem. Attached is an example log output when bundling up an index.js file having a dependency on react-ui.

If you eliminate the network (thank you polly.js), the whole thing takes 591ms. 🎉

@ggoodman
ggoodman / promiseMachine.ts
Created March 10, 2020 18:59
Example of generating a typed FSM for a Promise
type PromiseReject = {
eventName: '@@promiseReject';
err: unknown;
};
type PromiseResolve<T> = {
eventName: '@@promiseResolve';
value: T;
};
@ggoodman
ggoodman / definition.json
Last active March 10, 2020 18:15
Definition for a state machine that tracks a node http request through its lifecycle
{
"PendingSocket": {
"kind": "Intermediate",
"onEnter": [
{}
],
"onEvent": {
"Error": [
{
"targetStates": [
@ggoodman
ggoodman / README.md
Created March 26, 2019 18:06
Try Velcro in your browser's dev tools

Check out Velcro for more information.

// Load the runtime
var V={},velcro=(()=>{V.V='Velcro' in window?Promise.resolve(Velcro):new Promise(resolve=>{V.S=document.createElement('script');V.S.src='https://unpkg.com/@velcro/runtime@0.1';V.S.onload=()=>resolve(Velcro);document.head.appendChild(V.S);});V.R=V.V.then(v=>v.createRuntime());return s=>V.R.then(r=>r.import(s))})();

// Render a simple React element to document.body
var React = await velcro('react'), ReactDOM = await velcro('react-dom'); ReactDOM.render(React.createElement('h1', null, 'Hello Velcro'), document.body);
'use strict';
const Assert = require('assert');
Assert.ok(module.webtask.secrets['jwt-scope'], 'The jwt-scope secret is required for the jwt-authz');
module.exports = () => {
const requiredScopes = module.webtask.secrets['jwt-scope'].split(/\s+/);
return function middleware(req, res, next) {