Skip to content

Instantly share code, notes, and snippets.

View abraithwaite's full-sized avatar
:shipit:
:(){ :|:& };:

Alan Braithwaite abraithwaite

:shipit:
:(){ :|:& };:
View GitHub Profile
@abraithwaite
abraithwaite / aws-run.sh
Created October 25, 2024 15:36
A script to run commands as a given profile using IAM Identity Center (SSO) profiles.
#!/bin/bash -e
# aws-run
# Usage: aws-run <profile-name> -- <command>
#
# To use this script with AWS IAM Identity Center user credentials, follow this guide:
# https://docs.aws.amazon.com/singlesignon/latest/userguide/howtogetcredentials.html#how-to-get-temp-credentials-automatic
#
# When asked for the CLI profile name, choose one that you don't mind typing
# every time you run a command.
@abraithwaite
abraithwaite / git-reach-branch
Created February 28, 2024 03:18
git-read-branch
function git-read-branch() {
git ls-tree -r $1 | grep $2 | awk '{print $3}' | xargs git cat-file blob
}
@abraithwaite
abraithwaite / gh-dl-release
Last active February 9, 2023 17:22 — forked from maxim/gh-dl-release
Download assets from private Github releases
#!/bin/bash
#
# gh-dl-release! It works!
#
# This script downloads an asset from latest or specific Github release of a
# private repo. Feel free to extract more of the variables into command line
# parameters.
#
# PREREQUISITES
#
@abraithwaite
abraithwaite / restic-backup.conf
Last active January 27, 2024 13:14
Automated Restic Backups with CPU+Memory throttling, inspired by: https://fedoramagazine.org/automate-backups-with-restic-and-systemd/
B2_ACCOUNT_ID=XXXXXXXXXXXXXXXXXXXXXXXXX
B2_ACCOUNT_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
RESTIC_REPOSITORY=b2:XXXXXXXXXXXXXXXXXX:/
RESTIC_PASSWORD=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
BACKUP_PATHS="/home/naomi.nagata"
BACKUP_EXCLUDES="--exclude-file /home/rupert/.restic_excludes --exclude-if-present .exclude_from_backup"
RETENTION_DAYS=7
RETENTION_WEEKS=4
@abraithwaite
abraithwaite / nginx.conf
Created June 15, 2022 23:36
nginx structured logging in JSON
http {
log_format json_combined escape=json
'{'
'"ts":"$time_iso8601",'
'"remote_addr":"$remote_addr",'
'"remote_user":"$remote_user",'
'"request_time":"$request_time",'
'"request":{'
'"http_referrer":"$http_referer",'
'"http_user_agent":"$http_user_agent",'
export interface Result<T> {
success: true
data: T
}
export interface InternalError {
success: false
user: false
error: string
}
@abraithwaite
abraithwaite / chill-zoom.sh
Last active May 8, 2024 08:43
Zoom in Systemd Cgroups on Linux. Change the max allocations to fit your workstation.
#!/usr/bin/bash -xe
cat <<EOF > "${HOME}/.config/systemd/user/zoom.slice"
[Slice]
AllowedCPUs=0-4
MemoryHigh=6G
EOF
cat /usr/share/applications/Zoom.desktop | sed -E 's#^(Exec=).*$#Exec=/usr/bin/systemd-run --user --slice=zoom.slice /opt/zoom/ZoomLauncher#' > "${HOME}/.local/share/applications/Zoom.desktop"
@abraithwaite
abraithwaite / LinkBankButton.tsx
Last active March 24, 2021 15:31
Simple PlaidLink Example
import * as React from 'react';
import { Button } from 'antd';
import { PlaidLink, usePlaidLink } from 'react-plaid-link';
export const LinkBankButton = () => {
const [token, setToken] = React.useState<string>("");
React.useEffect(() => {
async function loadToken() {
package dsn
type DSN string
func (d DSN) String() string {
i := strings.Index(string(d), "&password=")
if i == -1 {
return string(d)
}
ret := []byte(d)
@abraithwaite
abraithwaite / slicequeue.go
Last active September 10, 2018 22:25
Slice based Queue in Go
package main
import (
"bufio"
"fmt"
"net/http"
_ "net/http/pprof"
"os"
"reflect"
"runtime"