Skip to content

Instantly share code, notes, and snippets.

View jamestharpe's full-sized avatar
🍴
Forking

James Tharpe jamestharpe

🍴
Forking
View GitHub Profile
/* eslint-disable @typescript-eslint/no-explicit-any */
import { createMachine, interpret, Interpreter, State } from "xstate";
const promiseMachine = createMachine({
id: "promise",
initial: "pending",
states: {
pending: {
on: {
RESOLVE: { target: "resolved" },
@jamestharpe
jamestharpe / machine.js
Last active April 2, 2021 22:24
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@jamestharpe
jamestharpe / machine.js
Last active March 11, 2021 16:08
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@jamestharpe
jamestharpe / machine.js
Created March 11, 2021 15:22
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@jamestharpe
jamestharpe / machine.js
Last active March 5, 2021 17:16
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@jamestharpe
jamestharpe / grade.js
Last active December 28, 2020 19:22
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@jamestharpe
jamestharpe / common-root.ts
Created August 18, 2019 18:12
Common root directory of a list of file paths using TypeScript
import { dirname, sep, resolve } from "path";
function commonRoot(...paths: string[]) {
return !paths || paths.length === 0
? undefined
: paths
.map(path => dirname(resolve(path)))
.reduce((prev, curr) => {
const prevParts = prev.split(sep);
const currParts = curr.split(sep);
@jamestharpe
jamestharpe / package.json
Created October 12, 2018 11:54
Run Mocha TypeScript Tests Against Serverless Framework with Local DynamoDB Instance
{
"name": "your-severless-application",
"version": "0.1.0",
"description": "Your description",
"main": "src/index.js",
"scripts": {
"test": "serverless offline start --migrate --exec \"mocha -r ts-node/register ./src/**/*.spec.ts\"",
"start": "serverless offline start",
},
"devDependencies": {