Skip to content

Instantly share code, notes, and snippets.

View leonidkuznetsov18's full-sized avatar
:electron:
stay hungry, stay foolish

Leonid Kuznetsov leonidkuznetsov18

:electron:
stay hungry, stay foolish
View GitHub Profile
@leonidkuznetsov18
leonidkuznetsov18 / curry.js
Last active June 4, 2020 10:39
curry (multiple arguments)
function curry(func) {
return function curried(...args) { // REST arguments to array
if (args.length >= func.length) {
return func.apply(this, args);
} else {
return function(...args2) {
return curried.apply(this, args.concat(args2));
}
}
@leonidkuznetsov18
leonidkuznetsov18 / fibonacci_bigInt.js
Last active June 3, 2020 20:59
fibonacci with BigInt
const fib = (function() {
let cache = new Map([[0, BigInt(0)],[1, BigInt(1)], [2, BigInt(1)]]);
return function(n) {
if (!cache.has(n)) {
cache.set(n, fib(n - 1) + fib(n - 2));
}
return cache.get(n);
};
})();
@leonidkuznetsov18
leonidkuznetsov18 / maxSubArray.js
Last active June 11, 2020 11:45
maximum sub arrays
function maxSubArray(nums) {
let currSum = -Infinity;
let maxSum = -Infinity;
for (let i = 0; i < nums.length; i++) {
currSum = Math.max(0, currSum);
currSum +=nums[i];
maxSum = Math.max(maxSum, currSum);
}
return maxSum;
};
@leonidkuznetsov18
leonidkuznetsov18 / recursive_update_value_nested_obj.js
Last active June 11, 2020 15:41
recursive update value inside nested objects
const fieldErrors = {
name: {
error: 'name.exists'
},
surname: {
field: {
error: 'surname.exists',
typeError: 'call.to.api.error',
},
@leonidkuznetsov18
leonidkuznetsov18 / strong-password-regex.md
Last active June 16, 2020 08:00 — forked from arielweinberger/strong-password-regex.md
Strong password Regular Expression - NestJS Course
  • Passwords will contain at least 1 upper case letter
  • Passwords will contain at least 1 lower case letter
  • Passwords will contain at least 1 number or special character
  • There is no length validation (min, max) in this regex!

Regular expression for JavaScript:

/((?=.*\d)|(?=.*\W+))(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$/
@leonidkuznetsov18
leonidkuznetsov18 / .zshrc
Last active April 28, 2021 06:44
zsh config
# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
{
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": false
},
"[javascriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": false
},
"[typescript]": {
@leonidkuznetsov18
leonidkuznetsov18 / multiple_ssh_setting.md
Created June 30, 2020 11:11 — forked from jexchan/multiple_ssh_setting.md
Multiple SSH keys for different github accounts

Multiple SSH Keys settings for different github account

create different public key

create different ssh key according the article Mac Set-Up Git

$ ssh-keygen -t rsa -C "your_email@youremail.com"
@leonidkuznetsov18
leonidkuznetsov18 / based_on_id_only_to_tree.js
Last active July 4, 2020 07:40
convert flat array to tree based on id only
const numberingArr = [
{ilvl: "0", numId: "1", text: "Sdvs"},
{ilvl: "0", numId: "1", text: "verFFE"},
{ilvl: "1", numId: "1", text: "235rf"},
{ilvl: "0", numId: "2", text: "Hrg"},
{ilvl: "1", numId: "2", text: "Gtegwr"},
{ilvl: "1", numId: "2", text: "ser"}
];
@leonidkuznetsov18
leonidkuznetsov18 / based_on_dot_to_tree.js
Created July 4, 2020 07:39
convert flat array to tree based on dot name
let array = [{ id: "1", name: "header1" }, { id: "2", name: "header2" }, { id: "1.1", name: "subheader1.1" }, { id: "1.2", name: "subheader1.2" }, { id: "2.1", name: "subheader2.1" }, { id: "2.2", name: "subheader2.2" }, { id: "1.1.1", name: "subheader1detail1" }, { id: "2.1.1", name: "subheader2detail2" }],
result = [];
array.forEach(function (a) {
let parent = a.id.split('.').slice(0, -1).join('.');
this[a.id] = { id: a.id, name: a.name };
if (parent) {
this[parent] = this[parent] || {};
this[parent].items = this[parent].items || [];