Skip to content

Instantly share code, notes, and snippets.

View albannurkollari's full-sized avatar

Erenndriel albannurkollari

View GitHub Profile
@albannurkollari
albannurkollari / regexWithOcurrencePattern.ts
Last active April 10, 2024 21:39
Regex with ocurrence pattern helper
export const regexWithOccurrencePattern = (regex: RegExp | string) => {
const source = regex instanceof RegExp ? regex.source : regex;
return new RegExp(`^${source}((,${source})+)?$`);
};
export const KEY_VALUE_PAIRS_REGEX = regexWithOccurrencePattern(/\w+=\w+/);
@albannurkollari
albannurkollari / bashrc
Last active December 12, 2023 22:56
My go to .bashrc
env=~/.ssh/agent.env
bind 'set enable-bracketed-paste off'
agent_load_env () { test -f "$env" && . "$env" >| /dev/null ; }
agent_start () {
(umask 077; ssh-agent >| "$env")
. "$env" >| /dev/null ;
}
agent_load_env
@albannurkollari
albannurkollari / gitconfig
Last active December 12, 2023 22:49
My go-to .gitconfig
[color]
ui = auto
[core]
editor = code --wait
autocrlf = false
[diff]
tool = code
[difftool "code"]
cmd = code --wait --diff $REMOTE $LOCAL
[alias]
@albannurkollari
albannurkollari / pollRequest.ts
Created October 24, 2023 10:25
Polls a given callback function until it resolves or the `maxTries` is reached.
/** `⚠️ DevNote`: Should always resolve and never reject. */
type PollRequestCallback = (count: number) => Promise<{ fulfilled: boolean; value: any }>;
type PollRequestOptions = { delay: number | 1000; maxTries: number | 10 };
/**
* Polls a given callback function until it resolves or the `maxTries` is reached.
*
* The resolved value should be an object with `fulfilled` and `value` properties.
* If `fulfilled` is `true`, then it will stop polling at that count and resolve the
* given `value`.
@albannurkollari
albannurkollari / pr-body-parser-with-unified.ts
Created March 25, 2023 03:23
e2e-filters-with-unified-plugins-pr-body-parser
import { unified } from 'unified';
import remarkParse from 'remark-parse';
import remarkGfm from 'remark-gfm';
import remarkRehype from 'remark-rehype';
import rehypeFormat from 'rehype-format';
import rehypeStringify from 'rehype-stringify';
import rehypeRaw from 'rehype-raw';
import { load as cheerioLoad } from 'cheerio';
(async () => {
@albannurkollari
albannurkollari / tokenizeStrAndSplitIntoChunks.js
Last active August 20, 2022 23:13
Tokenize a string consequetively and split into chunks
const tokenizeStrAndSplitIntoChunks = (strToTokenize = '') =>
[...strToTokenize].reduce(
(acc, letter, i, { length }) => {
if (/\w+/.test(letter)) {
acc[acc.length - 1] += letter;
} else if (i !== length - 1 && acc.at(-1) !== '') {
acc.push('');
}
return acc;
@albannurkollari
albannurkollari / what-forces-layout.md
Created April 6, 2022 08:41 — forked from paulirish/what-forces-layout.md
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
@albannurkollari
albannurkollari / triggerNativeEventFor.js
Created March 7, 2022 10:53
Trigger a React synthetic event programmatically in JS
export const triggerNativeEventFor = (elm, { event, ...valueObj }) => {
if (!(elm instanceof Element)) {
throw new Error(`Expected an Element but received ${elm} instead!`);
}
const [prop, value] = Object.entries(valueObj)[0] ?? [];
const desc = Object.getOwnPropertyDescriptor(elm.__proto__, prop);
desc?.set?.call(elm, value);
elm.dispatchEvent(new Event(event, { bubbles: true }));
@albannurkollari
albannurkollari / .gitconfig
Created July 29, 2021 09:36
My day to day GIT aliases
# to be updated
[alias]
## disecting/inspecting/searching
findkeyword = "!f() { git log -S $1 --oneline -- ':(exclude)*package-lock.json' . ; }; f"
@albannurkollari
albannurkollari / cloudSettings
Last active September 1, 2020 19:09
Visual Studio Code Settings Sync Gist
{"lastUpload":"2020-09-01T19:09:55.494Z","extensionVersion":"v3.4.3"}