Skip to content

Instantly share code, notes, and snippets.

View 100xff's full-sized avatar
🐋
chasing the flow state

Fionn 100xff

🐋
chasing the flow state
  • Hong Kong
View GitHub Profile
enable=add-default-case
enable=avoid-nullary-conditions
enable=check-extra-masked-returns
enable=check-set-e-suppressed
enable=check-unassigned-uppercase
enable=require-double-brackets
@100xff
100xff / aws-sso-list-accounts
Created June 7, 2024 08:52
List AWS SSO accounts
#!/bin/bash
set -euo pipefail
access_token="$(jq -r .accessToken < $(ls -1U ~/.aws/sso/cache/*.json | head -n 1))"
aws sso list-accounts --access-token "$access_token" --output table
@100xff
100xff / ssh_instance_connect_config
Created April 8, 2024 18:05
Connect to instance connect instances via ssh i-*
Host i-*
User ubuntu
ProxyCommand bash -c "aws ec2-instance-connect send-ssh-public-key --ssh-public-key file://~/.ssh/id_ed25519.pub --instance-os-user %r --instance-id %h; aws ec2-instance-connect open-tunnel --instance-id %h"
@100xff
100xff / tail@.service
Created March 31, 2024 14:44
Tail logs from a file to the journal
# vim: ft=systemd
[Unit]
Description=Tail %I logs into the journal
After=%i.service
BindsTo=%i.service
[Service]
Type=exec
ExecStart=tail -n 0 -F /path/to/file
@100xff
100xff / git-cocommit
Created January 2, 2024 12:43
Git subcommand to add co-authors to a commit
#!/usr/bin/env bash
# Usage:
# git cocommit -a "Fionn <fionn@github.com>" \
# -a "Another committer <example@example.com>" \
# -- -m "Commit message" ...
set -euo pipefail
declare -a TRAILER_FLAGS
export ZLE_SPACE_SUFFIX_CHARS=$'&|'
@100xff
100xff / stdin_or_file.py
Created September 8, 2023 08:51
Read from stdin or a file in Python, Unix-style
#!/usr/bin/env python3
import sys
with open(sys.argv[1], encoding="utf8") if len(sys.argv) == 2 else sys.stdin as f:
pass
@100xff
100xff / commit_message.regex
Created September 7, 2023 16:51
Good commit message
(?P<subject>(^[A-Z][A-Za-z]+[^ing|ed] )(.{1,50}[^.])$)(\n\n(?P<body>(^.{1,80}$)(\n{0,2})+)*)
@100xff
100xff / no_newlines.sh
Last active March 31, 2024 15:05
List tracked files that don't end in a new line
#!/usr/bin/env bash
set -euo pipefail
function file_ends_with_newline {
[[ $(tail -c1 "$1" | wc -l) -gt 0 ]]
}
function main {
count=0
@100xff
100xff / sync.py
Created October 26, 2022 12:04
Make asynchronous coroutines synchronous
import asyncio
from typing import TypeVar, Any
T = TypeVar("T")
def sync(f: Coroutine[None, None, tuple[T, Any, Any]]) -> T:
return asyncio.run(f)[0]