Skip to content

Instantly share code, notes, and snippets.

View alanbsmith's full-sized avatar
👋

Alan B Smith alanbsmith

👋
View GitHub Profile
@alanbsmith
alanbsmith / guard-and-callback-example.jsx
Created December 14, 2021 04:09
Simplified guard and callback example
const MyToggleButton = ({ isContentReady, {...props} }) => {
const modelConfig = {
isIntiallyToggled: true,
shouldToggle: (data, state) => {
if (!iContentReady) {
return false;
}
return true;
},
onToggle: (data, prevState) => {
@alanbsmith
alanbsmith / function-iterator.md
Created December 14, 2021 02:35
function iterator
function eventHandler(...fns) {
  return (e) => {
    fns.forEach(fn => fn(e);
  }
}

function Component({ onClick )) {
  const handler = useClickable();
 
// generate a random answer for a given range
function setAnswer(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min);
}
// find the midpoint for a given range
function getRangeMidpoint(min, max) {
const count = min + max - 1;
return Math.ceil(count/2);
}
@alanbsmith
alanbsmith / Cocktail Starter List.md
Created November 17, 2021 20:38
A cocktail starter list and things to have on-hand for making drinks at home

Cocktail Starter List

Below are lists of simple cocktails to make at home that often share the same ingredients. If you're getting started, this is a great list to get some classic cocktails under your belt and practice your technique.

Great Starter Cocktails

Gin

  • Gin & Tonic - gin / tonic / fresh lime or lemon
  • Gimlet - gin / simple syrup / fresh lime
@alanbsmith
alanbsmith / peach-thyme-bourbon-infusion.md
Created August 27, 2021 23:59
Peach Thyme Bourbon Cocktail 🥃

Peach Thyme Bourbon Cocktail

Infusion

Ingredients

  • 2 cups high-proof bourbon (I like Knob Creek)
  • 1 peach
  • a few small fresh thyme sprigs
@alanbsmith
alanbsmith / lemon_scones.md
Created August 28, 2021 12:04
Lemon scones

Lemon Scones

Ingredients

  • 3 cups all-purpose flour
  • ⅓ cup granulated sugar
  • 1 tsp salt
  • 2 ½ tsp baking powder
  • ½ tsp baking soda
  • ¾ cup unsalted butter frozen and grated (see post)
@alanbsmith
alanbsmith / keyboard support.md
Last active August 11, 2021 00:23
keyboard support

Menu follows the Actions Menu pattern using aria-activedescendant. Below is table of supported keyboard shortcuts and associated actions.

Key Action
Enter or Space Activates the menu item and then closes the menu
Escape Closes the menu
Up Arrow Moves focus to the previous menu item – if focus is on first menu i
@alanbsmith
alanbsmith / sign.js
Last active August 5, 2021 09:17
A JS function for adding a signature to an HTML canvas element
function sign(name, fontSize = 96) {
// assumes the id of the canvas element is 'canvas'
const canvas = document.getElementById('canvas')
const ctx = canvas.getContext('2d');
ctx.font = `italic ${fontSize}px Snell Roundhand`;
const signatureWidth = ctx.measureText(name).width;
const x = canvas.width/2 - signatureWidth/2;
const y = canvas.height/2 + fontSize/2;
ctx.fillStyle = ctx.strokeStyle;
ctx.fillText(name, x, y);

Type Hierarchy Mapping

Main Mapping

Labs Mapping

  • { type.body2 } => { type.levels.subtext.medium }