Skip to content

Instantly share code, notes, and snippets.

View sjlongland's full-sized avatar

Stuart Longland sjlongland

View GitHub Profile
@sjlongland
sjlongland / asyncioexample.py
Last active October 26, 2025 00:39
Running a background AsyncIO thread without blocking main thread
#!/usr/bin/env python3
import threading
import functools
import logging
import asyncio
import time
import sys
@sjlongland
sjlongland / gh36273-4.4.5.patch
Created October 14, 2025 10:35
Mastodon GH36273 fix backported to Mastodon 4.4.5
diff --git a/app/lib/request.rb b/app/lib/request.rb
index 4858aa4bc..de67d1659 100644
--- a/app/lib/request.rb
+++ b/app/lib/request.rb
@@ -65,6 +65,7 @@ class Request
# and 5s timeout on the TLS handshake, meaning the worst case should take
# about 15s in total
TIMEOUT = { connect_timeout: 5, read_timeout: 10, write_timeout: 10, read_deadline: 30 }.freeze
+ SAFE_PRESERVED_CHARS = '+,'
@sjlongland
sjlongland / board.dts
Created September 18, 2025 02:23
RS-485 on Zephyr
&uart0 {
compatible = "nordic,nrf-uarte";
status = "okay";
current-speed = <115200>;
pinctrl-0 = <&uart0_default>;
pinctrl-1 = <&uart0_sleep>;
pinctrl-names = "default", "sleep";
/*
@sjlongland
sjlongland / mains-ctl.sh
Created August 31, 2025 03:17
Controlling a 240V battery charger with a TS-7670 MODBUS 24V switch
#!/bin/sh
# Controlling the 24V power MOSFETs in the TS-7670
# for 240V solid-state relay control.
#
# © 2025 Stuart Longland VK4MSL
# GPIOs for the various control lines.
# References:
# - https://cdn.embeddedts.com/resource-attachments/ts-7670-schematic.pdf
@sjlongland
sjlongland / inetstatus.sh
Created March 10, 2025 14:58
Internet status check for PPPoE on OpenBSD
#!/bin/sh
INTERFACE=pppoe0
CACHEDIR=/var/cache/inetstatus
LASTSTATE=${CACHEDIR}/last
date=$( TZ=UTC date "+%Y-%m-%dT%H:%M:%SZ" )
eval $(
ifconfig ${INTERFACE} \
| sed -ne '/sid:/ { s/^.*PADI retries: \([0-9]*\) PADR retries: \([0-9]*\) *.*$/padi=\1 padr=\2/; p; }; /status:/ { s/^.*: \(.*\) *$/status="\1"/; p; }'
@sjlongland
sjlongland / gist:4fa62cd5dd1e8351212c4f5d03eeceaf
Created October 5, 2024 04:21
Samsung N150+ dmesg (DragonFlyBSD 6.4)
Copyright (c) 2003-2022 The DragonFly Project.
Copyright (c) 1992-2003 The FreeBSD Project.
Copyright (c) 1979, 1980, 1983, 1986, 1988, 1989, 1991, 1992, 1993, 1994
The Regents of the University of California. All rights reserved.
MPTABLE: warning duplicated PCI int entry for bus 0, dev 29, pin 0
MPTABLE: warning duplicated PCI int entry for bus 0, dev 31, pin 1
DragonFly v6.4.0-RELEASE #54: Fri Dec 30 09:06:50 PST 2022
[email protected]:/usr/obj/usr/src/sys/X86_64_GENERIC
acpi_hpet: frequency 14318180
Using cputimer HPET for TSC calibration
@sjlongland
sjlongland / README.md
Created July 18, 2024 07:48
SVG Template engine in Python

Proof of concept SVG template engine

This is an attempt to do SSTV images using SVG-based templates. The idea is to be able to create "message images" that just contain arbitrary text, and "reply images" which are used to respond to a transmission.

Usage

Edit the template template.svg to taste, putting in your details for things like the call-sign.

@sjlongland
sjlongland / locator.py
Last active July 18, 2024 02:32
Get the current maidenhead grid locator from gpsd in Python
#!/usr/bin/env python3
"""
Retrieve the current maidenhead grid locator from gpsd and return it.
© 2024 Stuart Longland VK4MSL
License: BSD-3-clause
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
@sjlongland
sjlongland / mastodon-v4.2.9-5k.patch
Created June 22, 2024 20:38
Patch to increase post limit on Mastodon 4.2.9 to 5000 characters
diff --git a/app/javascript/mastodon/features/compose/components/compose_form.jsx b/app/javascript/mastodon/features/compose/components/compose_form.jsx
index 9222b2dc8..962310a28 100644
--- a/app/javascript/mastodon/features/compose/components/compose_form.jsx
+++ b/app/javascript/mastodon/features/compose/components/compose_form.jsx
@@ -100,7 +100,7 @@ class ComposeForm extends ImmutablePureComponent {
const fulltext = this.getFulltextForCharacterCounting();
const isOnlyWhitespace = fulltext.length !== 0 && fulltext.trim().length === 0;
- return !(isSubmitting || isUploading || isChangingUpload || length(fulltext) > 500 || (isOnlyWhitespace && !anyMedia));
+ return !(isSubmitting || isUploading || isChangingUpload || length(fulltext) > 5000 || (isOnlyWhitespace && !anyMedia));
@sjlongland
sjlongland / multicast.py
Created June 22, 2024 11:02
Python asyncio multicast bi-directional communication example
#!/usr/bin/env python3
"""
Very simple multicast IPv6 socket implementation in asyncio.
Allows for transmission and reception of UDPv6 datagrams to and from multicast
groups.
"""
# © 2024 Stuart Longland <[email protected]>