Skip to content

Instantly share code, notes, and snippets.

View achetronic's full-sized avatar
💭
From bad practises always to the best ones

Alby Hernández achetronic

💭
From bad practises always to the best ones
View GitHub Profile
@achetronic
achetronic / prepare-commit-msg
Created August 1, 2024 22:12
Co-Authored-By in your commits, but easier. Put it in '$HOME/.git/hooks/prepare-commit-msg'. Thank me later
#!/bin/bash
function prompt_for_multiselect {
# little helpers for terminal print control and key input
GREEN='\033[00;32m'
YELLOW='\033[00;33m'
RESTORE='\033[0m'
ESC=$( printf "\033")
cursor_blink_on() { printf "$ESC[?25h"; }
@achetronic
achetronic / adopt-helm-resources.sh
Last active July 31, 2024 14:03
Put Helm annotations and labels on already deployed Kubernetes resources to adopt them inside a Helm Release automatically
#!/bin/bash
LOCAL_EXIT_CODE=0
RELEASE_NAME="istiod"
RELEASE_NAMESPACE="istio-system"
HELM_CHART_PATH="./istio/istiod"
HELM_EXTRA_VALUES_PATH="./istio/common/istio.yaml"
@achetronic
achetronic / get-gcloud-gke-contexts.sh
Last active October 17, 2024 23:35
Get all the GKE contexts available for you authenticted account
#!/bin/bash
LOCAL_EXIT_CODE=0
# Get a list of projects from Gcloud
PROJECTS=($(gcloud projects list --format="value(projectId)"))
# Create a directory to split clusters kubeconfig files later
mkdir -p "${HOME}/.kube/clusters"
@achetronic
achetronic / update-s3-objects-acls-huge-buckets.sh
Created October 14, 2022 13:23
Update ACLs, object by object, for buckets with millions of objects inside
#!/usr/bin/env bash
## VARIABLES
BUCKET_NAME="YOUR-BUCKET-TO-PROCESS"
BUCKET_PREFIX="THE-PREFIX-TO-START-PROCESSING/"
NEXT_FILE_TO_PROCESS=""
BASE_LIST_COMMAND="aws s3api list-objects-v2 --bucket ${BUCKET_NAME} --prefix ${BUCKET_PREFIX} --output text --query 'Contents[].Key' --max-items 100 --page-size 100"
@achetronic
achetronic / add-ssh-key-to-all-ec2-machines.sh
Created July 2, 2022 19:23
Add an SSH key to all EC2 machines on AWS
#!/usr/bin/env bash
AWS_ENVIRONMENT="production"
SSH_PUBLIC_KEY="ssh-ed25519 XXXYYYZZZexampleXXXYYYZZZ/XYZXYZ [email protected]"
# Copy the key to a temporary location
touch /tmp/id_ed25519.pub
echo "${SSH_PUBLIC_KEY}" > /tmp/id_ed25519.pub
# See all machines in all regions
@achetronic
achetronic / get-docker-image-tag-by-sha.sh
Created July 2, 2022 19:19
Find the tag of a Docker image having only the SHA256
#!/bin/bash
SHA256_HASH="5bb4faffc8b35e2702b2ffa78e982b979d7b66db29bd55b0c58de8fa745df661"
for i in {1..1000}
do
echo "Looking into page: $i"
curl "https://registry.hub.docker.com/v2/repositories/apache/superset/tags/?page=$i" \
| jq '.results[] | select(.["images"][]["digest"] == "sha256:'${SHA256_HASH}'")'