Skip to content

Instantly share code, notes, and snippets.

View brookslybrand's full-sized avatar

Brooks Lybrand brookslybrand

View GitHub Profile
@brookslybrand
brookslybrand / machine.js
Created January 31, 2020 18:22
Generated by XState Viz: https://xstate.js.org/viz
// taken from https://www.w3resource.com/javascript/form/email-validation.php
const emailReg = /^\w+([.-]?\w+)*@\w+([.-]?\w+)*(\.\w{2,3})+$/;
// taken from https://stackoverflow.com/questions/19605150/regex-for-password-must-contain-at-least-eight-characters-at-least-one-number-a
const passwordReg = /^(?=.*[A-Za-z])(?=.*\d)(?=.*[@$!%*#?&])[A-Za-z\d@$!%*#?&]{8,}$/;
function mockAuthenticate(email, password, ms = 1500) {
return new Promise((resolve, reject) => {
setTimeout(() => {
if (Math.random() < 0.5) resolve(email);
@brookslybrand
brookslybrand / machine.js
Created January 17, 2020 16:18
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@brookslybrand
brookslybrand / machine.js
Last active January 17, 2020 15:53
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
title id
Bill's Pump P-201 0SMXdqEPUWGzhgMzJ2UX
16E1 Brine Exchanger 2Ghc9mqNC4J7xUBusiZg
Demo Pump P-0100 4frqz1OOo6FAY2dpnzP3
C Ditch 4mivCBjk9B4FsMYQ9dWL
V-1267 5z7NEvpQgsYwF5hFt2ix
16Z1 C Refrigeration Compressor 85RdTIPCLYvrJ0Ma5ybG
Leveling Pond 8doLIoXUMKA7fGIRf2hh
xxxxx 97z1kTNJB9W2oT9R28tG
16P1-2 Chilled Brine Pump AI4wFNxUTKaJBRuOeKsL
const incrementTime = assign({
time: (context, e) => context.time + 1
});
// Guard to check if the max count was reached
function maxCountReached(context, event) {
return context.time >= 3;
}
const timerMachine = Machine(
const reducer = produce((state, action) => {
// eslint-disable-next-line default-case
switch (action.type) {
case REVERSE: {
state.reverse();
break;
}
case SET_OPTION: {
const { id, option } = action;
const itemOptions = state.find(item => item.id === id).options;
import React, { useEffect, useState } from 'react'
import { Offline, Online } from 'react-detect-offline'
// some inline styling so everything isn't squished
const formStyle = { padding: '2rem 0rem' }
const inputStyle = { margin: '1rem 0rem' }
// a simple form with a first name, last name, and submit button
const Form = ({ db }) => {
// store form values in a state hook
// sets the name in the store and in the state hook
const setName = id => value => {
// update the store
db.formData.put({ id, value })
// update the state hook
setNames(prevNames => ({ ...prevNames, [id]: value }))
}
import React, { useState } from 'react'
import Dexie from 'dexie'
import Form from './Form'
const App = () => {
const [open, setOpen] = useState(true)
return (
<div style={{ margin: '2rem auto', width: '200px' }}>
import React from 'react'
import ReactDOM from 'react-dom'
import './index.css'
import App from './App'
import * as serviceWorker from './serviceWorker'
ReactDOM.render(<App />, document.getElementById('root'))
serviceWorker.register()