Skip to content

Instantly share code, notes, and snippets.

:octocat:
Understand Create Evaluate

Yehor Sergeenko bricss

:octocat:
Understand Create Evaluate
View GitHub Profile
@bricss
bricss / iso-8601.js
Created Jul 1, 2020
RegExp to validate ISO 8601 date
View iso-8601.js
const isoDate = /^(?:[-+]\d{2})?(?:\d{4}(?!\d{2}\b))(?:(-?)(?:(?:0[1-9]|1[0-2])(?:\1(?:[12]\d|0[1-9]|3[01]))?|W(?:[0-4]\d|5[0-2])(?:-?[1-7])?|(?:00[1-9]|0[1-9]\d|[12]\d{2}|3(?:[0-5]\d|6[1-6])))(?![T]$|[T][\d]+Z$)(?:[T\s](?:(?:(?:[01]\d|2[0-3])(?:(:?)[0-5]\d)?|24\:?00)(?:[.,]\d+(?!:))?)(?:\2[0-5]\d(?:[.,]\d+)?)?(?:[Z]|(?:[+-])(?:[01]\d|2[0-3])(?::?[0-5]\d)?)?)?)?$/;
@bricss
bricss / flout.sh
Last active Mar 6, 2020
Ignore file change(s) for CI
View flout.sh
#!/usr/bin/env bash
# Ignore file change(s) for CI
# Usage: `sh flout.sh`
git status --porcelain | cut -c4- | xargs -n1 git update-index --assume-unchanged
@bricss
bricss / cp-pkg.sh
Last active Mar 6, 2020
Cherry-pick package.json change(s) between branches
View cp-pkg.sh
#!/usr/bin/env bash
# Cherry-pick package.json change(s) between branches
# Usage: `sh cp-pkg.sh branch`
# Add --patch after branch name if auto merge conflict(s) occur
git restore --source $@ package{,-lock}.json packages/*/package{,-lock}.json
@bricss
bricss / .eslintrc.json
Last active Jul 1, 2020
Ultra refined ESLint `>=7.3.x` config
View .eslintrc.json
{
"env": {
"browser": true,
"es2020": true,
"jasmine": true,
"jest": true,
"mongo": true,
"node": true
},
"extends": [
@bricss
bricss / keygen.sh
Last active Mar 6, 2020
Generating public/private Ed25519 key pair
View keygen.sh
#!/usr/bin/env bash
# Generating public/private Ed25519 ssh key pair
# Usage: `sh keygen.sh "your.email@example.com"`
ssh-keygen -t ed25519 -C "$@"
@bricss
bricss / peers-install.sh
Last active Mar 6, 2020
Install node package "peerDependencies" by simple shell script
View peers-install.sh
#!/usr/bin/env bash
# Add the following line to the "scripts":
# "postinstall": "printf \"Please install peerDependencies by running:\\n node -p -e \\x22require('./package.json').peerDependencies\\x22 | sed \\x22s/[\\{\\},]//g ; s/: /@/g\\x22 | xargs -r npm install\\n",
if echo | xargs -r >/dev/null 2>&1; then
xopts="-r"
else
xopts=""
fi
@bricss
bricss / broom.sh
Last active Mar 6, 2020
Remove remote merged branches from Git repo
View broom.sh
#!/usr/bin/env bash
# Remove remote merged branches from Git repo
git fetch --prune --tags origin
git branch --remotes --merged origin | grep origin | grep -v $(git symbolic-ref --short HEAD) | grep -v -e master | sed s/origin\\/// | xargs git push origin --delete
@bricss
bricss / druuid.js
Created Jan 16, 2019
Date-relative (and relatively universally unique) UUID generation. Inspired by: https://www.npmjs.com/package/druuid
View druuid.js
exports.gen = (date = Date.now()) => {
return ((BigInt(date) << (64n - 41n)) ^ (BigInt(window ? crypto.getRandomValues(new Uint8Array(32)).join('') : [...crypto.randomBytes(32)].join('')) % (2n ** (64n - 41n)))).toString();
};
exports.time = (uuid) => {
return new Date(Number((BigInt(uuid) >> (64n - 41n))));
};
@bricss
bricss / squash-all-exp.sh
Last active May 23, 2020
Squashes all commits on the branch
View squash-all-exp.sh
#!/bin/sh
# Squashes all commits on the branch
# Use: `sh squash-all.sh "one commit message"`
current=$(git describe --all --always --contains)
parent=$(git show-branch -a | grep '\*' | grep -v `git rev-parse --abbrev-ref HEAD` | head -n1 | sed 's/.*\[\(.*\)\].*/\1/' | sed 's/[\^~].*//')
count=$(git log --abbrev-commit --decorate --first-parent --pretty=oneline $parent..$current | wc -l)
git reset --soft HEAD~$count
git commit -am "$@"
@bricss
bricss / pre-push
Last active Mar 6, 2020
Warns before pushing to protected branches
View pre-push
#!/usr/bin/env bash
# Warns before pushing to protected branches
# Set up default git hooks with `git config --global core.hooksPath /path/to/hooks`
# Bypass with `git push --no-verify`
current=$(git rev-parse --abbrev-ref HEAD)
protect="^(master|release|patch-*)"
secs=15
status=0
You can’t perform that action at this time.