Skip to content

Instantly share code, notes, and snippets.

View beenotung's full-sized avatar

Beeno Tung beenotung

View GitHub Profile
@beenotung
beenotung / hackers-news.users.js
Last active May 2, 2020 22:05
user script to improve readability and night mode for hackers news
// ==UserScript==
// @name hackers-news
// @namespace http://tampermonkey.net/
// @version 0.1
// @description improve readability and night mode for hackers news
// @author You
// @match https://news.ycombinator.com/item?id=*
// @match https://news.ycombinator.com/*
// @grant none
// ==/UserScript==
@beenotung
beenotung / .bash_error
Created May 11, 2021 23:28
command not found handler for shell
command_not_found_handle() {
# Do not run within a pipe
if test ! -t 1; then
echo "command not found: $1" >&2
return 127
fi
# run local file if exist
if [ -f "$1" ]; then
echo "running ./$1..." >&2
@beenotung
beenotung / npm
Last active June 24, 2021 03:19
proxy npm to call pnpm
#!/bin/bash
set -e
set -o pipefail
case "$1" in
i|install)
shift
case "$1" in
-g|--global)
shift
npx --no npm i -g $@
@beenotung
beenotung / yarn
Created June 24, 2021 03:19
proxy yarn to call pnpm
#!/bin/bash
set -e
set -o pipefail
echo >&2 original: yarn $@
if [ "$1" == 'install' ] || [ "$1" == 'add' ] ; then
shift
if [ "$1" == '--silent' ]; then
shift
fi
echo >&2 mapto: pnpm install --prefer-offline $@
@beenotung
beenotung / .bash_error
Created August 4, 2022 13:56
demo bash error fallback handler for node.js developer
command_not_found_handle() {
# Do not run within a pipe
if test ! -t 1; then
echo "command not found: $1" >&2
return 127
fi
# run local npm package if exist
cmd="node_modules/.bin/$1"
if [ -f "$cmd" ]; then
@beenotung
beenotung / workspace-clean
Created September 24, 2020 16:02
to free up disk space by deleting downloaded packages
#!/usr/bin/env node
let fs = require('fs');
let path = require('path');
let util = require('util');
let target = {
files: [
'workspace.xml',
],
dirs: [
@beenotung
beenotung / git-ls-blob
Created September 13, 2023 15:33
find large files from git blob store
#!/bin/bash
set -e
set -o pipefail
case "$1" in
-s|--sum)
git rev-list --objects --all \
| git cat-file --batch-check='%(objecttype) %(objectsize) %(rest)' \
| sed -n 's/^blob //p' \
| awk '{x+=$1}END{print x}' \
| $(command -v gnumfmt || echo numfmt) --field=1 --to=iec-i --suffix=B --round=nearest
@beenotung
beenotung / git-rm-from-history
Last active September 13, 2023 15:41
remove file from git completely
#!/bin/bash
set -e
set -o pipefail
FILTER_BRANCH_SQUELCH_WARNING=1 git filter-branch --force --index-filter "git rm --cached --ignore-unmatch $@" --prune-empty --tag-name-filter cat -- --all
@beenotung
beenotung / 01-weighted-cache-pool.js
Last active February 20, 2024 17:59
Weighted Cache Pool Walk Through. Explaination Video: https://youtu.be/k3rKetctNug
let time = 0
Date.now = () => {
time++
return time
}
class Cache {
pool = {}
size = 0
wget \
--recursive \
--level=inf \
--waitretry=10 \
--retry-connrefused \
--page-requisites \
--convert-links \
--html-extension \
--adjust-extension \
--span-hosts \