Skip to content

Instantly share code, notes, and snippets.

View klingtnet's full-sized avatar
a damn fine cup of coffee

Andreas Linz klingtnet

a damn fine cup of coffee
View GitHub Profile
  • Most information was taken from the [release notes].
  • Release is schedules for February 2023. Releases happened between 16th and 25th in the past, so I assume that 1.20 will be released end of February as well.

Context

Package context received WithCancelCause which allows to cancel a context with a given error. This is pretty nice to have something more meaningful than the usual context.Canceled error, that won't tell you anything about why something got canceled. (playground)

Errors

@klingtnet
klingtnet / packagestats.go
Created December 17, 2021 18:19
List all packages in a Go module
package main
import (
"fmt"
"io/fs"
"log"
"os"
"path/filepath"
"sort"
"strings"
@klingtnet
klingtnet / ryzen-random-reboots-fix.md
Last active November 22, 2022 07:59
Ryzen Linux random reboots in idle state

My Ryzen 7 3700X desktop machine had random reboots when in idle. Stress tests worked fine over many hours, no problem there. There's a Gentoo Wiki entry that recommends to set idle=nomwait and processor.max_cstate=5. For me, it did not work and neither did the tips from this kernel Bug report. Those random reboots disappeared after I reset my BIOS to optimized factory defaults. The only change I apply to those factory defaults is to apply the XMP profile of memory modules. It turned out that, if the XMP settings were applied, the random reboot appeared again. Luckily i stumbled over this linustechtips forum thread where someone said that power down mode needs to be disabled. Someone else said that they fixed this issue by setting the RAM voltage to 1.36V instead of 1.35V. Anyways, disabling _power down mod

@klingtnet
klingtnet / rclone-galcier-type-scaleway-backup-restore.md
Created August 14, 2021 10:59
A note on restoring glacier type backups with rclone and scaleway

Restoring backups with rclone that are stored as [C14/Glacier cold storage][glacier] on Scaleway will fail with Failed to copy: failed to open source object: AccessDenied: Access Denied..

# create backup
$ rclone --s3-storage-class=GLACIER sync backup/ scaleway-encrypted:
...
# try to restore
$ rclone --s3-storage-class=GLACIER sync scaleway-encrypted: backup/
Failed to copy: failed to open source object: AccessDenied: Access Denied.
...
@klingtnet
klingtnet / imagediff.go
Last active April 27, 2021 06:18
Image comparison using MagickWand/ImageMagick in Go
package main
import (
"log"
"gopkg.in/gographics/imagick.v3/imagick"
)
func run(refFile, srcFile, prefix string) (err error) {
refMW := imagick.NewMagickWand()
@klingtnet
klingtnet / pipewire-on-arch-linux-gnome.md
Last active September 11, 2022 18:35
Pipewire on Arch Linux (Gnome)

Those are the only instructions I need to run to have a fully working Pipewire setup that is compatible with PulseAudio, Jack and ALSA:

$ yay -Rcns pulseaudio-jack
# note that pipewire-jack-dropin is an AUR package
$ yay -S pipewire-{jack,jack-dropin,alsa,pulse}
$ systemctl --user enable pipewire pipewire-pulse pipewire-media-session
$ systemctl reboot
# done
@klingtnet
klingtnet / rl.go
Last active December 1, 2020 19:22
Read random lines from a file
// inspired by https://github.com/miku/randlines
package main
import (
"errors"
"io"
"log"
"math/rand"
"os"
"strconv"
@klingtnet
klingtnet / throttle-amd-gpu-fan.sh
Created November 17, 2020 16:21
Throttle AMD GPU fan under linux
#!/usr/bin/env bash
# https://wiki.archlinux.org/index.php/Fan_Speed_Control#AMDGPU_sysfs_fan_control
set -eu
PWM_CONTROLS=$(find /sys/class/drm/card0/device/ -iname 'pwm?' -type f)
for pwm_control in "$PWM_CONTROLS"; do
# echo 2 to reset to auto
echo 1 >"${pwm_control}_enable"
cat "${pwm_control}_min" >"$pwm_control"
package main
import (
"bytes"
"fmt"
"io"
"io/ioutil"
nurl "net/url"
"os"
"path/filepath"
@klingtnet
klingtnet / README.md
Last active August 29, 2020 19:59
You can not overwrite command line arguments with Go

You can not overwrite command line arguments with Go

The code above will not change what is printed when running xargs -0 <\ /proc/<PID>/cmdline. This is likely because os.Args is a slice copy of the actual command line arguments: https://github.com/golang/gofrontend/blob/289d94b9e6303ec74649d1f08d418300f2b4d0fd/libgo/go/runtime/runtime.go#L61 You may ask why anyone want's to do this, e.g. MySQL is overwriting passwords passed from the command line such that they can not be read with the method above, at least not after process initialization is finished:

On some systems, your password becomes visible to system status programs such as ps that may be invoked by other users to display command lines. MySQL clients typically overwrites the command-line password argument with zeros during their initialization sequence.

Conclusion: Use [environment variables to pass secrets](https://security.stackexchange.com/questions/14000/environ