Skip to content

Instantly share code, notes, and snippets.

View grumd's full-sized avatar
🏠
Working from home

Anton Kalmanovich grumd

🏠
Working from home
  • Proxet
  • Ukraine, Kiev
View GitHub Profile
@nopeless
nopeless / check-prime.ts
Last active April 5, 2024 20:26
static prime checking using typescript types
// Prime checking regex, which this code is based off of
// https://regex101.com/r/RIJkGF/1
type StringDivisible<n extends string, div extends string> = n extends `` ? true : n extends `${div}${infer r}` ? StringDivisible<r, div> : false;
type Substrings<n extends string, d extends string = ""> = n extends `${d}${infer r}` ? readonly [` ${d}`, ...Substrings<r, ` ${d}`>] : readonly [];
type StringFactors<n extends string> = Substrings<n> extends readonly [unknown, ...infer R extends readonly string[], unknown] ? R : never;
type StringIsPrime<n extends string, Factors extends readonly string[] = StringFactors<n>> = Factors extends readonly [infer s extends string, ...infer R extends readonly string[]] ? StringDivisible<n, s> extends true ? false : StringIsPrime<n, R> : true;
type RepeatStringByStringDigit<str extends string, d extends string> =
@parties
parties / renameReactJsToJsx.sh
Last active April 27, 2024 19:37
rename all *.js files containing React markup to *.jsx
# finds all *.js files that have either `</` or `/>` tags in them and renames them to *.jsx
find ./src -type f -name '*.js' -not -name '*.jsx' -not -name '*.ejs' -exec bash -c 'grep -l -E "</|/>" "$0"' {} \; -exec bash -c 'mv "$0" "${0%.js}.jsx"' {} \;