Skip to content

Instantly share code, notes, and snippets.

@all-you-need-is-laugh
all-you-need-is-laugh / relations.ts
Created May 3, 2024 23:54
TypeORM entity relations type
// LIBRARY TYPES
type _Arr<N, Result extends number[] = []> = Result['length'] extends N ? Result : _Arr<N, [...Result, 1]>;
type _Decrement<N extends number> = _Arr<N> extends [any, ...infer U] ? U['length'] : 0;
type _Concat<S1 extends string, S2 extends string> = [S1] extends [never]
? [S2] extends [never]
? ''
: S2
: [S2] extends [never]
# Open following directory in (shell) terminal:
# for Windows: C:\Users\<insert_your_user_name>\AppData\Roaming\Code\User\History
# for Linux/WSL: /home/<insert_your_user_name>/.vscode-server/data/User/History
# Run command (template):
grep -rl '<some unique text from your setttings>' 2>/dev/null | xargs -I {} ls -al --time-style=long-iso "$PWD/{}" | sort -kr5,5 -kr6,6
# For example:
grep -rl '"editor.defaultFormatter":' 2>/dev/null | xargs -I {} ls -al --time-style=long-iso "$PWD/{}" | sort -kr5,5 -kr6,6
@all-you-need-is-laugh
all-you-need-is-laugh / jest-unwrap-console.ts
Last active December 14, 2022 15:53
I hate Jest console wrapping
//////////////////////////////////////////////
//////// test/jest-unwrap-console.ts /////////
//////////////////////////////////////////////
import * as originalConsole from 'console';
// Hi, Jest! Thx, for redundant ugly console wrapping which I didn't ask for
global.console = originalConsole;
//////////////////////////////////////////////
/////////////// jest.config.ts ///////////////
// Converts number or string containing numbers to "easy readable" word
const vowels = 'aeiouy';
const consonants = 'bcdfgklmnprstvwxz'; // without 'hjq'
function toWord (number, maxLen = Infinity) {
let vowelsIndex = -1;
let consonantsIndex = -1;
return number.toString()
.replace(/(^0)?\./, '')
@all-you-need-is-laugh
all-you-need-is-laugh / prepare-commit-msg
Last active February 15, 2023 11:13
Appends commit message with issue number
#!/bin/bash
# Appends commit message with issue number in format (for example, if your branch has name like `feature/ISSUE-1234-make-world-better`):
# "Commit message" #ISSUE-1234
COMMIT_MSG_FILE=$1
# Include any branches for which you wish to disable this script
if [ -z "$BRANCHES_TO_SKIP" ]; then
BRANCHES_TO_SKIP=(main master develop)