Skip to content

Instantly share code, notes, and snippets.

View Powell-v2's full-sized avatar
🌊
🌺🌋

Pavel Yermolin Powell-v2

🌊
🌺🌋
View GitHub Profile
@Powell-v2
Powell-v2 / update_deps.sh
Last active July 9, 2019 09:52
Updates all minor updates and patches. Useful if all versions in a project are exact.
PACKAGES_TO_UPDATE=()
function get_major_version { echo $(echo $1 | grep -o -E '^[0-9]{1,2}'); }
# https://stackoverflow.com/questions/1527049/how-can-i-join-elements-of-an-array-in-bash
function join_by { local d=$1; shift; echo -n "$1"; shift; printf "%s" "${@/#/$d}"; }
{
while read package current wanted latest location
do
@Powell-v2
Powell-v2 / flatten.js
Created July 3, 2019 12:39
Flatten array without using native `flat()`.
`use strict`
const { isArray } = Array
const deepFlatten = (array) => {
if (!isArray(array)) {
throw new Error(`Expecting array to process, instead got ${typeof array}.`)
}
return array.reduce((accumulator, element) =>
[
@Powell-v2
Powell-v2 / post_merge_deps_update.sh
Last active March 1, 2024 13:18
Install any missing deps after merging in updates from remote.
# capture info messages and any errors in a log file
exec >> log/hooks-out.log 2>&1
if git diff-tree --name-only --no-commit-id ORIG_HEAD HEAD | grep -q 'package.json'; then
echo "$(date): reinstalling deps since package.json changed"
yarn > /dev/null
else
echo "$(date): no changes detected in package.json"
fi
@Powell-v2
Powell-v2 / check_unused_deps.sh
Created March 15, 2019 15:30
Checks whether deps listed in package.json are in actual use and suggests removing those that are not used directly.
for dep in $(jq -r ".dependencies | keys | .[]" package.json); do
if ! grep "from .*$dep.*" -Rq --exclude-dir="node_modules" .; then
echo "you can probably remove $dep"
fi
done