Skip to content

Instantly share code, notes, and snippets.

View afirth's full-sized avatar

Alastair Firth afirth

View GitHub Profile
@afirth
afirth / gist:8ab37f9a672e1f57388e189a5b7cf219
Last active January 3, 2024 22:00
ubuntu fix deep sleep (change from s2idle)
# check deep is not selected and also available
cat /sys/power/mem_sleep
# temp set
sudo su -
root@:~# echo "deep" > /sys/power/mem_sleep
exit
# test
systemctl suspend -i
kubectl get secret NAME -o json | jq '.data | map_values(@base64d)'
kubectl get secret NAME -o go-template='{{range $k,$v := .data}}{{printf "%s: " $k}}{{if not $v}}{{$v}}{{else}}{{$v | base64decode}}{{end}}{{"\n"}}{{end}}'
@afirth
afirth / ita_parser.sh
Created August 2, 2022 21:32
parse ita matrix json into csv with jq
for f in *.json; do
jq -r '. | .ext.totalPrice, (.itinerary.slices[].segments[] |[.carrier.code, .flight.number, .legs[].origin.code, .legs[].departure, .legs[].destination.code, .legs[].arrival] | @csv)' < $f
done
@afirth
afirth / Makefile
Created May 6, 2022 19:48
Makefile for helm template + kustomize
#!make
include .env
MAKEFLAGS += \
--warn-undefined-variables
SHELL = /usr/bin/env bash
.SHELLFLAGS := -O globstar -eu -o pipefail -c
.SUFFIXES:
# consistent sorting on OSX/nix
Codecov
Product
Solutions
Customers
@afirth
afirth / kustomization.yaml
Created August 21, 2020 20:50
kustomize patch service for NEGs ingress (GKE)
patchesJSON6902:
- target:
version: v1
kind: Service
name: NAME
namespace: NS
patch: |-
- op: add
path: "/metadata/annotations"
@afirth
afirth / gist:fb3b4dcd3ce1db9adc58993ff09cd02d
Created August 13, 2020 15:57
recover staged or reset files in git (ran git add but somehow discarded without committing)
export UNIQUE_CODE=sops_version
#from https://stackoverflow.com/a/14988152/13484536
for b in $(git fsck --lost-found | grep blob | awk '{print $3}'); do git cat-file -p $b | grep -q ${UNIQUE_CODE} && echo $b && git cat-file -p $b && echo; done
@afirth
afirth / gist:35f2e422fd056c776a4463a5948cf6fd
Created July 31, 2020 14:18
JSON logs for ingress-nginx (stackdriver compatible)
log-format-escape-json: "true"
http-snippet: |
map $msec $timestamp_secs { ~(.*)\..* $1; }
map $msec $timestamp_nanos { ~.*\.(?<tsn>.*) "${tsn}000000"; }
log-format-upstream: '{"timestampSeconds":"$timestamp_secs", "timestampNanos":"$timestamp_nanos", "time_epoch":"$msec", "time_iso8601":"$time_iso8601", "remote_addr":"$proxy_protocol_addr", "x-forward-for":"$proxy_add_x_forwarded_for", "request_id":"$req_id", "remote_user":"$remote_user", "bytes_sent":$bytes_sent, "request_time":$request_time, "status":$status, "vhost":"$host", "request_proto":"$server_protocol", "path":"$uri", "request_query":"$args", "request_length":$request_length, "duration":$request_time, "method":"$request_method", "http_referrer":"$http_referer", "http_user_agent":"$http_user_agent" }'
@afirth
afirth / gist:147fe2d1e5d2cd673216c30e96d637e5
Created June 8, 2020 13:41
get latest release from github
.PHONY: sops
SOPS_URL=$(shell curl -s "https://api.github.com/repos/mozilla/sops/releases/latest" | grep -o "http.*sops_.*_amd64\.deb")
sops: $(curl)
wget $(SOPS_URL) -O ~/Downloads/sops.deb
sudo apt install ~/Downloads/sops.deb
@afirth
afirth / view_all_secrets.sh
Last active April 19, 2020 07:39
kubectl view all secrets in namespace
#requires jq >= 1.6
k get secret -o json -n <namespace> | jq -r '.items[] | [.metadata.name, (.data |map_values(@base64d) )]'
# only keys
k get secret -o json -n <namespace> | jq -r '.items[] | [.metadata.name, (.data |map_values(@base64d) )] | to_entries | .[] | [.value] ' | grep ':'
# better format
k get secret -o json -n accounts-web | jq -r '.items[] | [.metadata.name, (.data |map_values(@base64d) )]' | grep --color=never -P '\w'