Skip to content

Instantly share code, notes, and snippets.

package imgbench
// Compile (or use GOARCH=arm for cross) with: go test -c
// Run with: ./imgbench.test -test.bench=.
import (
"image"
"image/jpeg"
"os"
"testing"
package main
import (
"archive/zip"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"regexp"
"strings"
@pgaskin
pgaskin / i3-dmenu-windows
Created August 1, 2019 02:00
i3 dmenu script to choose between windows on the current workspace.
#!/bin/sh
fws="$(i3-msg -t get_workspaces | jq -c '[ .[] | select(.focused).num ][0]')"
wnd="$(i3-msg -t get_tree | jq --argjson fws "$fws" -c '[[ .. | select(.>={} and .type == "workspace" and .num == $fws) | .. | select(.>={} and .type == "con" and .name) ] | to_entries | .[] | [.value.id, (.key + 1 | tostring) + ". " + .value.name ]]')"
sel="$(echo "$wnd" | jq -r '.[][1]' | dmenu -i | cut -d '.' -f1)"
test -z "$sel" || cid="$(echo "$wnd" | jq --argjson sel "$sel" -r '.[$sel-1][0]')"
test -z "$cid" || i3-msg "[con_id=$cid]" focus

Regexps for replacing old error stuff with Go 1.13-style things.

  • github.com/pkg/errors.Wrapf: errors\.Wrapf\(([^,]+), ("[^"]+)", ([^)]+)\) -> fmt.Errorf($2: %w", $3, $1)
  • github.com/pkg/errors.Wrap: errors\.Wrap\(([^,]+), ("[^"]+)"\) -> fmt.Errorf($2: %w", $1)
  • fmt.Errorf %v: (fmt\.Errorf\("[^"]+: )%v(", [^)]+\)) -> $1%w$2
Code Description Comment
Complete BISAC Subject Headings List, 2021 Edition Generated on 2022-02-03T17:00:35.308Z from https://bisg.org/page/BISACEdition
ANT000000 Antiques & Collectibles / General
ANT056000 Antiques & Collectibles / Advertising
ANT001000 Antiques & Collectibles / Americana
ANT002000 Antiques & Collectibles / Art
ANT003000 Antiques & Collectibles / Autographs
ANT005000 Antiques & Collectibles / Books
ANT006000 Antiques & Collectibles / Bottles
ANT007000 Antiques & Collectibles / Buttons & Pins
@pgaskin
pgaskin / kobodevices.yaml
Last active July 17, 2023 16:10
Kobo device information based on 4.18.13737
# 1. create top-level classes from Device::codeName(QString)
# 2. split into legacy and current based on if class in Device::getDeviceClassString() is based on Device::codeName
# 3. add legacy families under top-level classes, codename=classname and Name is from Device::getDeviceClassString()
# 4. add legacy device ids under families from Device::codeName(QString)
# 5. skip current families for now, add device ids from Device::codeName(QString)
# 6. add device names from known values to those devices
# 7. split current devices into families based on Device::codeName(bool), remaining ones have a matching classname
# 8. add family names from Device::getDeviceClassString()
#
# 9. add full values for most specific (codename, then classname) thingies from Image::sizeForType(Device)
@pgaskin
pgaskin / .savefile.go
Last active December 30, 2020 08:31
Save file reader implemented in Go for various games.
// Save file reader implemented in Go for various games.
// - Titanfall 2
// - Dragon Age: Inquisition
// - STAR WARS Jedi: Fallen Order
@pgaskin
pgaskin / loginsrv.tmpl.html
Last active January 28, 2020 03:45
Improved loginsrv template. https://sso.geek1011.net.
{{- /* Template config options */ -}}
{{- /* $internal_group, if set, will show $internal_group_msg to all users not in the specified group. */ -}}
{{- $internal_group := "internal" -}}
{{- /* internal_group_msg shows for users who are not in $internal_group */ -}}
{{- $internal_group_msg := "You are logged in as an external user, and may not have access to all resources." -}}
{{- /* End template config options */ -}}
@pgaskin
pgaskin / qdatastream.go
Last active December 30, 2020 08:21
Go Qt 5.2 QDataStream reader implementation.
package main
import (
"bytes"
"encoding/binary"
"encoding/hex"
"encoding/json"
"fmt"
"io"
"net/url"
@pgaskin
pgaskin / armelfplt.go
Last active December 30, 2020 08:23
Resolving ARM PLT entries. See https://github.com/pgaskin/kobopatch/blob/master/patchlib/syms.go for the latest version.
package main
import (
"debug/elf"
"encoding/binary"
"fmt"
"io"
"os"
"github.com/ianlancetaylor/demangle"