Skip to content

Instantly share code, notes, and snippets.

@larrybotha
larrybotha / machine.js
Created October 22, 2019 14:02
Generated by XState Viz: https://xstate.js.org/viz
// Luna Med user auth machine
const authUserMachine = Machine({
id: 'user',
initial: 'noUser',
context: {
error: undefined,
user: undefined,
@larrybotha
larrybotha / machine.js
Last active October 25, 2019 00:00
Generated by XState Viz: https://xstate.js.org/viz
// LunaMed organization authorisation
const fetchTargets = [{target: 'select', cond: 'hasOrgs'}, {target: 'fetching'}];
const xeroTokenExchangeTargets = [
{target: '#org.xeroSelect.exchangingToken', cond: 'hasOrgs'},
{target: 'fetchingOrgsForXeroTokenExchange'},
];
@larrybotha
larrybotha / A.markdown
Last active May 6, 2024 11:22
XState + AWS Amplify example

XState + AWS Amplify example

A breakdown of a project that uses XState to manage state for authenticating a user with Cognito, and then finding the authorized application user with an invoked machine.

  1. create auth machine
  2. create auth context
  3. handle AWS authentication
  4. once user authenticates with Cognito, redirect to user route to get user from db
  5. at user route use userMachine service from authMachine to get application user
  6. once associated application user is found, send user to organization route to allow user to associate session with specific organization
@larrybotha
larrybotha / machine.js
Last active October 4, 2019 22:51
Generated by XState Viz: https://xstate.js.org/viz
const bullishMachineConfig = {
initial: 'findingStock',
on: {
MARKET_TRENDING_DOWN: 'bearish',
MARKET_TRENDING_SIDEWAYS: 'evaluatingGeneralMarket',
},
states: {
findingStock: {
@larrybotha
larrybotha / machine.js
Last active October 22, 2019 14:00
Generated by XState Viz: https://xstate.js.org/viz
// Luna Med auth machine
const fetchMachine = Machine({
id: 'auth',
initial: 'unknown',
states: {
unknown: {
entry: 'storeRequestUrl',
@larrybotha
larrybotha / machine.js
Last active September 30, 2019 03:12
Generated by XState Viz: https://xstate.js.org/viz
const tradingStrategyMachine = Machine({
id: 'three-step-trading-process',
initial: 'backtesting',
context: {
timesRefactored: 0,
},
states: {
@larrybotha
larrybotha / machine.js
Last active September 20, 2019 21:32
Generated by XState Viz: https://xstate.js.org/viz
const xeroOrgMachine = Machine({
id: 'xeroOrg',
initial: 'noOrg',
states: {
noOrg: {
invoke: {
src: "requestAuthUrl",
onDone: "exchangingToken",
@larrybotha
larrybotha / machine.js
Last active September 20, 2019 21:14
LunaMed UI User Machine: https://xstate.js.org/viz
const userMachine = Machine({
id: "user",
initial: "noUser",
states: {
noUser: {
invoke: {
src: "getUser",
onDone: "userFound",
@larrybotha
larrybotha / A.markdown
Last active April 7, 2017 22:10
Two.js Renderer for PhysicsJS

Two.js Renderer for PhysicsJS

A starting point for a Two.js renderer for PhysicsJS.

@larrybotha
larrybotha / A.markdown
Last active April 27, 2021 09:02
Mac OS Sierra MySQL my.conf

Fixing Mac OS Sierra MySQL Woes

MySQL throwing ERROR 2006 (HY000): MySQL server has gone away?

mysql -u root -p
# enter password

mysql > SET GLOBAL max_allowed_packet=1073741824;