Skip to content

Instantly share code, notes, and snippets.

View keymon's full-sized avatar

Hector Rivas Gandara keymon

  • London, UK
  • 22:37 (UTC)
View GitHub Profile
@keymon
keymon / .aerospace.toml
Created September 17, 2024 15:11
Aerospace config similar to my i3 setup
# Reference: https://github.com/i3/i3/blob/next/etc/config
enable-normalization-flatten-containers = false
enable-normalization-opposite-orientation-for-nested-containers = false
# All possible keys:
# - Letters. a, b, c, ..., z
# - Numbers. 0, 1, 2, ..., 9
# - Keypad numbers. keypad0, keypad1, keypad2, ..., keypad9
# - F-keys. f1, f2, ..., f20
@keymon
keymon / pgpassfile_updater.go
Created October 4, 2023 14:50
A funciton in golang that updates a temporary pgfile and sets PGPASSFILE env var. Can be updated to use pgpassfile
package pgfile
import (
"context"
"fmt"
"io/ioutil"
"log"
"os"
"strings"
"time"
@keymon
keymon / get_creds.sh
Last active February 21, 2023 13:15
Warpper script to get dynamic IAM RDS credentials and call a command (psql, terraform, whatever)
#!/bin/bash
set -o pipefail -e -u
SCRIPT_NAME="$0"
SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
PROJECT_ROOT_DIR="$(cd "${SCRIPT_DIR}" && git rev-parse --show-toplevel)"
# Role to assume before trying to assume the master_user role
RDS_CREDS_ROLE_ARN="${RDS_CREDS_ROLE_ARN:-}"
@keymon
keymon / download-convert.sh
Created July 28, 2022 01:32
Download HMRC monthly exchange rates and convert to JSON/CSV
for i in 21 22; do for o in 0{1,2,3,4,5,6,7,8,9} 10 11 12; do wget http://www.hmrc.gov.uk/softwaredevelopers/rates/exrates-monthly-$o$i.XML; done; done
for i in *; do xq < $i; done | \
jq '
.exchangeRateMonthList |
(."@Period" | split(" ")[0] | strptime("%d/%b/%Y") | strftime("%d/%m/%Y")) as $from |
(."@Period" | split(" ")[2] | strptime("%d/%b/%Y") | strftime("%d/%m/%Y")) as $to |
.exchangeRate[] |
select(.currencyCode == "USD") |
{from: $from, to: $to, rate: .rateNew}
@keymon
keymon / shared-sg-for-lbs.sh
Last active September 29, 2021 23:28
Replace SG in ELBs in EKS with a shared one without downtime
#!/bin/bash
# AWS sets a limit of how many rules per Security Group can be added.
# This limit dynamic, and depends on the hard limit of rules by ENI: 1000, and computed as: 1000 / max number SG per ENI
#
# In EKS this is a problem as each ELB gets one SG that is added to the nodes SG. For instance,
# if you want to have up to 3 SG per ENI, so our hard limit is 333 loadbalancers.
#
set -e -o pipefail -u
SCRIPT_NAME="$0"
@keymon
keymon / aks-disk-clone.go
Created September 22, 2021 16:36
Clone PV in AKS
func CloneAzureDisk(
ctx context.Context,
azureClients AzureClients,
originSubscriptionID,
originResourceGroupName,
originDiskName,
targetSubscriptionID,
targetResourceGroupName,
targetDiskName string,
) (snapshot compute.Snapshot, disk compute.Disk, err error) {
-----BEGIN PGP PUBLIC KEY BLOCK-----
mQENBGE+ickBCADt5K+QcLPG9v7bKIE1d66MUsDm3XdJjK8pOIQKx65BesDE4H2Z
/n0fUvJHrwYCHQ5ejGibTLyeihQtz++LTKCA3bCOdRNh4GeAT+Jre/NxTwcrawgw
2ojNsqm6dHCgyXc2Db1UVxaduo2gfvZuxCYe0uKoNRQnZyGm9Z67E4r3kqCyDyfl
3rJYSW3cEjQvq4dSynOcyhfRiL/dWiK7VWweaI6NA9CVH+8EAlfGJB88r2mW68YQ
2DKlmtBDeKC79b1x5TBbUwXtHRThytMW9ikGD0hylxtviVSDJjFBHCUyZTGvQI6+
ZMWevz4HRWnXry0YAarOhMbtdt14gZmid3KLABEBAAG0NUhlY3RvciBSaXZhcyBH
YW5kYXJhIChZdWJpa2V5IE5lbykgPGtleW1vbkBnbWFpbC5jb20+iQFUBBMBCgA+
FiEEs4OvNfQ6eXux7Bzp/Tc4vA/SoXwFAmE+ickCGwMFCQeEzgAFCwkIBwIGFQoJ
@keymon
keymon / mandelbrot-jq.sh
Last active August 28, 2021 00:26
Compute the Mandelbrot set using jq.
#!/bin/bash
jq -r -n --argjson limit 150 --argjson size_x 140 --argjson size_y 400 '
def add_i($a;$b): [$a[0]+$b[0],$a[1]+$b[1]];
def mult_i($a;$b): [$a[0]*$b[0]-$a[1]*$b[1], $a[0]*$b[1]+$b[0]*$a[1]];
def norm($a): $a[0]*$a[0]+$a[1]*$a[1] | sqrt;
def compute_c: [-2.0+.[0]*2.5/$size_x+0.8, 1.15-.[1]*2.3/$size_y*1.2+0.22];
def compute_z($iter;$c):
if ($iter == 0) or (norm(.) >= 4) then $iter
else
add_i(mult_i(.;.); $c//[0,0]) | compute_z($iter-1; $c//.)
#!/bin/bash
## Ensure we redact credentials in output
redact_creds() {
sed 's/\(password[:="\\ ]*\)[^" ]*/\1<REDACTED>/ig'
}
exec > >(redact_creds) 2>&1
## Example code
set -x
@keymon
keymon / README.md
Created February 5, 2021 11:19
Troubleshooing weird nodePort routing in KOPS

Context

We are trying to expose some pods as nodeport to allow inter k8s communication. But the nodeport does not get routed properly to the target pod when the origin is one of the pods themselves.

We run KOPS v1.11.9

Test scenario