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
// Lazy load a value and cache it from the `getter` | |
function lazy<T>(getter: () => T): { value: T } { | |
return { | |
get value() { | |
const evaluated = getter() | |
Object.defineProperty(this, 'value', { value: evaluated }) | |
return evaluated | |
} | |
} |
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
# Check if running in iTerm2 and `tmux` is available | |
if [[ "$TERM_PROGRAM" == "iTerm.app" ]] && command -v tmux &>/dev/null; then | |
# Start a new tmux session or attach to an existing one | |
if [[ -z "$TMUX" ]]; then | |
tmux attach || tmux new | |
fi | |
fi |
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
pnpm add next@canary react@beta react-dom@beta | |
pnpm add -D babel-plugin-react-compiler | |
echo "module.exports = { | |
experimental: { | |
reactCompiler: true | |
}, | |
}" > next.config.js |
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 | |
import * as core from '@arethetypeswrong/core' | |
import { groupProblemsByKind } from '@arethetypeswrong/core/utils' | |
import { execSync } from 'child_process' | |
import { readFile, stat, unlink } from 'fs/promises' | |
import path from 'path' | |
const problemFlags = { | |
NoResolution: 'no-resolution', | |
UntypedResolution: 'untyped-resolution', |
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
const linearGradientText = ( | |
text: string, | |
startColor: number[], | |
endColor: number[] | |
) => { | |
let gradient = '' | |
for (let i = 0; i < text.length; i++) { | |
const r = Math.floor( | |
startColor[0] + (i / (text.length - 1)) * (endColor[0] - startColor[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
type KeysOfUnion<T> = T extends T ? keyof T : never |
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
# https://stackoverflow.com/questions/61546603/bash-find-file-and-insert-text-in-beginning-of-empty-and-non-empty-files | |
# insert `'client'\n` to all .client.tsx files | |
find . -type f -name '*.client.tsx' -print0 | while IFS= read -rd '' file; do ed -s "$file" <<< $'0a\n\'client\'\n\n.\nw\nq'; done | |
# rename files | |
ls | grep \.png$ | sed 'p;s/\.png/\.jpg/' | xargs -n2 mv |
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
git rev-list --objects --all \ | |
| grep "$(git verify-pack -v .git/objects/pack/*.idx \ | |
| sort -k 3 -n \ | |
| tail -10 \ | |
| awk '{print$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
const path = require('path'); | |
const webpack = require('webpack'); | |
const fs = require('fs'); | |
// Based on the NodeWatchFileSystem class at: | |
// - https://github.com/webpack/webpack/blob/master/lib/node/NodeWatchFileSystem.js | |
// which in turn exposes: | |
// - https://www.npmjs.com/package/watchpack | |
class CustomWatchFileSystem { |
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
const mouseEventOf = (eventType) => (element, x, y) => { | |
const rect = element.getBoundingClientRect() | |
const event = new MouseEvent(eventType, { | |
view: window, | |
bubbles: true, | |
cancelable: true, | |
clientX: rect.left + x, | |
clientY: rect.top + y, | |
}) |
NewerOlder