Skip to content

Instantly share code, notes, and snippets.

@marjamis
marjamis / names.txt
Last active December 15, 2022 08:33
Possible project names
hound
sleuth
waldo
snoop/snooper
seeker
@marjamis
marjamis / sha256sum-duplication-checker.sh
Last active September 24, 2022 04:23
Bash scripts and examples
#!/bin/sh
SHA256SUMS_FILE="./sha256_sums"
UNIQ_COUNTS_SORTED="./uniq_counts_sorted"
find . -type f -exec sha256sum {} \; > $SHA256SUMS_FILE
cat $SHA256SUMS_FILE | sort -k1 | cut -f1 -d\ | uniq -c | sed "s:^ *::g" | sort -rk1 > $UNIQ_COUNTS_SORTED
IFS="
@marjamis
marjamis / Dockerfile.build-go
Last active April 20, 2023 09:39
Starter application files
FROM golang:1.19 as build
WORKDIR /go/src/
COPY go.* .
RUN go mod download
COPY . .
# --mount flag allows for speedier builds of the binary
RUN --mount=type=cache,target=/root/.cache/go-build CGO_ENABLED=0 GOOS=linux go build -o app main.go
# Final image in the build process
@marjamis
marjamis / wordle-starting-word.txt
Last active July 27, 2024 12:52
Todays starting wordle word example
nitro
@marjamis
marjamis / Makefile.cert-generation
Last active September 27, 2023 23:52
TLS Certificate generation for webserver. Not to be used for production as the settings need heavy reviewing before that step
.DEFAULT_GOAL := helper
# Uses the required .env for docker-compose to find root location.
CERTS_LOCATION ?= $(shell cat .env | grep -i CERTS_LOCATION | cut -f2 -d\=)
CA_LOC ?= $(CERTS_LOCATION)/ca
# Default location for client certificates to be stored.
CLIENT_LOC ?= $(CERTS_LOCATION)/client_certificates_remote
# Specific files for easier reference and changes. May change this in the future.
CA_CRT ?= $(CA_LOC)/ca.crt
@marjamis
marjamis / Corefile
Last active September 24, 2022 04:26
CoreDNS Example
(global_configurations) {
log {
class all
}
errors
cache
prometheus :9153
}
coredns.io:5300 {
@marjamis
marjamis / curl_eks.sh
Created January 6, 2022 01:23
Curled EKS endpoint with a Bearer Token and the appropriate public certificate
export CLUSTER="test"
PAYLOAD=$(aws eks describe-cluster --name $CLUSTER --query 'cluster.{CA: certificateAuthority.data,Endpoint: endpoint}')
echo $PAYLOAD | jq -rc .CA | base64 -D > /tmp/public_cert
ENDPOINT=$(echo $PAYLOAD | jq -rc .Endpoint)
curl -v --cacert /tmp/public_cert -H "Authorization: Bearer "$(aws eks get-token --cluster-name $CLUSTER | jq -rc .status.token) $ENDPOINT/api/v1/namespaces/default/pods/
## Additional curl options
curl -X GET --cacert /var/lib/kubelet/pods/<podId>/volumes/kubernetes.io~secret/<kube-proxy token secret>/ca.crt -H "Authorization: Bearer $(cat token)" https://<endpoint IP>:443/api/v1/endpoints
kubectl -n kube-system create serviceaccount kube-dns
@marjamis
marjamis / Makefile.manual-docker-image
Last active September 27, 2023 23:54
Manual creation of a basic docker image with image and repository manifest generation
.DEFAULT_GOAL := helper
BUILD_TIME ?= $(shell date '+%s')
# Useful for colour coding outputs
TEXT_RED = \033[0;31;1m
TEXT_BLUE = \033[0;34;1m
TEXT_GREEN = \033[0;32;1m
TEXT_PURPLE = \033[0;35;1m
TEXT_NOCOLOR = \033[0m
@marjamis
marjamis / docker_registry.sh
Last active January 5, 2022 02:00
Sample curl commands for accessing registries
export DOCKER_REGISTRY_USERNAME="marjamis"
export REPOSITORY="test"
# Note: If using the base64 command doesn't work here you can run a docker login with your credentials and then copy the base64 value from the file: ~/.docker/config.json
export TOKEN=$(curl -H "Authorization: Basic <base64 of docker hub username:password>" "https://auth.docker.io/token?service=registry.docker.io&scope=repository:$DOCKER_REGISTRY_USERNAME/$REPOSITORY:pull,push" | jq .)
# Get the manifest of a specific image
curl -LH "Authorization: Bearer $TOKEN" https://index.docker.io/v2/$DOCKER_REGISTRY_USERNAME/$REPOSITORY/manifests/<tag or digest> | jq .
# Get a list of tags for images in this repository
@marjamis
marjamis / git_stats.sh
Created November 23, 2021 02:36
Basic way to build up generating of git stats with bash with JSON output. Just an example...
#!/bin/bash
# echo "## Each files last update, sorted from oldest to newest"
# cd .. && git ls-tree -r --name-only HEAD | while read filename; do echo "$(git log -1 --format="%aI" -- $filename) $filename"; done | sort -rk1
function lastCommit {
git log -1 --format=%cI
}
function addNumber {