Skip to content

Instantly share code, notes, and snippets.

View ignavan39's full-sized avatar
🔨
develop

Ivan Ignatenko ignavan39

🔨
develop
View GitHub Profile
@ignavan39
ignavan39 / helper.ts
Last active March 24, 2023 07:26
typescript helpers
export type UniqueArray<T> = T extends readonly [infer X, ...infer Rest]
? InArray<Rest, X> extends true
? ['Encountered value with duplicates:', X]
: readonly [X, ...UniqueArray<Rest>] | readonly [...UniqueArray<Rest>]
: T;
type InArray<T, X> = T extends readonly [X, ...infer _Rest]
? true
: T extends readonly [X]
? true
@ignavan39
ignavan39 / find_locks.sql
Last active March 16, 2022 10:48
Find and kill table locks
SELECT t.schemaname,
t.relname,
l.locktype,
l.page,
l.virtualtransaction,
l.pid,
l.mode,
l.granted
FROM pg_locks l
JOIN pg_stat_all_tables t ON l.relation = t.relid AND t.schemaname <> 'pg_catalog'::name
CREATE OR REPLACE FUNCTION trigger_set_timestamp()
RETURNS TRIGGER AS $$
BEGIN
NEW.updated_at = NOW();
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
ALTER TABLE users ADD created_at TIMESTAMP NOT NULL DEFAULT NOW();
ALTER TABLE users ADD updated_at TIMESTAMP NOT NULL DEFAULT NOW();
@ignavan39
ignavan39 / .dockerignore
Last active October 11, 2021 11:10
Dockerfile for NodeJs
/node_modules
/dist
@ignavan39
ignavan39 / .env.example
Last active January 12, 2023 16:00
Docker-compose with Postgres
DATABASE_NAME=
DATABASE_USER=
DATABASE_PASSWORD=
@ignavan39
ignavan39 / config.service.ts
Last active October 8, 2021 07:20
config.service.ts
import dotenv from 'dotenv';
import { DeepPartial } from 'typeorm';
type Join<K, P> = K extends string | number
? P extends string | number
? `${K}${'' extends P ? '' : '.'}${P}`
: never
: never;
type Prev = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...0[]];
export type Paths<T, D extends number = 10> = [D] extends [never]