Skip to content

Instantly share code, notes, and snippets.

@albertywu
albertywu / psub.md
Last active March 9, 2021 20:05
bash parameter substituation
@albertywu
albertywu / raid.sh
Last active March 17, 2021 00:19
raid0 setup
# note: run as root
devicemount=/mnt
logicalname=/dev/md0
# get instance storage block devices
devices=( $(lsblk -o name,type,size,model,mountpoint | grep -i "NVMe Instance Storage" | awk '{print "/dev/"$1}') )
if [[ "${#devices[@]}" -gt 0 ]] ; then
mkdir -p "$devicemount"
@albertywu
albertywu / unpivot.md
Last active March 26, 2021 19:40
unpivot a table in presto
Convert table t1 of this form:

id | p50 | p75 | p95
---------------------
1  | 10  | 11  | 12
2  | 13  | 14  | 15

into this form:
@albertywu
albertywu / max_v8_heapsize.sh
Last active April 3, 2021 20:17
get max v8 heap size for node
echo "console.log(require('v8').getHeapStatistics())" | node - | grep heap_size_limit
# both max-old-space-size and max_old_space_size work
export NODE_OPTIONS="--max-old-space-size=16384"
export NODE_OPTIONS="--max_old_space_size=16384"
# alternatively, "node --max-old-space-size=16384 ..."
const o = { foo: 1, bar: 2 }
const a = [1, 2, 3]
// iterate over keys in object
for (prop of Object.keys(o)) {
console.log(prop)
}
// iterate over values in object
for (value of Object.values(o)) {
@albertywu
albertywu / jira_cli.md
Last active November 1, 2021 20:11
jira_cli.md
go install github.com/ankitpokhrel/jira-cli/cmd/jira@latest
export JIRA_API_TOKEN=$(usso -ussh t3 -print)
jira setup

# Add to startup script:
jira()
{
	unset -f jira
	JIRA_API_TOKEN=$(usso -ussh t3 -print)

using latest version 0.9.0

  1. works without cluster_id
resource "buildkite_pipeline" "wua-test-no-cluster" {
  name = "wua-testing-no-cluster"
  description = "testing creating a pipeline without cluster"
  repository = "gitolite@code.uber.internal:mobile/android"
  default_branch = "main"
  steps = file("./pipelines/mobile-release/metro-minion-build-release-apk-android.yml")
@albertywu
albertywu / sqlcsv
Last active June 21, 2022 17:56
sqlcsv - run sql on your csv
# Usage:
# sqlcsv foo.csv foo 'select count(*) from foo;'
#
# Requirement:
# brew install sqlite
function sqlcsv {
local file="$1"
local table="$2"
local cmd="$3"
@albertywu
albertywu / clibuddy.md
Last active April 15, 2023 02:00
A specification for clibuddy

I want to create a python CLI tool called 'clibuddy' that uses the 'click' library.

The CLI tool will wrap another command, and will either 1) print out detailed information of what failed or 2) attempt to fix errors any time the wrapped command fails with exit code > 0.

Structure of CLI app:

clibuddy --tool="tools/mytool.py" --explain mytool ...mytool_args
clibuddy --tool="tools/mytool.py" --fix mytool ...mytool_args