Skip to content

Instantly share code, notes, and snippets.

View ei-grad's full-sized avatar

Andrew Grigorev ei-grad

View GitHub Profile
@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
@ei-grad
ei-grad / beamforming.py
Created July 7, 2023 13:38
Example of ~realtime audio processing in Python. Pretending to be a beamforming noise-cancellation, but doing something strange actually.
import threading
import logging
from numpy.fft import fft, ifft
import numpy as np
import jack
def denoice(left, right):
fft_l = fft(left)
@ei-grad
ei-grad / solve.py
Created June 29, 2023 15:33
SPbCTF - iZba
import sys
import random
import requests
http = requests.Session()
http.cert = 'client.pem'
base_url = 'https://its-izba-4ncvjm8.spbctf.ru:13443'
@ei-grad
ei-grad / exact_size_chunks_iter.py
Last active October 6, 2023 18:58
Generator function that efficiently transforms an iterator yielding data chunks of arbitrary sizes into an iterator yielding chunks of a specified exact size, except possibly for the last chunk.
from typing import TypeVar, Iterable, Generator, Callable, cast, Sequence
T = TypeVar('T', bound=Sequence)
def exact_size_chunks_iter(
chunks_iter: Iterable[T],
chunk_size: int,
concat: Callable[[Iterable[T]], T] = cast(Callable[[Iterable[T]], T], b''.join),