Skip to content

Instantly share code, notes, and snippets.

Avatar
🦁
Very serious fun.

Leonard Bogdonoff rememberlenny

🦁
Very serious fun.
View GitHub Profile
@rememberlenny
rememberlenny / States-v3.md
Created Jun 11, 2021 — forked from andymatuschak/States-v3.md
A composable pattern for pure state machines with effects (draft v3)
View States-v3.md

A composable pattern for pure state machines with effects

State machines are everywhere in interactive systems, but they're rarely defined clearly and explicitly. Given some big blob of code including implicit state machines, which transitions are possible and under what conditions? What effects take place on what transitions?

There are existing design patterns for state machines, but all the patterns I've seen complect side effects with the structure of the state machine itself. Instances of these patterns are difficult to test without mocking, and they end up with more dependencies. Worse, the classic patterns compose poorly: hierarchical state machines are typically not straightforward extensions. The functional programming world has solutions, but they don't transpose neatly enough to be broadly usable in mainstream languages.

Here I present a composable pattern for pure state machiness with effects,

View machine.js
const sceneStates = {
initial: 'playingVideoCanvasScene',
states: {
playingVideoCanvasScene: {
on: {
COMPLETE_SCENES: 'done',
NEXT_SCENE: {
actions: assign({
changeScene: (context, event) => {
if (remainingOrderedScenes.length) {
View gist:c0f7c3c87d25583aa9334cebc23a2c56
counterSlice.js
------------------
import { createSlice, createAsyncThunk } from '@reduxjs/toolkit'
import fakeFetch from './fakeFetch';
export const lazyAdd = createAsyncThunk('counter/lazyAdd',
async (payload, thunkAPI) => {
// throw ('error in thunk!')
const response = await fakeFetch(payload);
return response;
@rememberlenny
rememberlenny / async-foreach.js
Created Dec 13, 2020 — forked from Atinux/async-foreach.js
JavaScript: async/await with forEach()
View async-foreach.js
const waitFor = (ms) => new Promise(r => setTimeout(r, ms))
const asyncForEach = async (array, callback) => {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array)
}
}
const start = async () => {
await asyncForEach([1, 2, 3], async (num) => {
await waitFor(50)
@rememberlenny
rememberlenny / gcloud-quota.MD
Created Oct 31, 2020 — forked from Tknott95/gcloud-quota.MD
Google Cloud FIX for - IN_USE_ADDRESSES | 8 Used Quota | exceeded quotas 8+ needed 1
View gcloud-quota.MD

Google Cloud Deploy fix for 8 used quota limit issue 8+ 1 needed

(visually see servers in pic)

Gcloud Logo

** error message **

IN_USE_ADDRESSES | 8 Used Quota | exceeded quotas 8+ needed 1
@rememberlenny
rememberlenny / index.js
Created Sep 27, 2020
How to get the file size of a Google Cloud Storage object in JavaScript
View index.js
/**
* TODO(developer): Uncomment the following lines before running the sample.
*/
// const bucketName = 'Name of a bucket, e.g. my-bucket';
// const filename = 'File to access, e.g. file.txt';
// Imports the Google Cloud client library
const {Storage} = require('@google-cloud/storage');
// Creates a client
@rememberlenny
rememberlenny / Gemfile
Created Jun 25, 2020 — forked from dhh/Gemfile
HEY's Gemfile
View Gemfile
ruby '2.7.1'
gem 'rails', github: 'rails/rails'
gem 'tzinfo-data', '>= 1.2016.7' # Don't rely on OSX/Linux timezone data
# Action Text
gem 'actiontext', github: 'basecamp/actiontext', ref: 'okra'
gem 'okra', github: 'basecamp/okra'
# Drivers
@rememberlenny
rememberlenny / Gemfile
Created Jun 25, 2020 — forked from dhh/Gemfile
HEY's Gemfile
View Gemfile
ruby '2.7.1'
gem 'rails', github: 'rails/rails'
gem 'tzinfo-data', '>= 1.2016.7' # Don't rely on OSX/Linux timezone data
# Action Text
gem 'actiontext', github: 'basecamp/actiontext', ref: 'okra'
gem 'okra', github: 'basecamp/okra'
# Drivers
@rememberlenny
rememberlenny / scroll-listener.js
Created Jan 15, 2020 — forked from paulmillr/scroll-listener.js
60FPS onscroll event listener
View scroll-listener.js
(function() {
var lastScrollY = 0;
var ticking = false;
var update = function() {
// do your stuff
ticking = false;
};
var requestTick = function() {
@rememberlenny
rememberlenny / figma-modernizer-output.json
Created Aug 27, 2019
Modernizr check on Figma desktop app 08-27-2019
View figma-modernizer-output.json
{
"input":{
"autocomplete":true,
"autofocus":true,
"list":true,
"placeholder":true,
"max":true,
"min":true,
"multiple":true,
"pattern":true,