Skip to content

Instantly share code, notes, and snippets.

View zgotsch's full-sized avatar

Zach Gotsch zgotsch

  • Palo Alto, CA
View GitHub Profile
@zgotsch
zgotsch / saga.md
Created July 22, 2015 07:10
pigment setup adventures!
@zgotsch
zgotsch / mail.js
Created November 3, 2015 03:10
Fancy email with nodemailer
var nodemailer = require('nodemailer');
var fs = require('fs');
// create reusable transporter object using SMTP transport
var transporter = nodemailer.createTransport({
service: 'Gmail',
auth: {
user: '[email protected]',
pass: 'yourpasswordhere'
}
### Keybase proof
I hereby claim:
* I am zgotsch on github.
* I am zgotsch (https://keybase.io/zgotsch) on keybase.
* I have a public key whose fingerprint is 5A5D F20F 8B8B 4B21 2D02 8105 C09C A697 501A 4F19
To claim this, I am signing this object:
@zgotsch
zgotsch / aphrodite_v1.x.x.js
Created November 1, 2017 23:42
Aphrodite Flow Types
// flow-typed signature: 20156f0acaa7b756a5b17b397b8b8220
// flow-typed version: <<STUB>>/aphrodite_v1.2.x/flow_v0.56.0
declare module "aphrodite" {
declare type SheetDefinition = {[id: string]: any};
declare opaque type SheetEntry;
// declare export type AphroditeExtension = {
// selectorHandler: SelectorHandler
// };
@zgotsch
zgotsch / example.tsx
Created April 27, 2018 21:35
formula-one example
import * as React from "react";
import Form, {FormErrors, FormError, FeedbackStrategy} from "formula-one";
import {Draft, Person, Iso, Faction, Ship} from "../types";
import Select from "./Select";
function validateName(name: string | null): null | string {
if (name === null || name === "") {
return "Name is required";
@zgotsch
zgotsch / form.jsx
Created May 4, 2019 00:45
A simple form
class Form extends React.Component {
state = {name: ""};
handleNameChange = e => {
this.setState({
name: e.currentTarget.value
});
};
render() {
@zgotsch
zgotsch / graph.ts
Created June 7, 2023 22:18
A small versioned graph structure on top of Postgres
import {sql} from "@vercel/postgres";
import assertNever from "./assertNever";
import invariant from "small-invariant";
type Identified = {id: unknown};
type IdentifierOf<T extends {id: unknown}> = T["id"];
type Node<T extends Identified> = {
id: IdentifierOf<T>;
version: number;
@zgotsch
zgotsch / README.md
Created September 11, 2023 20:04
User-space serializable sequential computations in JS/TS

I was thinking some today about long-running computations on function-as-a-service (hereafter FaaS) platforms. FaaS platforms have relatively strict runtime constraints (e.g. 10s on Vercel's unpaid plan, but up to 15m on AWS Lambda, with others usually falling somewhere in-between). When doing computations that are either interruptable (a sequence of less expensive operations) or take place remotely (e.g. expensive API calls to something like an AI service), the ability to suspend and resume these long-running/blocking computations may make it possible to run them on FaaS platforms.

A quick web search told me what I was looking for is called "serializable first-class continuations" and, unfortunately, JS doesn't have support for first-class continuations, much less serializable ones. However, since I was primarily interested in interrupting and serializing computations at await-points, I thought I might be able to get somewhere by leveraging generators. Unfortunately generators aren't serializable either,

@zgotsch
zgotsch / nominal.ts
Created September 13, 2023 03:24
Nominal Types
// Typescript 5.2.2
// https://www.typescriptlang.org/play?#code/KYDwDg9gTgLgBDAnmYcBCUCGA7AJgHgBUAadAPjgF45C4AyOAbwH1mAjLPALnQF96mrAO4BLGNmABnST0K8A3ACgkKOAEFsiDDlxV0nAgFdsAa2wQh2UsbMXsZJStQBVbBx340cUDGB5J6praeBTUaADaAETCYhLSkQC6SoqgkLBwAGbGAMYwIhDYcO54RKRoZAAUILIAlDzBBCTkTIpwcFDAMIZQhSBwmAE4iEq8iing0PBZ2Ln5hcW4AMKelXVwRJXVNDVUFA2lzYytbe2d3YVVO5QUfQP9miNj2QWSUxAQepEZ75H9Ac-YV6OZCoACi2DySAAkrpqCx2AYeJFwZDEDDIgplCC4CixGjcAAmPT7V5QETYADmpGRELx6LITxe8D61AWFW+EB2kkweUkGREUjgACUzj1CCD8E4IBkigZ8DZzJZqbjobhImQHIoAPRak5wAB6AH5GYD4Ig9GyOVyeSI+QKAvsFXZlbTVeqlDq9UaTa84AAvC0GZY01H0io1dnvGoe3Unb2KPrc3n8wUq-GKc1J20pgJpmGKANZu2p13phNwIs5nGlmEEjMVm3F3M1wkFhvJ+3V0OtrGqZx6VwLSUg6VwEAMz1teMA30wCB52GynTBhfq8NKGfwTB6OcLyOcmNew1AA
export type Brand<T, B> = T & {__brand: B} & {__witness: T};
type AnyBrand = Brand<unknown, unknown>;
type Unbrand<B extends AnyBrand> = B["__witness"];
export function brand<T, B>(x: T): Brand<T, B> {
return x as any;
}