Skip to content

Instantly share code, notes, and snippets.

View beenotung's full-sized avatar

Beeno Tung beenotung

View GitHub Profile
@beenotung
beenotung / template.nginx
Last active April 10, 2024 08:55
nginx port forward to nodejs
server {
listen 80;
listen [::]:80;
server_name example.cc;
# client_max_body_size 1M;
location / {
proxy_pass http://localhost:8080;
@beenotung
beenotung / certbot-renew-crontab.txt
Last active March 23, 2024 11:18
crontab to auto renew https cert with certbot and nginx
# Launch the editor: sudo crontab -e
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command
M H * * * certbot renew --post-hook "service nginx restart"
# M should be a random number range: 0..59
# H should be a random number range: 0..23
wget \
--recursive \
--level=inf \
--waitretry=10 \
--retry-connrefused \
--page-requisites \
--convert-links \
--html-extension \
--adjust-extension \
--span-hosts \
@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
@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 / 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 / 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 / .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 / 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 / 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 $@