Skip to content

Instantly share code, notes, and snippets.

View caruccio's full-sized avatar
😐
state = not in mood

Mateus Caruccio caruccio

😐
state = not in mood
View GitHub Profile
@caruccio
caruccio / kubectl-setup.sh
Last active September 12, 2024 15:21
Setup basic kubectl bash env
# curl -sL https://gist.github.com/caruccio/b9eb86e307ecc293d5b832af8c577605/raw/kubectl-setup.sh | bash
mkdir -p ~/bin ~/opt
if [ -d ~/opt/kubectx ]; then
cd ~/opt/kubectx
git pull
else
git clone https://github.com/ahmetb/kubectx ~/opt/kubectx
fi
@caruccio
caruccio / for_dir.sh
Created September 9, 2024 13:09
Execute command in a list of directories
# Install: add this function to your ~/.bashrc or ~/.profile
# Open a new shell and use it:
#
# $ for_dir /tmp /home /var -- ls -la
#
function for_dir()
{
local dirs=()
@caruccio
caruccio / kubectl-use_version
Created September 3, 2024 21:16
Select kubectl binary by version
#!/bin/bash
function download()
{
KUBECTL_VERSIONS=(
$(curl -s "https://api.github.com/repos/kubernetes/kubernetes/releases?per_page=100" \
| jq -r '.[] | .tag_name' \
| grep '^v[0-9]\.[0-9][0-9]\?\.[0-9][0-9]\?$' \
| sort -Vr \
| awk -F . '!a[$1 FS $2]++' \
@caruccio
caruccio / terminal-sequence.py
Created June 1, 2024 11:49
Pythonic terminal sequencies
#!/usr/bin/env python
class TermSequence:
'''Reference: https://stackoverflow.com/a/33206814/1006369
'''
sequence = []
# standard 4-bit color codes
black = 30
red = 31
@caruccio
caruccio / canivete.md
Created May 20, 2024 14:51
Talk - Canivete suiço de gambiarras
@caruccio
caruccio / kubectl-show_tls.md
Last active September 19, 2024 14:09
Show decoded tls cert and key from a secret

$ cat kubectl-show_tls

#!/bin/bash

BIN_AWK=${0}.awk

command kubectl get secret -o json "$@" \
  | jq -r 'select(.type="kubernetes.io/tls") | .data|.[]|values|@base64d' \
  | xargs printf "%b" \
@caruccio
caruccio / kubectl-show_secret
Last active September 19, 2024 14:08
Show decoded contents of a secret
#!/bin/bash
usage()
{
echo "Usage: kubectl show-secret [-n namespace] secret [...secret]"
exit
}
while [ $# -gt 0 ]; do
while getopts n: opt; do
@caruccio
caruccio / caddy-insecure-tls-reverse-proxy.md
Last active May 17, 2024 12:32
Caddy insecure tls reverse proxy

This example shows how to access an insecure tls server using a reverse proxy

$ cat insecure-proxy.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: prom-proxy
@caruccio
caruccio / aws-assume-role
Created May 17, 2024 11:53
AWS Assume Role
#!/bin/bash
#
# Install:
# $ echo 'source ~/bin/aws-assume-role' >> ~/.bashrc
#
# Usage:
# $ aws-assume-role [name]
#
# Prerequisite:
# Create an IAM role like this in the account you what access:
@caruccio
caruccio / kubectl-color
Created May 12, 2024 18:47
Example kubectl plugin
#!/bin/bash
ContainerCreating=$(tput setaf 13) # magenta
Pending=$(tput setaf 3) # yellow
Running=$(tput setaf 2) # green
Error=$(tput setaf 1) # red
BackOf="$Error"
Terminating=$(tput setaf 8) # gray
Finished="$Terminating"
Completed="$Terminating"