Skip to content

Instantly share code, notes, and snippets.

View drewwyatt's full-sized avatar

Drew Wyatt drewwyatt

View GitHub Profile
@drewwyatt
drewwyatt / create_or_checkout.yml
Created October 26, 2023 22:17
Create a new branch only if one doesn't already exist
name: Create or Update Branch
on:
workflow_dispatch:
inputs:
branch:
required: true
jobs:
checkout-branch:
runs-on: ubuntu-latest
@drewwyatt
drewwyatt / machine.js
Created October 21, 2020 02:40
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@drewwyatt
drewwyatt / native-event-button.tsx
Last active May 19, 2019 04:02
onClick={wat} snippet
import React, { DetailedHTMLProps, FC, HTMLAttributes } from 'react';
import { useNativeEvent } from './useNativeEvent';
type ButtonProps = DetailedHTMLProps<HTMLAttributes<HTMLButtonElement>, HTMLButtonElement>;
type Props =
& ButtonProps
& { onClick: EventListener }; // make onClick required
export const NativeEventButton: FC<Props> = ({ onClick, ...rest }) => {
const ref = useNativeEvent('click', onClick)
@drewwyatt
drewwyatt / useNativeEvent.ts
Created May 18, 2019 23:50
onClick={wat} snippet
import { useEffect, createRef } from 'react';
const stopPropagationAndUseHandler = (handler: EventListener): EventListener => e => {
e.stopImmediatePropagation();
handler(e);
}
export const useNativeEvent = (type: string, handler: EventListener) => {
const ref: React.RefObject<any> = createRef();
@drewwyatt
drewwyatt / react-dom-comment.ts
Created May 18, 2019 23:31
onClick={wat} snippet
/**
* Summary of `ReactBrowserEventEmitter` event handling:
*
* - Top-level delegation is used to trap most native browser events. This
* may only occur in the main thread and is the responsibility of
* ReactDOMEventListener, which is injected and can therefore support
* pluggable event sources. This is the only work that occurs in the main
* thread.
*
* - We normalize and de-duplicate events to account for browser quirks. This
const el = findDomNode(this);
el.addEventListener("click", handler);
const handler = () => alert('🙌');
const MyComponent = () => <button onClick={handler}>🔥</button>;
╰─$ gitclean
Running 'git fetch'...
Running 'git remote prune origin'...
Running 'git branch -vv'...
Running 'git branch -d RN-423'...
Running 'git branch -d WE-1885-cancel-subscription-reason'...
Running 'git branch -d anna/WE-2304/app-page-refactor'...
Running 'git branch -d chandra/we-2246-ts'...
Running 'git branch -d dw-more-uat'...
/*
[2018-12-17] Challenge #370 [Easy] UPC check digits
The Universal Product Code (UPC-A) is a bar code used in many parts of the world. The bars encode a 12-digit number used to identify a product for sale, for example:
042100005264
The 12th digit (4 in this case) is a redundant check digit, used to catch errors. Using some simple calculations, a scanner can determine, given the first 11 digits, what the check digit must be for a valid code. (Check digits have previously appeared in this subreddit: see Intermediate 30 and Easy 197.) UPC's check digit is calculated as follows (taken from Wikipedia):
1. Sum the digits at odd-numbered positions (1st, 3rd, 5th, ..., 11th). If you use 0-based indexing, this is the even-numbered positions (0th, 2nd, 4th, ... 10th).
2. Multiply the result from step 1 by 3.
3. Take the sum of digits at even-numbered positions (2nd, 4th, 6th, ..., 10th) in the original number, and add this sum to the result from step 2.
import { Prompter, Validators } from './prompt';
const main = async () => {
const inputs = await new Prompter()
.prompt('What is the auction id?', { validator: Validators.required })
.then(p => p.prompt('Start Date?', { validator: Validators.isDate }))
.then(p => p.prompt('End Date?', { validator: Validators.isDate }))
.then(p => p.finish());
console.log(inputs);