Skip to content

Instantly share code, notes, and snippets.

@anhkind
anhkind / lzw_encoder.js
Created August 29, 2025 02:13 — forked from revolunet/lzw_encoder.js
LZW javascript compress/decompress
// LZW-compress a string
function lzw_encode(s) {
var dict = {};
var data = (s + "").split("");
var out = [];
var currChar;
var phrase = data[0];
var code = 256;
for (var i=1; i<data.length; i++) {
currChar=data[i];
@anhkind
anhkind / memorySizeOf.ts
Created August 13, 2025 03:06
Calculate Memory Size of a JS Object
function memorySizeOf(obj: any) {
const seen = new WeakSet<object>();
function sizeOf(value: any): number {
if (value === null || value === undefined) return 0;
const t = typeof value;
if (t === "number" ) return 8;
if (t === "boolean") return 4;
if (t === "bigint" ) return 8;
@anhkind
anhkind / load_dotenv.sh
Created July 6, 2025 10:26 — forked from mihow/load_dotenv.sh
Load environment variables from dotenv / .env file in Bash
# The initial version
if [ ! -f .env ]
then
export $(cat .env | xargs)
fi
# My favorite from the comments. Thanks @richarddewit & others!
set -a && source .env && set +a
@anhkind
anhkind / unix.md
Last active May 9, 2024 08:36
Unix misc
@anhkind
anhkind / wirerest_grafana_config.yml
Last active April 5, 2024 11:18
Wirerest dashboard on Grafana
# For Grafana dashboard: https://grafana.com/grafana/dashboards/19458-wireguard-wirerest-jvm/
# put these under `metrics.configs.scrape_configs`
- job_name: 'wirerest'
metrics_path: '/actuator/prometheus'
authorization:
credentials: YOUR_WIREREST_TOKEN
static_configs:
targets: ['YOUR_WIREREST_IP:8081']
@anhkind
anhkind / .profile
Last active January 22, 2024 07:18
Select git executable in WSL
# from: https://github.com/microsoft/WSL/issues/4401#issuecomment-670080585
# checks to see if we are in a windows or linux dir
function isWinDir {
case $PWD/ in
/mnt/*) return $(true);;
*) return $(false);;
esac
}
# wrap the git command to either run windows git or linux
@anhkind
anhkind / rerender.directive.ts
Created August 5, 2021 08:56
Angular directive to re-render a template if it detects any changes of the input
/**
* Example:
*
* <ng-container *rerender='changingInput'>
* this content will be re-rendered everytime `changingInput` changes
* </ng-container>
*/
import { Directive,
Input,
@anhkind
anhkind / yardoc_cheatsheet.md
Created April 9, 2020 07:17 — forked from phansch/yardoc_cheatsheet.md
Improved YARD cheatsheet
@anhkind
anhkind / virtualbox.sh
Last active December 22, 2018 05:25
Settings of Virtualbox
# HOST
# make symlink work on shared folder (from: https://github.com/npm/npm/issues/992#issuecomment-174154202)
VM_NAME="Ubuntu"
SHARE_NAME="sf_dev"
VBoxManage setextradata "$VM_NAME" VBoxInternal2/SharedFoldersEnableSymlinksCreate/$SHARE_NAME 1
# check again
VBoxManage getextradata "$VM_NAME" enumerate
@anhkind
anhkind / upgrade.sh
Last active September 20, 2018 15:46
Upgrade Node and Yarn
brew upgrade node
brew upgrade yarn
yarn install --ignore-engines