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 { type SetStateAction, useMemo, useRef, useState } from "react"; | |
type KeysOfType<O, T> = { | |
[K in keyof O]: Required<O>[K] extends T ? K : never; | |
}[keyof O]; | |
type TListState<T extends object> = [ | |
items: T[], | |
handlers: Readonly<{ | |
list: () => T[]; |
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
// utils/types.ts | |
type KeysOfType<O, T> = { [K in keyof O]: O[K] extends T ? K : never }[keyof O]; | |
// utils/array.ts | |
function inAbcOrderBy<T extends object, K extends KeysOfType<T, string>>(prop: K) { | |
return (a: T, b: T): number => { | |
return (a[prop] as string).localeCompare(b[prop] as string); | |
}; | |
} |
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
for file in *; do | |
if [ -f "$file" ]; then | |
if [ "$file" = "convert_images.sh" ]; | |
then | |
continue | |
fi | |
sips -s format heic -s formatOptions 100 $file --out ./ | |
fi | |
done |
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 { createElement, lazy, useEffect, useMemo, ComponentType, ReactElement } from 'react'; | |
export function withAwaitData<T extends {}, K extends keyof T, P extends T[K][]>( | |
component: ComponentType<T>, | |
fetcher: (...args: P) => Promise<void>, | |
keys?: K[], | |
): (props: T) => ReactElement<T>; | |
export function withAwaitData<T extends {}, K extends keyof T, P extends T[K][]>( | |
component: ComponentType<T>, | |
fetcher: (...args: P) => Promise<void>, |
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 React, {useEffect, useState, useCallback} from 'react'; | |
import Sticky from 'react-stickynode'; | |
type TFilter = { | |
name: string; | |
value: string; | |
component: React.ReactElement; | |
}; | |
interface IProps { |
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 calc(num: number, lines: number = 3) { | |
const step = (num + (num * 2 / 100)) / lines; | |
const shift = 10 ** (Math.ceil(Math.log10(Math.ceil(step) + 1)) - 2); | |
return Math.floor((Math.ceil(step / shift) * shift) * 10) / 10; | |
} | |
function round(num: number, low: number) { | |
return Math.max(calc(num), calc(low * -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 URL = 'https://www.google-analytics.com/collect'; | |
export function ga(category: string, action: string) { | |
return new Promise((res) => { | |
const data = { | |
v: 1, | |
tid: 'UA-XXXXX-Y', | |
t: 'event', | |
ec: category, | |
ea: action, |
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 SECOND = 1000; | |
const MINUTE = SECOND * 60; | |
const HOUR = MINUTE * 60; | |
const DAY = HOUR * 24; | |
const TIME = { | |
second: SECOND, | |
minute: MINUTE, | |
hour: HOUR, | |
day: DAY, |
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
performance.mark('custom_start'); | |
// do some staff here... | |
performance.mark('custom_end'); | |
// https://www.w3.org/TR/navigation-timing/#sec-navigation-timing-interface | |
performance.measure('custom', 'custom_start', 'custom_end'); | |
performance.clearMeasures('custom'); |
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 { useState, useEffect } from 'react'; | |
const DELAY = 400; | |
const mapQueries = (query: string) => window.matchMedia(query).matches; | |
function useQueries(queries: string[]): boolean[] { | |
const [values, setValues] = useState(queries.map(mapQueries)); | |
useEffect(() => { | |
let timer: number; |
NewerOlder