Skip to content

Instantly share code, notes, and snippets.

View ebeloded's full-sized avatar

Evgenij (Eugene) Beloded ebeloded

View GitHub Profile
@ebeloded
ebeloded / auth.ts
Last active March 31, 2022 06:40
Playwright auth
import esbuild from 'esbuild'
import { firebaseConfig } from '@lumiere/config'
import { initializeApp } from 'firebase-admin/app'
import { getAuth } from 'firebase-admin/auth'
import { expect } from '@playwright/test'
import { test } from './setup'
const app = initializeApp()
const auth = getAuth(app)
@ebeloded
ebeloded / NestedPartial.ts
Last active June 12, 2023 12:32
NestedPartal.ts
type Primitive = string | number | boolean | undefined | null
type UnionToIntersection<U> = (
U extends unknown ? (k: U) => void : never
) extends (k: infer I) => void
? I
: never
type AddPrefixToKeys<
Prefix extends string,
@ebeloded
ebeloded / hash.ts
Created May 22, 2023 07:16
simpleHash
const getN2 =
(maxN: number) =>
(s: string): number => {
let hash = 0
for (let i = 0; i < s.length; i++) {
// Compute a hash by rotating the previous hash and XORing with the current character
hash = (hash << 5) ^ (hash >> 27) ^ s.charCodeAt(i)
}
function getStringId(index) {
const symbols =
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
let num = index
let id = ''
do {
id = symbols[num % 62] + id
num = Math.floor(num / 62)
} while (num > 0)
return id
@ebeloded
ebeloded / dbPath.ts
Created June 6, 2023 07:53
dbPath.ts
type PathConfig = { [key: string]: PathConfig }
type Collection<T extends PathConfig> = ((id?: string) => string) & {
[K in keyof T]: Collection<T[K]> & ((id?: string) => string)
}
function collection<T extends PathConfig>(
basePath: string,
name: string,
subCollections?: T
@ebeloded
ebeloded / createPath.ts
Last active June 9, 2023 23:24
createPath
type ProxyType<T> = {
[P in keyof T]: Record<string, ProxyType<T[P]> & Callable> & Callable
}
type Callable = {
(arg?: string): string
}
export function createPath<T extends {}>(_input: T): ProxyType<T> {
const proxy: any = (path: string[]) =>
@ebeloded
ebeloded / NestedKeysAtPath.ts
Last active November 7, 2024 09:02
NestedKeys & AtPath utility types
type NestedKeys<T> = T extends object
? {
[K in keyof T]-?: K extends string
? T[K] extends infer U
? U extends object
? K | `${K}.${NestedKeys<U>}`
: K
: never
: never;
}[keyof T]