This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
dictPath="/usr/share/dict/words" | |
middleLetter=$1 | |
allLetters=$2 | |
# The following argument validations must be true in order for the script to be correct | |
[[ -n "$middleLetter" && -n "$allLetters " ]] || { echo "Usage: ./spellingBee.sh <middle letter> <all letters>"; exit 0; } | |
[[ "$middleLetter" =~ ^[a-zA-z]$ ]] || { echo "Usage: Middle letter must be a single letter"; exit 0; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript: (() => { | |
/* | |
* This script is meant to be run as a JavaScript bookmarklet. "Install" it by pasting the script | |
* into the URL field of a bookmark in your browser. | |
* https://www.freecodecamp.org/news/what-are-bookmarklets/ | |
* | |
* When invoked the first time, it will set a timer that prints the currently focused element to the | |
* console every 2 seconds. When invoked again, it will cancel that timer, and will continue to | |
* toggle the timer on each subsequent invocation. | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/zsh | |
# Get all the 5 letter words. This only needs to be generated once, | |
# so do it outside the script and leave the file on disk. | |
# grep '^.....$' /usr/share/dict/words > 5LetterWords.txt | |
# All the known green letters as a regex, e.g. `greens 'AB.C.'` | |
greens() { | |
grep -i $1 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
font-family: sans-serif; | |
} | |
.grid { | |
display: inline-flex; | |
flex-direction: column; | |
border-right: 3px solid black; | |
border-bottom: 3px solid black; | |
background-color: beige; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { cleanup, render, screen } from '@testing-library/react'; | |
import * as React from 'react'; | |
type MemoOption = 'none' | 'hook' | 'HOC'; | |
function ParentComponent({ log, memo }: { log: (msg: string) => void; memo: MemoOption }) { | |
log('parent'); | |
// This value is not sent into the child, it's just used to rerender the parent. | |
const [value, setValue] = React.useState(0); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Originally from https://leetcode.com/problems/group-anagrams/ | |
/* Prompt */ | |
// #------------------# | |
// # Coding question: # | |
// # Group anagrams # | |
// #------------------# | |
// | |
// Given an array of strings, group the strings that are anagrams of each other. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Taken from https://leetcode.com/problems/course-schedule/ | |
/* Problem statement */ | |
// There are a total of numCourses courses you have to take, labeled from 0 to | |
// numCourses - 1. You are given an array prerequisites where prerequisites[i] = | |
// [a_i, b_i] indicates that you must take course b_i first if you want to take | |
// course a_i. | |
// | |
// For example, the pair [0, 1], indicates that to take course 0 you have to |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as React from 'react'; | |
export type AsyncFetchState<T, E = unknown> = { | |
data: T | null; | |
loading: boolean; | |
error: E | undefined; | |
}; | |
/** | |
* This hook performs an async operation and stores its result in component state. It protects |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Higher Order Component that renders the wrapped component with the given key (derived from its | |
* props), which allows us to easily "reset" a component if certain props change. | |
* @param component | |
* @param getKey | |
*/ | |
export function KeyOn<P>(component: React.ComponentType<P>, getKey: (props: P) => string) { | |
const displayName = `KeyOn(${component.displayName})`; | |
const hoc = (props: P) => { | |
const key = getKey(props); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useEffect, useState } from 'react'; | |
import { StateMachine } from 'xstate'; | |
import { useMachine } from '@xstate/react'; | |
import { inspect } from '@xstate/inspect'; | |
let iFrameElement: HTMLIFrameElement | null = null; | |
function createIFrame() { | |
if (!iFrameElement) { | |
const iframe = document.createElement('iframe'); |
NewerOlder