Skip to content

Instantly share code, notes, and snippets.

[\[][Uu][Rr][Ll]=["]?([^"\]]+)["]?[\]] => <a href="$1">

[\[][/][Uu][Rr][Ll][\]] => </a>

[\[][Uu][Rr][Ll][\]]([^\[]+)[\[][/][Uu][Rr][Ll][\]] => <a href="$1">$1</a>

[\[](/)?[Bb][\]] => <$1b>

[\[](/)?[Ii][\]] => <$1i>

@pgaskin
pgaskin / xob.go
Last active April 6, 2021 00:43
A port of github.com/florentc/xob to Go
package xob
import (
"fmt"
"github.com/BurntSushi/xgb"
"github.com/BurntSushi/xgb/xproto"
)
// ported from github.com/florentc/xob@d6ca69d6a45a9c1ac1c99e00357d0df32f956f19 (GPLv3)
FROM opensuse/tumbleweed AS mingw32
RUN zypper --non-interactive addrepo https://download.opensuse.org/repositories/windows:mingw:win32/openSUSE_Tumbleweed/windows:mingw:win32.repo && \
zypper --non-interactive --gpg-auto-import-keys refresh
RUN zypper --non-interactive install \
wget m4 git-core meson bsdtar gzip xmlstarlet \
mingw32-filesystem mingw32-cross-gcc mingw32-cross-gcc-c++ mingw32-cross-binutils mingw32-cross-pkgconf && \
zypper clean
FROM i386/alpine AS wine
ENV WINEDEBUG="-all" \
@pgaskin
pgaskin / LithiumDictionary.js
Last active January 2, 2025 14:19
Dictionary mod for the Lithium EPUB Reader Android app (it also works on arbitrary webpages).
/*
* Copyright 2019-2021 Patrick Gaskin
* Licensed under the MIT license.
* Requires WebView 4.4.4+.
* Requires an instance of https://github.com/pgaskin/dictserver.
*/
'use strict';
var Dictionary = function () {
var Popup = function () {
package date_stuff
func PrintCalendar(d time.Time, l *time.Location, s time.Weekday) {
d = d.In(l)
start := time.Date(d.Year(), d.Month(), 1, 0, 0, 0, 0, l) // inclusive
for start.Weekday() != s {
start = start.AddDate(0, 0, -1)
}

vncviewer-android-patch

This script patches VNC Viewer 3.7.1.44443.

Patches

  • Fix double-backspace bug on certain keyboards (e.g. recent GBoard versions).
  • Write all log messages to logcat (for debugging, since the default file log option doesn't include all log messages, e.g. key/mouse events).

Requirements

  • Java 1.8+
  • APKTool v2.5.0+
@pgaskin
pgaskin / restic-systemd.md
Last active March 4, 2025 19:14
Secure restic backups with systemd.

restic systemd configuration

  1. sudo install -Dm644 restic@.service /etc/systemd/system/.
  2. For each target:
    • Place the options (exclude, etc) and paths in the variable BACKUP_OPTIONS="..." in /etc/restic/TARGET/config. Newlines can be escaped with backslashes.
    • Place the repository path in /etc/restic/TARGET/repository.
    • Place the repository password in /etc/restic/TARGET/password.
  3. To run the backups on a schedule, create a .timer file in /etc/systemd/system/ based on restic.timer.example, set the schedule and target unit, then systemctl enable --now whatever.timer.
  4. To run the backups manually, just systemctl start it.
@pgaskin
pgaskin / Base32.java
Created June 2, 2021 06:03
Java base32 decode.
import java.io.ByteArrayOutputStream;
class Base32 {
public static byte[] decode(String str) {
ByteArrayOutputStream s = new ByteArrayOutputStream(str.length());
for (byte c : str.getBytes())
if (!Character.isWhitespace(c))
s.write(Character.toUpperCase(c));
@pgaskin
pgaskin / cdputil.go
Last active September 27, 2021 03:58
Some useful helpers for chromedp.
// Package cdputil contains some useful helpers for chromedp.
package cdputil
import (
"context"
"errors"
"fmt"
"strings"
"time"
@pgaskin
pgaskin / interceptsl.go
Last active December 31, 2021 06:54
Go function to intercept escape sequences to set the terminal title.
package main
// interceptsl intercepts escape sequences to set the terminal title.
func interceptsl(ctx context.Context, w io.Writer, r io.Reader, title chan<- string) error {
state := 0
ibuf := make([]byte, 256)
tbuf := make([]byte, 256)
obuf := make([]byte, 256) // will use up to cap(ibuf) + cap(tbuf) + 4 in certain situations
for {