Skip to content

Instantly share code, notes, and snippets.

@alavkx
alavkx / package.json
Created January 8, 2024 22:36
Simple Puppeteer Web Scraper
{
"name": "some-project",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"scrape": "npx tsx ./src/scrape.ts"
},
"author": "",
"license": "ISC",
@alavkx
alavkx / Banner.tsx
Last active January 27, 2021 17:57
A11y: Which labeling method is more semantically "correct"?
// Option A: associate the label directly and hide the redundant DOM node
<div role="status" aria-label={title}>
<div aria-hidden>{title}</div>
</div>
// Option B: associate the label with an id
<div role="status" aria-labelledby="banner-title">
<div id="banner-title">{title}</div>
</div>
@alavkx
alavkx / machine.js
Created January 19, 2021 17:25
Generated by XState Viz: https://xstate.js.org/viz
// XState Brain Teaser 2 - Async Validation
// https://www.youtube.com/watch?v=nUKA0xhkZc8
const fetchValidateUserCanSendAmount = () => fetch("/validate-user-can-send-amount")
const fetchValidateBankDetails = () => fetch("/validate-bank-details")
const validationMachine = Machine({
id: 'validation',
initial: 'idle',
context: {},
@alavkx
alavkx / machine.js
Created October 19, 2020 19:56
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@alavkx
alavkx / machine.js
Last active March 1, 2021 19:57
Generated by XState Viz: https://xstate.js.org/viz
const assignField = (name) => assign({ [name]: (ctx, event) => event.payload });
const initialContext = {
agreeToTerms: undefined,
};
const quoteAcceptionMachine = Machine({
id: 'quoteAcception',
initial: 'loading',
context: initialContext,
meta: {
@alavkx
alavkx / machine.js
Last active October 8, 2020 13:11
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@alavkx
alavkx / machine.js
Created October 2, 2020 16:17
Generated by XState Viz: https://xstate.js.org/viz
const optimisticInputMachine = initial => Machine({
id: 'optimisticInput',
initial: 'idle',
context: {
value: initial,
savedValue: initial,
},
states: {
idle: {
on: {
@alavkx
alavkx / machine.js
Created September 16, 2020 19:44
Generated by XState Viz: https://xstate.js.org/viz
const optimisticInputMachine = initial => Machine({
id: 'optimisticInput',
initial: 'idle',
context: {
value: initial,
savedValue: initial,
},
states: {
idle: {
on: {
@alavkx
alavkx / machine.js
Last active September 11, 2020 20:17
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@alavkx
alavkx / machine.js
Last active August 13, 2020 19:55
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions