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 / play.go
Created November 8, 2017 22:28
Neat way to do configuration in Golang
package main
import (
"encoding/json"
"errors"
"fmt"
"reflect"
"github.com/tidwall/gjson"
)
20:57:08 $ curl -v 'http://www.google.com/' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36' --compressed > /dev/null
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Trying 172.217.6.36...
* TCP_NODELAY set
* Connected to www.google.com (172.217.6.36) port 80 (#0)
> GET / HTTP/1.1
> Host: www.google.com
> Accept: */*
@abraithwaite
abraithwaite / Dockerfile.mysql
Created August 21, 2018 16:39
Postgres and MySQL Dockerfile trick
FROM mysql
COPY migrations /migrations
RUN cp /migrations/*.up.sql /docker-entrypoint-initdb.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"
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 / 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() {
@abraithwaite
abraithwaite / chill-zoom.sh
Last active December 12, 2024 09:16
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"
export interface Result<T> {
success: true
data: T
}
export interface InternalError {
success: false
user: false
error: string
}
@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",'
@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