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
@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 / xfce-hidpi-scaling-commands.sh
Last active October 20, 2021 13:26
XFCE4.14 properly switch scaling factor
# 2 times scaling
$ xfconf-query --channel xsettings --property /Gdk/WindowScalingFactor --set 2 && xfconf-query --channel xfwm4 --property /general/theme --set Default-xhdpi && xfconf-query --channel xsettings --property /Gtk/CursorThemeSize --set 48 && xfce4-panel -r
# normal scaling
$ xfconf-query --channel xsettings --property /Gdk/WindowScalingFactor --set 1 && xfconf-query --channel xfwm4 --property /general/theme --set Default && xfconf-query --channel xsettings --property /Gtk/CursorThemeSize --set 16 && xfce4-panel -r
@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 / Viewsonic-VG2755-2k.md
Created January 14, 2020 15:14
Viewsonic VG2755-2k

Viewsonic VG2755-2k

A 27" WQHD business IPS display: specs.

Often customers report problems about humming or buzzing noises caused by badly designed power supplies when a device is connected and charged via USB-C to a display. One very bad example of this is the Lenovo ThinkVision P27h-10, but also devices from Dell and Philips seem to be noisy when USB-C charging is active. I owned one of the P27h-10 for a short time and the noise was unbearable so I returned the display to the seller. Except that the monitor was very good, sturdy built, crisp and very bright diplay. Nonetheless, I wanted to have a display where I can connect my X1 through a single cable.

The Viewsonic VG2755-2k works fine when connected via USB-C, it can provide up to 60W charging power (15W more than the Lenovo) and makes absolutely no noise.

@klingtnet
klingtnet / vim-overview.md
Created November 7, 2016 11:05
An overview of vim and a list of important commands with examples

vim notes

  • the following notes are derived from this awesome presentation
  • a modal text editor
  • modes:
    • normal (default on start)
    • insert
    • visual
    • command mode
  • don't use the arrow keys
@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

@klingtnet
klingtnet / parse.go
Last active August 20, 2020 06:00
How to properly parts of an unknown YAML file in Go
package main
import (
"fmt"
"log"
"os"
"strings"
"gopkg.in/yaml.v2"
)