Skip to content

Instantly share code, notes, and snippets.

View leoxlin's full-sized avatar
:shipit:
Probably Shipping Code Furiously

Leo X. Lin leoxlin

:shipit:
Probably Shipping Code Furiously
View GitHub Profile
@leoxlin
leoxlin / phrase_gen.py
Created July 27, 2022 13:05
Generate some-random-words-and-names style word phrases for external ids, hostnames etc.
#!/usr/bin/env python3
# Usage: ./phrase_gen.py [number of words, default=5] [seperator, default='-']
import random
import sys
def generate_phrase(num_choices, seperator):
return seperator.join(random.choices(WORDS, k=num_choices))
# WORD LIST FROM http://web.archive.org/web/20091003023412/http://tothink.com/mnemonic/wordlist.txt
WORDS=[

Install 1Pass-CLI V1 and V2

1password CLI changed their schema significantly between v1 and v2.

This can cause a lot of scripts to break.

The official upgrade guide actually recommend running them in parallel.

https://developer.1password.com/docs/cli/upgrade

Git Diff + Patch

Using a diff patch is often times overlooked as a merge strategy because not many people know it exists. This is really useful when you have two branches that have diverged commit wise or if you only want to merge/revert diff from specific files but not cherry-pick the entire commit.

How it works

You want can use git diff of the exact things you want to merge/revert.

# eg. `AWS_PROFILE=production wait_stack create api-servers`
wait_stack () {
STEP_NAME=$1
STACK_NAME=$2
aws cloudformation wait stack-${STEP_NAME}-complete --stack-name ${STACK_NAME} && \
osascript -e "display notification \"stack-${STEP_NAME}-complete ${STACK_NAME}\""
}

Git + JIRA Tools

  1. Install the JIRA CLI

    brew install go-jira
    

    If you cannot install this via brew or is on another OS than MacOS. Look at the install instructions on https://github.com/go-jira/jira

@leoxlin
leoxlin / csv
Created August 13, 2020 19:19
Utility to selectively output CSV files
#!/usr/bin/env python
import csv
import sys
if len(sys.argv) < 2:
print("usage: csv <filename> <opt: col1,col2,...>")
sys.exit(1)
filename = sys.argv[1]
import java.util.Arrays;
import java.util.List;
import java.util.function.Function;
public class JavaLambdaCompilerExample {
interface ImplicitLambda1 {
String whatever();
}
interface ImplicitLambda2 {

Problem

At HubSpot we use dba workload on Vitess for migrations.

We discovered that sometimes certain shards will hang while doing a planned reparent and eventually fail.

Deep diving

We were able to isolate the hanging behavior to a draining tx_pool on vttablet

@leoxlin
leoxlin / select-lock-query.md
Last active June 20, 2018 23:40
SELECT_LOCK not enabled in transactions

Query

CREATE TABLE `example` (
  `id1` int NOT NULL,
  `row1` int NOT NULL,
  `row2` int NOT NULL
); 

SELECT * FROM example WHERE (id1, row1, row2) IN ((1, 2, 3), (4, 5, 6)) FOR UPDATE;