Skip to content

Instantly share code, notes, and snippets.

View kwokhou's full-sized avatar
🎯
Focusing

Andy Yong kwokhou

🎯
Focusing
View GitHub Profile
@kwokhou
kwokhou / read-json.js
Created December 9, 2022 06:48
NodeJS Read JSON file
const fs = require('fs')
const path = require('path')
async function start () {
const filepath = path.resolve(__dirname, 'config.json')
const config = await fs.promises.readFile(filepath, 'utf8')
const json = JSON.parse(config)
console.log(json)
}
@kwokhou
kwokhou / read-write-file.js
Created August 29, 2022 00:08
Reading and writing to file in NodeJS
const fs = require('fs');
const readFile = async filePath => {
try {
const data = await fs.promises.readFile(filePath, 'utf8')
return data
}
catch(err) {
console.log(err)
}
@kwokhou
kwokhou / FileUtils.js
Created March 27, 2022 23:43
Read and write file in NodeJS
const fs = require('fs');
const readFile = async filePath => {
try {
const data = await fs.promises.readFile(filePath, 'utf8')
return data
}
catch(err) {
console.log(err)
}
@kwokhou
kwokhou / Base VS Extensions.md
Last active March 14, 2020 03:04
Basic VS Code for JavaScript Developer
@kwokhou
kwokhou / fix-stuck-terminating-namespace.sh
Created September 7, 2019 02:40
Fix kubernetes pods or namespace stuck at removing/terminating state
# Pre-requisite
# 1. change <my-namespace> to the namespace to alter finalizing
# 2. change <my-cluster-id> to the cluster id from rancher url (e.g. https://my-rancher-ip/c/<my-cluster-id>/nodes
# 3 Replace the following commands in a text editor and run
(NAMESPACE=<my-namespace>; CLUSTER=c-fm5bd; kubectl proxy & kubectl get namespace $NAMESPACE -o json |jq '.spec = {"finalizers":[]}' >temp.json; curl -k -H "Content-Type: application/json" -X PUT --data-binary @temp.json 127.0.0.1:8001/k8s/clusters/$CLUSTER/api/v1/namespaces/$NAMESPACE/finalize; )
# Source: https://github.com/rancher/rancher/issues/16477
@kwokhou
kwokhou / pg_hba.conf
Created August 27, 2019 05:35
Configure passwordless access to Postgres docker container
...
host replication all ::1/128 trust
host all andy 172.17.0.0/16 trust
^ ^ ^
host user ip range of host trust = no password
...
@kwokhou
kwokhou / README.md
Last active June 20, 2019 06:01 — forked from jondkinney/README.md
Creating deploy user on Linode / Ubuntu

Create deploy user

Log in with ssh root@public-ip

Setup default editor

select-editor

Add a user, disable password & skip questions

{
"prettier.eslintIntegration": true,
"editor.tabSize": 2,
"editor.minimap.enabled": false,
"eslint.autoFixOnSave": false,
"editor.formatOnPaste": true,
"editor.formatOnSave": false,
"editor.fontFamily": "Fira Code",
"editor.fontLigatures": true,
"editor.fontSize": 12,
@kwokhou
kwokhou / .gitconfig
Last active July 15, 2019 21:37
Git config
[user]
name = Some dude
email = somedude@gmail.com
[core]
excludesfile = /Users/somedude/.gitignore_global
editor = vi
pager = less -FRSX
whitespace = trailing-space,cr-at-eol
autocrlf = input
[color]
@kwokhou
kwokhou / better-defaults.sh
Last active August 10, 2018 21:21
Better macOS defaults
#!/bin/bash
# Turn on / off the no so "natural" mouse scroll direction
defaults write -g com.apple.swipescrolldirection -bool NO
# Auto hide dock
defaults write com.apple.dock autohide -bool YES
# Use `sudo mdutil -i off "/Volumes/foo"` to stop indexing any volume.
sudo defaults write /.Spotlight-V100/VolumeConfiguration Exclusions -array "/Volumes"