Skip to content

Instantly share code, notes, and snippets.

View patrickshan's full-sized avatar

Patrick Shan patrickshan

View GitHub Profile
@patrickshan
patrickshan / trace_dns_drops.bt
Created October 17, 2022 10:28 — forked from xh4n3/trace_dns_drops.bt
trace_dns_drops traces DNS drops by ip_vs_in and ipt_do_table.
#!/usr/bin/env bpftrace
/*
* trace_dns_drops traces DNS drops by ip_vs_in and ipt_do_table.
*
* Background:
* 1. Before 5.9, ip_vs_in can cause UDP packets drops when IPVS RS deleted
* and source port reused, See https://github.com/kubernetes/kubernetes/issues/71514 for more details.
* 2. Misconfiguration of iptables can cause DNS drops.
*
* Usage:
@patrickshan
patrickshan / gist:e431dc2ef90ed1e8a4d15029a341a908
Created August 16, 2022 11:10
Find and print out namespace and pod name for all naked pods in a Kubernete cluster
kubectl get pods -A -ojson | jq -c '.items[] | select(.metadata.ownerReferences == null) | "\(.metadata.namespace) => \(.metadata.name)"'

Stevey's Google Platforms Rant

I was at Amazon for about six and a half years, and now I've been at Google for that long. One thing that struck me immediately about the two companies -- an impression that has been reinforced almost daily -- is that Amazon does everything wrong, and Google does everything right. Sure, it's a sweeping generalization, but a surprisingly accurate one. It's pretty crazy. There are probably a hundred or even two hundred different ways you can compare the two companies, and Google is superior in all but three of them, if I recall correctly. I actually did a spreadsheet at one point but Legal wouldn't let me show it to anyone, even though recruiting loved it.

I mean, just to give you a very brief taste: Amazon's recruiting process is fundamentally flawed by having teams hire for themselves, so their hiring bar is incredibly inconsistent across teams, despite various efforts they've made to level it out. And their operations are a mess; they don't real

@patrickshan
patrickshan / install_bcc.sh
Created September 14, 2018 23:57
install bcc on debian testing (buster)
# install llvm clang dependencies
sudo apt install llvm-6.0-dev libclang-dev
git clone https://github.com/iovisor/bcc.git
mkdir bcc/build; cd bcc/build
cmake .. -DCMAKE_INSTALL_PREFIX=/usr
make
sudo make install
@patrickshan
patrickshan / build_kernel.sh
Created August 18, 2018 12:16
Use ramdisk to build latest kernel deb package for debian
#!/bin/bash
if [[ $EUID -ne 0 ]]
then
echo "This script must be run as root"
exit 1
fi
if [[ $# -ne 1 ]]
then

Create Root CA (Done once)

Create Root Key

Attention: this is the key used to sign the certificate requests, anyone holding this can sign certificates on your behalf. So keep it in a safe place!

openssl genrsa -des3 -out rootCA.key 4096
#!/bin/bash
instance_profile=`curl http://169.254.169.254/latest/meta-data/iam/security-credentials/`
aws_access_key_id=`curl http://169.254.169.254/latest/meta-data/iam/security-credentials/${instance_profile} | grep AccessKeyId | cut -d':' -f2 | sed 's/[^0-9A-Z]*//g'`
aws_secret_access_key=`curl http://169.254.169.254/latest/meta-data/iam/security-credentials/${instance_profile} | grep SecretAccessKey | cut -d':' -f2 | sed 's/[^0-9A-Za-z/+=]*//g'`
token=`curl -s http://169.254.169.254/latest/meta-data/iam/security-credentials/${instance_profile} | sed -n '/Token/{p;}' | cut -f4 -d'"'`
region="ap-southeast-2"
file="test.sh"
bucket="test.bucket"
@patrickshan
patrickshan / main.go
Created May 23, 2017 23:49 — forked from lizrice/main.go
Container from scratch
package main
// @lizrice, mostly copied from @doctor_julz: https://gist.github.com/julz/c0017fa7a40de0543001
import (
"fmt"
"os"
"os/exec"
"syscall"
)
@patrickshan
patrickshan / exercise.tour.go
Created July 21, 2016 11:19 — forked from zyxar/exercise.tour.go
tour.golang exercise solutions
/* Exercise: Loops and Functions #43 */
package main
import (
"fmt"
"math"
)
func Sqrt(x float64) float64 {
z := float64(2.)