Skip to content

Instantly share code, notes, and snippets.

View samj's full-sized avatar

Sam Johnston samj

View GitHub Profile

Keybase proof

I hereby claim:

  • I am samj on github.
  • I am samj (https://keybase.io/samj) on keybase.
  • I have a public key ASBDf_aG6MdbtOwsHS8CU8SoUNYowR8YZaPQgnTND3NFzQo

To claim this, I am signing this object:

@samj
samj / Tailscale.sh
Created September 17, 2024 22:11
Tailscale on Qnap with Exit Node and Advertise Routes
#!/bin/sh
CONF=/etc/config/qpkg.conf
SOCKET=/tmp/tailscale/tailscaled.sock
QPKG_NAME="Tailscale"
QPKG_ROOT=`/sbin/getcfg ${QPKG_NAME} Install_Path -f ${CONF}`
QPKG_PORT=`/sbin/getcfg ${QPKG_NAME} Service_Port -f ${CONF}`
export QNAP_QPKG=${QPKG_NAME}
set -e
case "$1" in
@samj
samj / gpg-pinentry-1password.sh
Created August 21, 2024 14:57
gpg pinentry protocol implementation for 1Password
#!/bin/bash
# gpg pinentry protocol implementation for 1Password
# expects gpg passphrase to be the password of a login item
# with username containing the gpg key id (eg 188E5DC27A54FA25)
# and a 'gpg-key' tag
#
# add to ~/.gnupg/gpg-agent.conf:
# pinentry-program /path/to/gpg-pinentry-1password.sh
@samj
samj / gist:66a2e8c601d4ada405080a227935cb0a
Created July 15, 2024 14:34
pinentry program for gpg to access a 1password item via its CLI (op)
#!/bin/bash
# Set your vault ID and item ID
ACCOUNT_ID="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
VAULT_ID="abcdefghijklmnopqrstuvwxyz"
ITEM_ID="abcdefghijklmnopqrstuvwxyz"
# Authenticate with 1Password (if not already authenticated)
# Retrieve the passphrase from 1Password
blueprint:
name: Set door codes webhook
description: >
Webhook that sets a door code slot on multiple lock entities using set_usercode.
IMPORTANT: When setting up this automation, click the gear icon beside the Webhook ID
to choose whether the webhook is 'Only accessible from the local network'.
domain: automation
input:
secret_token:
name: Secret Token
@samj
samj / battery-health-check.py
Created November 27, 2023 11:18
A Python script to monitor MacBook battery health. It checks the battery's maximum capacity and sends a macOS notification if the capacity falls to 80% or below. Useful for keeping an eye on battery health and knowing when it might be time to consider servicing or replacing the MacBook's battery.
#!/usr/bin/env python3
import subprocess
import re
import os
def get_battery_health():
# Run the system_profiler command to get battery information
result = subprocess.run(["/usr/sbin/system_profiler", "SPPowerDataType"], capture_output=True, text=True)
output = result.stdout