Skip to content

Instantly share code, notes, and snippets.

View ei-grad's full-sized avatar

Andrew Grigorev ei-grad

View GitHub Profile
#!/bin/bash
# Fetch instance types
instance_types=$(aws ec2 describe-instance-types --region us-east-1 \
--filters "Name=processor-info.supported-architecture,Values=arm64_mac" \
| jq -r '.InstanceTypes[].InstanceType' | sed 's/\.metal//g')
# Loop through each instance type and fetch pricing information
for instance_type in $instance_types; do
aws pricing get-products --service-code AmazonEC2 \
@ei-grad
ei-grad / Corefile
Created August 22, 2024 11:15
Using `coredns` as local caching name server
. {
bind lo
#forward . /etc/resolv.dhcp.conf
forward . tls://1.1.1.1 tls://1.0.0.1 {
tls_servername cloudflare-dns.com
}
cache {
success 99840 259200 600
serve_stale
}
@ei-grad
ei-grad / Dockerfile
Last active August 15, 2024 06:02
EKS Bottlerocket - use ephemeral disks to store container images
FROM public.ecr.aws/amazonlinux/amazonlinux:minimal
RUN microdnf -y install e2fsprogs bash mdadm util-linux && microdnf clean all
ADD setup-runtime-storage.sh ./
ENTRYPOINT ["/bin/bash", "setup-runtime-storage.sh"]
@ei-grad
ei-grad / coreml2text.py
Last active July 12, 2024 14:23
Extract and analyze the structure of a mlProgram CoreML models with CoreML7 spec version. This script outputs the layer names, their corresponding offsets, and tensor dimensions in a readable format. It's particularly useful for debugging and identifying unexpected sizes in exported CoreML models.
# Copyright (c) 2024 Andrew Grigorev <andrew@ei-grad.ru>
#
# This software is licensed under the MIT License. Redistribution and use are permitted
# provided that the license terms are met. For details, see the MIT License:
# https://opensource.org/licenses/MIT
import sys
from functools import reduce
from operator import mul
#!/bin/bash
# Usage: tfe-api <endpoint> [<jq filter>]
set -euo pipefail
if [ $# -lt 1 ] || [ -z "${TF_TOKEN_app_terraform_io:-}" ]; then
[ $# -lt 1 ] && echo "Usage: tfe-api <endpoint> [<jq filter>]" >&2
[ -z "${TF_TOKEN_app_terraform_io:-}" ] && echo "TF_TOKEN_app_terraform_io is not set" >&2
exit 1
fi
@ei-grad
ei-grad / go.mod
Last active May 16, 2024 10:59
get-caller-identity in go
module get-caller-identity
go 1.22.1
require (
github.com/aws/aws-sdk-go-v2 v1.26.2
github.com/aws/aws-sdk-go-v2/config v1.27.14
github.com/aws/aws-sdk-go-v2/service/sts v1.28.8
)
@ei-grad
ei-grad / refresh-session-token.py
Created February 27, 2024 18:13
Maintain AWS temporary credentials with Yubikey as MFA and `pass` to store static secret key
#!/usr/bin/env python
"""
This script is used to refresh the session token for the AWS CLI.
It maintains credentials in the AWS_SHARED_CREDENTIALS_FILE file, and
refreshes the session token when it is about to expire.
It relies on the following tools:
- pass: a password manager
@ei-grad
ei-grad / draw-projected
Last active February 22, 2024 11:59
Draw OSM geometries over each other projected to 1km units
#!/usr/bin/env python
#
# Draw OSM geometries over each other projected to 1km units
#
# Install requirements:
# pip install osmnx matplotlib
#
# Usage:
# draw-projected "Cyprus island" "RU-MOW"
#
@ei-grad
ei-grad / radiusd.conf
Last active January 12, 2024 22:18
FreeRadius configuration for WiFi WPA2/3 Enterprise EAP TLS
name = radiusd
prefix = ""
logdir = "/var/log/radius"
run_dir = "/var/run/radiusd"
libdir = "/usr/lib/freeradius"
debug_level = 2
proxy_requests = no
raddbdir = "/etc/raddb"
certdir = "${raddbdir}/certs"
@ei-grad
ei-grad / get-cf-records
Created January 2, 2024 14:59
Script to fetch list of all cloudflare DNS records
#!/bin/bash
cf_api_fetch() {
curl -s "https://api.cloudflare.com/client/v4/$1" \
-H "X-Auth-Email: $CLOUDFLARE_EMAIL" \
-H "X-Auth-Key: $CLOUDFLARE_API_KEY" \
| jq -r "$2"
}
for zone_id in $(cf_api_fetch "zones" '.result[] | .id'); do