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' | |
export type UpdateIndicator = (x: number, y: number) => void | |
export function useMouseIndicator(indicatorFactory?: () => { el: HTMLElement; update: UpdateIndicator; }) { | |
const [isActive, setIsActive] = useState(false) | |
useEffect(function attach() { | |
if (!isActive) return | |
if (!indicatorFactory) return |
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
function getLast<T>(items: T[]) { | |
if (items.length > 0) { | |
return items[items.length - 1] | |
} | |
} | |
/** | |
* @param items Sorted array of integers | |
*/ | |
export function findSequences(items: number[]) { |
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
export function openPopupModal(url: URL) { | |
const features = { | |
popup: 'yes', | |
width: 820, | |
height: 700, | |
top: 'auto', | |
left: 'auto', | |
toolbar: 'no', | |
menubar: 'no', | |
} |
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 debounce from 'lodash.debounce' | |
import { useCallback, useMemo, useState } from 'react' | |
export interface Props<T> { | |
defaultValue: T | |
timeout: number // in ms | |
} | |
function useExpiringState<T>({ | |
defaultValue, |
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
declare module 'package-path' { | |
export function normalExport(): any | |
export default function defaultExport(): any | |
} |
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
function isPlugin(maybePlugin) { | |
return typeof maybePlugin === 'function' | |
} | |
function composePlugins(...plugins) { | |
return (baseConfig) => plugins | |
.filter(isPlugin) | |
.reduce((c, plugin) => plugin(c), baseConfig) | |
} |
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
export function asArray<T>(item: T | T[]) { | |
return Array.isArray(item) ? item : [item] | |
} |
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 bash | |
# https://sharats.me/posts/shell-script-best-practices/ | |
set -o errexit | |
set -o nounset | |
set -o pipefail | |
if [[ "${TRACE-0}" == "1" ]]; then | |
set -o xtrace | |
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
export function identity<T>(item: T) { | |
return item | |
} |
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
export function sortByOrder<O, I>(order: O[], getID: (item: I) => O) { | |
return (a: I, b: I) => { | |
const aID = getID(a) | |
const bID = getID(b) | |
return order.indexOf(aID) - order.indexOf(bID) | |
} | |
} |