Skip to content

Instantly share code, notes, and snippets.

@tsjk
tsjk / BisqEasyBuyerAsTakerProtocol.md
Created March 7, 2025 12:54
BisqEasyBuyerAsTakerProtocol
stateDiagram-v2
    state BuyerAsTaker {
        [*] --> TakerSentTakeOfferRequest
        TakerSentTakeOfferRequest --> TakerReceivedOfferResponse: Option 1 - Buyer receives take offer response, then account details can be exchanged in any order.
        TakerReceivedOfferResponse --> BuyerSentBtcAddress: Option 1.1 - Buyer sends btc address first, then seller sends account data.
        TakerSentTakeOfferRequest --> TakerDidNotReceiveOfferResponse: Option 2 - Buyer takes offer and sends btc address right after that. Then receives take offer response and finally seller's account data.
        TakerReceivedOfferResponse --> BuyerReceivedAccountData: Option 1.2 - Seller sends account data first, then buyer sends btc address.
        BuyerReceivedAccountData --> BuyerSentBtcAddressAndReceivedAccountData
        BuyerSentBtcAddress --> BuyerSentBtcAddressAndReceivedAccountData
@tsjk
tsjk / get_lnbits_wallet_balances.sql
Last active February 10, 2025 14:55
Show balances of LNbits wallets
-- Individual wallets
SELECT wallets.name AS wallet_name, SUM(apipayments.amount - ABS(apipayments.fee)) AS balance FROM apipayments
INNER JOIN wallets ON apipayments.wallet = wallets.id
WHERE ((wallets.deleted = FALSE) OR (wallets.deleted IS NULL)) AND
(((apipayments.status = 'success') AND (apipayments.amount > 0)) OR
((apipayments.status IN ('success', 'pending')) AND (apipayments.amount < 0)))
GROUP BY wallets.name;
-- Total
SELECT SUM(COALESCE(apipayments.amount, 0) - COALESCE(ABS(apipayments.fee), 0)) AS total_balance FROM apipayments
@tsjk
tsjk / tdcurl.sh
Created October 13, 2024 18:11
Access Telldus API using curl
#!/bin/bash
[[ "${1^^}" == "GET" || "${1^^}" == "POST" ]] && [[ "${2}" =~ ^/.*$ ]] || exit 2
urlencode () {
[[ -n "${1}" ]] && echo -n "${1}" | perl -p -e 's/([^A-Za-z0-9-._~])/sprintf("%%%02X", ord($1))/seg'
}
#oauth1 vars
consumer_key="..."
@tsjk
tsjk / books-20250228.md
Last active February 28, 2025 12:12
Non-fiction titles for Lund (Audio)Book Club Meetup Group 20250228

New suggestions

Keon West - The Science of Racism: Everything you need to know but probably don't - yet (2025) {352pp} [Goodreads link]

Racism has been on the table before, and we judged it to be an interesting subject. This is a recently published work from a professor of Social Psychology at The University of London. Perhaps a bit closer to our quarters than books focusing on specific American problems.

David DeSteno - How God Works: The Science Behind the Benefits of Religion (2021) {256pp} [Goodreads link]

This book was mentioned in another book I just read (The Anxious Generation: How the Great Rewiring of Childhood Caused an Epidemic of Mental Illness by Jonathan Haidt). I for one have been interested in the topic for a while but haven't really found a book that looked inviting enough. Could this be something?

Nathan H. Lents - The Sexual Evolution (2025) {336pp} [[Goodreads link]](https://ww

@tsjk
tsjk / pdmn-ps.functions
Created September 29, 2023 15:53
Functions for getting process lists and process trees of podman containers from the host's perspective
function pdmn-ps() {
# With this one can do like, given a container called tor-client,
# kill -HUP $(pdmn-ps tor-client | \
# grep -F ' tor -f /config/torrc --defaults-torrc /config/torrc.custom.default' | \
# awk '{ print $2 }')
# Useful for when one has both a client and a relay, and has a smaller overhead than exec-ing into the container.
local container_pid
[[ -n "${1}" ]] && podman container exists "${1}" && { \
container_pid=$(podman inspect --format '{{.State.Pid}}' "${1}")
ps -o 'user,pid,%cpu,%mem,vsz,rss,tty,stat,lstart,time,command' \
@tsjk
tsjk / openwrt-wg0-firewall.sh
Last active September 11, 2023 06:46
Fix of WireGuard routing confusion on OpenWRT
#!/bin/sh
# Intermittently, the routing of WireGuard datagrams seem to become confused, leading to temporarily hung connections.
# This script aims to remedy this - assuming that the OpenWRT system is a
# WireGuard peer that uses the port(s) listed in WG_PORTS. E.g. (/etc/config/network):
# config interface 'wg0'
# option proto 'wireguard'
# option listen_port '51820'
# ...
#
@tsjk
tsjk / ln-fee-info.sh
Created August 22, 2023 09:39
Defines an ln-fee-info() function. Needs the uplot ruby package, sqlite3, bc, jq, working bitcoin-cli, working lightning-cli, and clboss's data. To see the response, you need to call the function.
function ln-fee-info() {
pgrep -u lightning -f '^/usr/bin/lightningd\s.*' &> /dev/null && { \
function o() {
if [[ "${1}" =~ ^.*1$ ]]; then echo "st"
elif [[ "${1}" =~ ^.*2$ ]]; then echo "nd"
elif [[ "${1}" =~ ^.*3$ ]]; then echo "rd"
else echo "th"; fi
}
local -i M N f n p x; local percentile j j_c t x_v; local -A T
local b=$(/usr/bin/timeout -k 35s 30s /usr/bin/lightning-cli --rpc-file=/run/lightning/lightningd.rpc getinfo | jq -r .blockheight)
@tsjk
tsjk / lightning-listconfigs.json
Last active June 11, 2023 13:32
lightning-listconfigs
{
"# version": "23.05-gentoo-r0",
"conf": "/etc/lightning/lightningd.conf",
"lightning-dir": "/var/lib/lightning",
"network": "bitcoin",
"allow-deprecated-apis": true,
"rpc-file": "/run/lightning/lightningd.rpc",
"plugins": [
{
"path": "/usr/bin/clboss",
@tsjk
tsjk / signal-desktop.local
Created February 7, 2023 10:28
Local profile for signal-desktop that enables its tray icon to work with firejail v0.9.72 (Tested on Gentoo) [~/.config/firejail/signal-desktop.local]
ipc-namespace
dbus-user.talk org.freedesktop.portal.Fcitx
dbus-user.talk org.freedesktop.portal.Background
dbus-user.talk org.freedesktop.Notifications
dbus-user.talk org.kde.StatusNotifierWatcher
dbus-user.own org.kde.*
env SIGNAL_DISABLE_GPU=0
env SIGNAL_DISABLE_GPU_SANDBOX=0
@tsjk
tsjk / sdparm-disable_sleep.sh
Last active January 9, 2024 20:17
Disabling of sleep on external disk using sdparm so that they do not disconnect in middle of transactions (e.g. WD_My_Book_25ED)
#!/bin/bash
# Usage: sdparm-disable_sleep.sh <device>
[[ -n "${1}" && -b "${1}" ]] \
&& sdparm --flexible --page=po -l -a "${1}" \
&& { sdparm --set=STANDBY_Z=0 -S "${1}" \
&& sdparm --set=SZCT=$((45*60*100)) -S "${1}" \
&& sdparm --flexible --page=po -l -a "${1}"; }