Skip to content

Instantly share code, notes, and snippets.

@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 ..."
@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 / 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 / psub.md
Last active March 9, 2021 20:05
bash parameter substituation
@albertywu
albertywu / dockertricks.sh
Last active March 2, 2021 15:56
docker tricks
# run a command inside a docker container
docker run --rm node ls
# run multiple commands inside a docker container
docker run --rm node bash -c "ls && pwd"
# pipe commands from stdin
echo "ls && pwd" | docker run --rm -i node bash
# pipe commands from script
@albertywu
albertywu / errors.go
Last active January 31, 2021 00:29
error handling in golang
package main
import (
"bytes"
"fmt"
"os"
"os/exec"
"strings"
)
#!/bin/bash
# reproduces this failure locally: https://buildkite.com/uber/web-code-runner/builds/3499312#49338f5b-c4e8-4d4b-8b60-c2961f22657f
function docker_login_ecr {
local DOCKER_CREDENTIAL_UBER_REGISTRY="027047743804.dkr.ecr.us-west-1.amazonaws.com"
aws --region=us-west-1 ecr get-login-password | docker login --username AWS --password-stdin $DOCKER_CREDENTIAL_UBER_REGISTRY
}
docker_login_ecr # so we can pull down image from buildkite
@albertywu
albertywu / pre-push
Created June 3, 2020 23:07
git hook that enforces that you've rebased origin/master before pushing
#!/bin/sh
# Called by "git push" after it has checked the remote status,
# but before anything has been pushed.
# If this script exits with a non-zero status nothing will be pushed.
#
# This hook is called with the following parameters:
#
# $1 -- Name of the remote to which the push is being done
#!/usr/bin/env bash
# --- NORMAL-MODE BENCHMARKS ---
echo "--- web-code-base normal ---"
docker system prune --all --force
docker pull 027047743804.dkr.ecr.us-west-1.amazonaws.com/web-code-base@sha256:ddfb3a6aecf3fa9fbafceb600f5d670efed472196b0dc405fc23b897a2a100d1
time IMAGE="web-code-base:normal-build" docker-compose --file tools/ci/scripts/docker/docker-compose-base.yml build web-code-base
echo "--- web-code normal ---"
docker system prune --all --force
@albertywu
albertywu / serdesTree.md
Last active May 26, 2020 04:55
serialize / deserialize a binary tree
/**
 * Encodes a tree to a single string.
 *
 * @param {TreeNode} root
 * @return {string}
 */
var serialize = function(root) {
  let result = []