Skip to content

Instantly share code, notes, and snippets.

View magickatt's full-sized avatar

Andrew Kirkpatrick magickatt

View GitHub Profile
@magickatt
magickatt / github_app_jwt.sh
Last active November 15, 2024 15:35
Generate GitHub App JWT and Token
#!/usr/bin/env bash
# Combination of generating the JWT and the token
# https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/generating-a-json-web-token-jwt-for-a-github-app#generating-a-json-web-token-jwt
# https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/authenticating-as-a-github-app#using-a-json-web-token-jwt-to-authenticate-as-a-github-app
# https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/generating-an-installation-access-token-for-a-github-app#generating-an-installation-access-token
# https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/authenticating-as-a-github-app-installation
set -o pipefail
@magickatt
magickatt / ci.yml
Created November 8, 2024 15:45
Merge Golang unit and integration test code coverage using GitHub Actions
name: CI
jobs:
unit-tests:
name: Unit Tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Go
@magickatt
magickatt / cobra_subcommand_usage.go
Last active November 8, 2024 15:35
Print usage for Cobra sub-commands
package cmd
import (
"fmt"
"os"
"text/tabwriter"
"github.com/you/your-project/cmd/testcmd"
"github.com/spf13/cobra"
)
@magickatt
magickatt / elasticmq.go
Created June 17, 2024 21:15
Use ElasticMQ with AWS SDK v2
ctx := context.TODO()
queueName := "something"
endpointURL := "http://localhost:9324"
messageBody := "test"
// Create a custom endpoint resolver for ElasticMQ
elasticmqResolver := aws.EndpointResolverWithOptionsFunc(func(service, region string, options ...interface{}) (aws.Endpoint, error) {
if service == sqs.ServiceID {
return aws.Endpoint{URL: endpointURL}, nil
}
@magickatt
magickatt / convert_namespace_to_subnamespace.sh
Last active April 19, 2024 21:25
Convert an existing namespace to a subnamespace using the Hierarchical Namespace Controller
PARENT_NAMESPACE=pizzeria
CHILD_NAMESPACE=pepperoni
$ kubectl annotate namespace $CHILD_NAMESPACE \
hnc.x-k8s.io/subnamespace-of=$PARENT_NAMESPACE
# namespace/pepperoni annotated
$ cat <<EOF | kubectl apply -f -
apiVersion: hnc.x-k8s.io/v1alpha2
@magickatt
magickatt / scheduled_deployment_restart.yaml
Last active April 15, 2024 20:39
Restart Kubernetes Deployment on a schedule using a CronJob
apiVersion: batch/v1
kind: CronJob
metadata:
name: "restart-{{ $application.name }}"
namespace: "{{ $.Release.Namespace }}"
spec:
concurrencyPolicy: Forbid
schedule: "* * * * *" # crontab.guru
jobTemplate:
spec:
@magickatt
magickatt / latest_release.yml
Created January 18, 2024 20:43
Upload multi-architecture Go binaries to GitHub release
name: Latest Release
# Customise for the tag format you are using
on:
push:
tags:
- v*
# Required for the release action to upload artifacts
permissions:
@magickatt
magickatt / adopt_helm_deployment_pod_resources.sh
Created April 28, 2023 15:06
Adopt Deployment Pod resources into a Helm install
# Can use https://gist.github.com/magickatt/e7885f748c2ecd5bb88dd64828b30fbf
# to adopt the Deployment resources themselves
NAME=test
NAMESPACE=default
kubectl get -n $NAMESPACE deployment -o name \
| xargs -I % kubectl patch -n $NAMESPACE % -p \
'{"spec": {"template":{"metadata":{"annotations":{"meta.helm.sh/release-name": "$NAME"}}}}}'
@magickatt
magickatt / adopt_helm_resources.sh
Created April 28, 2023 15:03
Adopt most resources into a Helm install
#!/bin/bash
NAME=test
NAMESPACE=default
RESOURCES=service,role.rolebinding # Comma-delimited
kubectl get -n $NAMESPACE $RESOURCES -o name \
| xargs -I % kubectl label -n $NAMESPACE % app.kubernetes.io/managed-by=Helm
kubectl get -n $NAMESPACE $RESOURCES -o name \
| xargs -I % kubectl annotate -n $NAMESPACE % meta.helm.sh/release-name=$NAME
@magickatt
magickatt / gmp_version.py
Created April 19, 2023 15:01
Show GMP (GNU MP Bignum Library) version using Python
# https://stackoverflow.com/a/22981757
import ctypes
so_name='/usr/lib64/libgmp.so.10' # or /usr/lib/libgmp.so, etc
var_name='__gmp_version'
L=ctypes.cdll.LoadLibrary(so_name)
v=ctypes.c_char_p.in_dll(L,var_name)
print(v.value)