Skip to content

Instantly share code, notes, and snippets.

View flavono123's full-sized avatar
🐶
Doggy days

Hansuk Hong(Hans) flavono123

🐶
Doggy days
View GitHub Profile
@flavono123
flavono123 / k-rollout-histroy-with-hash.sh
Last active March 27, 2023 02:37
kubectl: list deploy's revisions and pod template hashes(replicaset)
#!/usr/bin/env sh
k rollout history deploy <deploy> -oyaml |
yq '{
.metadata.annotations."deployment.kubernetes.io/revision": .spec.template.metadata.labels.pod-template-hash
} as $item ireduce ({}; . *+ $item)'
: '
example outputs
@flavono123
flavono123 / check_docker_limit_rate.sh
Last active January 25, 2023 14:00
Check remaining Docker pull requests for anonymous
#!/bin/bash
# ref. https://www.docker.com/blog/checking-your-current-docker-pull-rate-limits-and-status/
TOKEN=$(curl "https://auth.docker.io/token?service=registry.docker.io&scope=repository:ratelimitpreview/test:pull" | jq -r .token)
curl --head -H "Authorization: Bearer $TOKEN" https://registry-1.docker.io/v2/ratelimitpreview/test/manifests/latest 2>&1 | grep ratelimit
@flavono123
flavono123 / maxips.bash
Last active November 28, 2022 15:47
Maximum Count of IPv4 Addresses by AWS EC2 Instance Type(for EKS VPC CNI)
$ aws ec2 describe-instance-types |
jq '.InstanceTypes[] |
{
"InstanceType": .InstanceType,
"MaximumIpv4Address": (.NetworkInfo.MaximumNetworkInterfaces * .NetworkInfo.Ipv4AddressesPerInterface - 3)
}' |
jq -s 'sort_by(.MaximumIpv4Address)'
@flavono123
flavono123 / aws_s3_prefix_sizes.sh
Created August 3, 2022 10:21
Aggregate total sizes of prefixes in the S3 bucket
#!/bin/bash
bucket=$1
prefixs=( "${@:2}" )
for prefix in "${prefixs[@]}"
do
size=$(aws s3api list-objects-v2 --bucket="${bucket}" --prefix="${prefix}" | jq '[.Contents[].Size] | add' | numfmt --to=si)
echo "${prefix}\t${size}"
done
@flavono123
flavono123 / Dockerfile
Created August 3, 2022 02:20
Install the "red-parquet" in Ubuntu bionic, RVM
FROM ubuntu:bionic
# Prerequisuite
RUN apt update && apt install -y ca-certificates lsb-release wget software-properties-common
# Libarrow
## ref. https://arrow.apache.org/install/
RUN wget https://apache.jfrog.io/artifactory/arrow/$(lsb_release --id --short | tr 'A-Z' 'a-z')/apache-arrow-apt-source-latest-$(lsb_release --codename --short).deb
RUN apt install -y ./apache-arrow-apt-source-latest-$(lsb_release --codename --short).deb && apt update
@flavono123
flavono123 / aws_s3_sum_of_incomplete_multipart_upload.sh
Created July 26, 2022 11:14
Sum incomplete multipart upload sizes in AWS S3
#!/bin/bash
# ref. https://stackoverflow.com/questions/43192556/using-jq-with-bash-to-run-command-for-each-object-in-array
bucket=$1
aws s3api list-multipart-uploads --bucket "${bucket}" | \
jq -r '.Uploads[] | [.UploadId, .Key] | @tsv' | \
while IFS=$'\t' read -r upload_id key; do
AWS_PAGER="" aws s3api list-parts --bucket "${bucket}" --key "${key}" --upload-id "${upload_id}"
done | \
jq 'select(has("Parts")) | .Parts[].Size' | \
@flavono123
flavono123 / aws_s3_last_modified.sh
Last active August 3, 2022 10:09
Aggregate the latest 'LastModified' of S3 objects by prefixes
#!/bin/bash
bucket=$1
prefixes=( "${@:2}" )
for prefix in "${prefixes[@]}"
do
lm=$(aws s3api list-objects-v2 --bucket="${bucket}" --prefix="${prefix}" | jq '.Contents | map(.LastModified) | sort_by(.)[-1]')
echo "${prefix}\t${lm}"
done
@flavono123
flavono123 / aws_s3_monthly_size.sh
Last active August 3, 2022 10:11
Aggregate S3 objects sizes by prefixes
#!/bin/bash
# Remaining prefix after the above prefix should be a format of '%Y/%m'
# ref. https://stackoverflow.com/questions/49382310/iterating-through-min-and-max-dates-in-bash-by-month
cur='2021-07-01'
endepoch=$(date '+%s')
bucket=$1
prefix=$2
while [[ $(date +%s -d "${cur}") -le "${endepoch}" ]]; do
@flavono123
flavono123 / mecached_lru_crawler_dump_exptime.sh
Last active June 3, 2022 05:49
Memcached dump all exptimes
#!/bin/bash
# Include infinite
echo 'lru_crawler metadump all' | nc 127.0.0.1 11211 | awk '{print $2}' | awk -F'=' '{if ($2==-1) {print "infinite"} else {system("date -d@"$2)}}'
# Exclue infinite
echo 'lru_crawler metadump all' | nc 127.0.0.1 11211 | awk '{print $2}' | awk -F'=' '$2 ~ !/-1/{system("date -d@"$2)}'
@flavono123
flavono123 / sort.jq
Last active March 29, 2022 22:41
Sort JSON by jq filters, like the option `--sort-keys`
jq 'walk(if type=="object" then to_entries | sort_by(.key) | from_entries else . end)'