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
#!/usr/bin/env node | |
const { program } = require('commander'); | |
const opentype = require('opentype.js'); | |
const fs = require('fs'); | |
program | |
.name('svgFromFont') | |
.usage("'text' [options]") | |
.description( | |
'Renders the given text using a specified font and outputs it as an SVG, which can be used as an image on the web.' |
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 } from 'react'; | |
/** | |
* Using the browser's Selection API, sets up a listener to detect when the user selects text that | |
* resides completely within a specified element. | |
* | |
* @param containerRef The element to detect selections within. | |
* @param callback The function to call when the selection changes. It may be called additional | |
* times, particularly with `null`. If the selected text resides only partially within the container | |
* element, the callback will be called with `null`. |
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 |
NewerOlder