Notes

This page contains various notes I've collected on various (technical) subjects. That can be small code snippets, handy commands etc.

Filter by subject:
CSS
Force a "hand" cursor
cursor: pointer;
Debian
Up-to-date Nvidia driver on Debian stable

Debian Stable is an excellent operating system, but rarely backports new Nvidia driver updates, which you might want for new driver features etc. for gaming. Nvidia provides a repository for its CUDA computing platform for Debian that includes up-to-date driver packages, and installs cleanly as an upgrade to the Debian-provided packages. Note that you might get "beta" drivers.

For Debian 12 (bookworm) use the following to enable the repository and upgrade:

wget https://developer.download.nvidia.com/compute/cuda/repos/debian12/x86_64/cuda-keyring_1.1-1_all.deb
sudo dpkg -i ./cuda-keyring_1.1-1_all.deb
sudo apt update && sudo apt upgrade

Then reboot.

Fedora
Using screen-bce on Fedora

Turning on bce in screen avoids padding the screen with trailing spaces, which makes copy+paste a lot simpler. It does not work simply by turning bce on, however, it also needs a termcap that tells the applications about this. In Fedora, this termcap isn't installed by default, you need to install the ncurses-term package, once you do everything starts working (to turn bce on add defbce on and term screen-bce to your screenrc).

The vulkan swrast lavapipe driver is being used instead of the nvidia driver

If vulkan doesn't work correctly, vulkan apps are crashing or you're getting "lavapipe is not a conformant Vulkan implementation, testing use only" in the terminal when launching vulkan apps, you've probably hit upon this issue.

Not quite sure where this problem actually comes from, but something is making the vulkan libraries load the software renderer, "lavapipe", instead of the nvidia accelerated driver.

A workaround is to set the environment variable VK_ICD_FILENAMES=/usr/share/vulkan/icd.d/nvidia_icd.json. You can either export VK_ICD_FILENAMES=/usr/share/vulkan/icd.d/nvidia_icd.json in a terminal and launch vulkan apps from there, or add VK_ICD_FILENAMES=/usr/share/vulkan/icd.d/nvidia_icd.json to /etc/environment (requires a relogin or reboot).

GIT
GIT: Files always shown as modified, refusing to be reset (on case-sensitive filesystems)

If you've got a git checkout where a file or set of files are refusing to be reset, that git always thinks have been modified even after git reset --hard, git checkout -f and git restore, then you might have checked out a git repository that contains a file or files whose filenames only differ in their casing, and you've checked them out on a case-insensitive filesystem (ie. macOS). In those cases the path to two different files will be the same, and unless the files contain the same data, git will assume one of them has been changed when checking your working tree. Your best bet to fixing it is to correct the repository on a machine with a case-sensitive filesystem and then checking it out again.

git push with a pre-push hook exits with 141

Exit value 141 means git received SIGPIPE, that is to say the process tried to write to a pipe that was closed. This usually means that your pre-push hook took too long to run, and thus the connection to your upstream provider was closed. You can fix this by making ssh send keepalive messages to your upstream provider. For instance, for gitlab.com, you would add the following to ~/.ssh/config:

Host gitlab.com  
    ServerAliveInterval 60  
    ServerAliveCountMax 10  

Adjust ServerAliveCountMax to around the number of minutes your pre-push hook takes to run.

Label a file for adding some time in the future
git add -N file

This lets git know that you intend to add a file at some later point. This makes the content of the file show up in ie. git diff

Staging partial commits

Lets you stage only parts of the changes made to a file for committing, instead of the entire contents.

Git add --patch FILE
Responses:

y   yes; stage this change
n   no; don't stage this change
s   split; cut the change in smaller parts
e   edit; manually define the part to split
GNOME
GNOME: increase the "unresponsive app" timeout

In GNOME, if you're seeing the "app is not responding" box too frequently (ie. when starting a game through wine/proton), you can increase the timeout that defines how long GNOME will wait before assuming an app is not responding. This is set through the dconf key org.gnome.mutter check-alive-timeout. The value is the number of miliseconds to wait before treating an app as not responding. You can modify it either through the "dconf Editor" or through the commandline (here it is being set to 20 seconds, 20 000 ms):

gsettings set org.gnome.mutter check-alive-timeout 20000
GNOME: Lock and unlock the screen from the commandline
# Lock
dbus-send --session --dest=org.gnome.ScreenSaver --type=method_call --print-reply --reply-timeout=20000 /org/gnome/ScreenSaver org.gnome.ScreenSaver.SetActive boolean:true

# Unlock
dbus-send --session --dest=org.gnome.ScreenSaver --type=method_call --print-reply --reply-timeout=20000 /org/gnome/ScreenSaver org.gnome.ScreenSaver.SetActive boolean:false
Run a script on login in GNOME

Create the following file as ~/.config/autostart/loginAutostart.desktop:

[Desktop Entry]
Version=1.0
Name=loginAutostart
Exec=/home/*username*/bin/loginAutostart
Icon=utilities-terminal
Terminal=false
Type=Application
StartupNotify=false
X-GNOME-Autostart-enabled=true

Make the .desktop-file executable. Then create ~/bin/loginAutostart and make it executable. It will now be run on each login.

GnuPG
Generating a new GPG key

Run gpg --gen-key, select option 1 (RSA and RSA), enter the maximum key size (4096) and then simply follow the rest of the instructions on-screen.

If you intend to use the key for signing you may want to publish it to a keyserver with gpg --keyserver pool.sks-keyservers.net --send-key KEYID where KEYID is the id of the key you just generated. For more in-depth information, see the GnuPG website.

gpg: Quick and dirty

gpg is a powerful encryption tool and can do many useful things, but sometimes you just need a simple tool to encrypt and decrypt data for yourself.

Start with the following alias (in .zshrc or .bashrc, depending on your shell - change to gpg2 if you use gpg2):

alias gpg='gpg --default-recipient-self'

This alias makes the default recipient be you, so if you don't specify one, it will be encrypted for you.

Then to encrypt a file:

gpg -e FILE

And to decrypt it:

gpg -d FILE.gpg -o FILE
ImageMagick
Resize an image to a fixed size while maintaining the aspect ratio

convert file.jpg -resize 800x -background white -gravity center -extent 800x600 file-aspect.jpg

This will pad above/below or to the right/left side of the image with the colour specified as -background, resize the image to the width or height as supplied to -resize and force the image to be the size supplied to -extent.

GNU/Linux (desktop)
Fix disappearing mouse cursor in Alacritty

Some Wayland compositors don't provide Alacritty with the information it needs to find the cursor theme, which results in an invisible mouse cursor when over the Alacritty window. You can work around this by telling Alacritty which cursor theme to use, you can do this either by setting the XCURSOR_THEME environment variable, or by symlinking the cursor theme you want to ~/.local/share/icons/default, ie. for Adwaita (the default Gnome theme) run: ln -sf /usr/share/icons/Adwaita ~/.local/share/icons/default

VirtualBox: Hide the statusbar and menubar
VBoxManage setextradata global GUI/Customizations noMenuBar,noStatusBar
Disable HTML5 video in Epiphany/Webkit2

There's no way to actually disable video support without recompiling, but you can trick gstreamer into thinking there are no video support plugins installed, which essentially allows you to disable video since the browser only tries to load videos if gstreamer tells it that the format is supported. No formats available in gstreamer, no video. You do this by setting the GST_PLUGIN_SYSTEM_PATH_1_0 environment variable to a path that has no gstreamer plugins in it. For instance GST_PLUGIN_SYSTEM_PATH_1_0=/root (which is usually unreadable for users) or GST_PLUGIN_SYSTEM_PATH_1_0=~/.does-not-exist.

Fix choppy video in firefox installed as a flatpak from flathub

You need the ffmpeg-full platform extension. flatpak install org.freedesktop.Platform.ffmpeg-full/x86_64. Note that if there are multiple ffmpeg-full extensions available, you must choose the same version that firefox uses for its runtime. As of november 2021 that's the 21.08 runtime, so the command would be flatpak install org.freedesktop.Platform.ffmpeg-full/x86_64/21.08. You may also want to pin it (to avoid it getting removed) with flatpak pin runtime/org.freedesktop.Platform.ffmpeg-full/x86_64/21.08.

Fix choppy audio when using pipewire while the system is under heavy load
pw-metadata -n settings 0 clock.force-quantum 2048

The low latency of pipewire is what results in this. The above command will temporarily increase it. The Debian Wiki has more details and instructions on how to make the changes permanent if you wish.

Add a tray/statusnotifier icon for Signal

The Signal desktop app has support for a tray/kstatusnotifiericon icon, but does not expose it through the app settings. You can use --use-tray-icon to enable the tray icon or --start-in-tray to both enable the icon and minimize to tray by default.

Enabling "sudo mode" in GNOME
gconftool -t boolean -s /apps/gksu/sudo-mode true
sudo usermod -a -G GROUP [USER]

Group is 'sudo' on Debian, 'wheel' on Mandriva

sudo with X11 programs

Usually speical tools like gksudo does the job fine. However, if that's not available (or broken) you can use sudo XAUTHORITY="$XAUTHORITY" DISPLAY="$DISPLAY" [command] instead.

systemctl refusing to suspend without interactive authentication

Use: sudo systemctl suspend -i --no-ask-password --force

Reason: Issuing something like sudo systemctl suspend -i asks twice for the users password, once through sudo and then again through polkit with an interactive password window on desktops. Adding --no-ask-password results in the error message "Call to Suspend failed: Interactive authentication required." (and still won't suspend). You can work around this by addding --force in addition to --no-ask-password.

Run a command on resume using systemd

This is based upon an example from the Arch Linux wiki.

Create the following systemd service file at /etc/systemd/system/resume@.service:

[Unit]
Description=Resume actions for user %I
After=suspend.target

[Service]
User=%i
Type=simple
ExecStart=/usr/bin/env sudo -u %i /home/%i/bin/resumeAutostart

[Install]
WantedBy=suspend.target

Then enable it for your user systemctl enable resume@**username**.service. You must enable it for each user you want to be able to run something on resume. Then the script ~/bin/resumeAutostart will be run on resume.

GNU/Linux (gaming)
Force use of the discrete GPU for OpenGL on AMD hardware

Certain games will default to the onboard GPU if one is present, instead of using the superior discrete GPU. This makes performance suffer. To force a game to use a discrete gpu set DRI_PRIME=1. In Steam, set launch options to: DRI_PRIME=1 %command%

GNU/Linux (general)
Automatically run a command on boot as a user

cron has an @reboot "time" that you can use, which makes the command run once during boot. This is very handy for running commands after a reboot as a user (in particular if you don't have root access and thus can't edit /etc/rc.local). Example (in your crontab - crontab -e):

@reboot /home/myuser/initCommand
Install a local .deb package (and resolve dependencies)

apt-get and aptitude can't install local packages, and installation with dpkg -i will not install any additional dependencies (requiring an additional apt-get install -f afterwards to resolve the deps).

The gdebi tool can install a local .deb package and resolve, download and install any dependencies (and in case you're wondering, gdebi is not a graphical tool, that's gdebi-gtk, gdebi's gtk front-end).

Logrotate as a user

Logrotate can be used as a user by supplying the --state (-s) parameter, which specifies an alternate location for the logrotate state file. Ie. logrotate --state ~/.logrotate.state ~/.logrotate.conf where ~/.logrotate.conf is your custom logrotate config file (which uses the same syntax as /etc/logrotate.conf).

Rsync "sparse" files (aka. files with holes - ie. kvm/qcow images)

Use the --sparse parameter for rsync. This will let rsync handle those files efficiently. Note however that --sparse can not be used with --inplace.

Run a command as root with sudo without password prompts

Edit sudoers with visudo.

Add the following line: *username* ALL = (root) NOPASSWD: */path/to/command*

Make sure the line comes after any password-requiring lines. The easiest way to make sure is to add it at the bottom of sudoers.

Use xz for logrotate

Add the following to /etc/logrotate.conf to use xz instead of gzip for compressed logfiles:

compresscmd /usr/bin/xz
uncompresscmd /usr/bin/unxz
compressext .xz
Various useful utilities
netselect - find the fastest server from a list of servers
unshare   - remove access to i.e. networking for a single process
nethogs   - simple network statistics
macOS
Blurry Terminus font when used in Alacritty on macOS

If you use the truetype variant of the Terminus font in Alacritty on macOS, it will look blurry. Some posts will recommend setting AppleFontSmoothing to 0, but that doesn't actually help. What you need is to install the bitmap variant of the font, but it needs to be packaged as a dfont for macOS to recognize it. Grab the fonts from https://github.com/Koston-0xDEADBEEF/TerminusBMP (both bold and medium) and copy the files to ~/Library/Fonts. Then configure Alacritty to use it:

[font]
normal = { family = "TerminusBMP-Medium" }
bold = { family = "TerminusBMP-Bold" }
size = 16
mutt
Maildir-indexing for full-text search

notmuch provides a full-text index of maildirs, and can easily be used from within mutt. The tool itself is available from https://notmuchmail.org/ (also packaged as notmuch in most major distros). You'll also need notmuch-mutt (which is also packaged in most major distros, as notmuch-mutt).

To start using it, first run notmuch setup.

I use the following cronjobs to generate the index

# Update mail index every 15 minutes
*/15 * * * *              notmuch new &> /dev/null
# Remove old search results every morning
11 5 * * *                rm -rf "/home/zerodogg/.cache/notmuch/mutt/results"

And the following code in your muttrc, where F7 will do a search and display the results, and F8 will reconstruct a thread from metadata.

macro index <F7> \                                                                                                                                                        
      "<enter-command>unset wait_key<enter><shell-escape>notmuch-mutt --prompt search<enter><change-folder-readonly>`echo ${XDG_CACHE_HOME:-$HOME/.cache}/notmuch/mutt/results`<enter>" \                                                                                                                                                           
      "notmuch: search mail"                                                                                                                                              
macro index <F8> \                                                                                                                                                        
      "<enter-command>unset wait_key<enter><pipe-message>notmuch-mutt thread<enter><change-folder-readonly>`echo ${XDG_CACHE_HOME:-$HOME/.cache}/notmuch/mutt/results`<enter><enter-command>set wait_key<enter>" \                                                                                                                                  
      "notmuch: reconstruct thread"                                                                                                                                       
Perl
A simple one-liner REPL

perl -MData::Dumper -MTerm::ReadLine -e '$r = Term::ReadLine->new(1);while(defined($_ = $r->readline("\$ "))){$ret=Dumper(eval($_));$err=$@;if($err ne ""){print $err;}else{print $ret;}}'

Alias (ie. for use in .bashrc):

alias 'perl-repl'='perl -MData::Dumper -MTerm::ReadLine -e '\''$r = Term::ReadLine->new(1);while(defined($_ = $r->readline("\$ "))){$ret=Dumper(eval($_));$err=$@;if($err ne ""){print $err;}else{print $ret;}}'\'''

screen+tmux
Recreate a deleted screen socket
kill -CHLD <PID>
Recreate a deleted tmux socket
kill -USR1 <PID>
Shell
Detach a process from its terminal in bash/zsh

Bash/ZSH has very powerful job control with its Ctrl-Z, fg and bg commands. A lesser known (but equally powerful) feature is disown. disown will detach a process from its controlling terminal, allowing it to continue running after you have exited your terminal.

Various
Disable «AI» in various places

A collection of ways to disable useless «AI».

ToolHow to
FirefoxIn about:config set browser.ml.enable to false
KagiDisable «Auto quick answer» in the Kagi settings and use the custom CSS snippet from codeberg.org/zerodogg/kagi-no-ai
Windows 11See StellarSands privacy guide for Win11
Websites (robots.txt)See the ai-robots-txt template
Vim
Disable any use of bold fonts
set t_md=
Archive
HOWTO: Using GNOME3 without pulseaudio in Debian 7 (Wheezy)

WARNING: This is completely unsupported. It could completely break your system, and you will probably not get any help from Debian voulenteers or the Debian GNOME maintainers. I do not take any responsibility from any issues or data loss caused by this procedure. PROCEED AT YOUR OWN RISK.

DO NOT report GNOME3 bugs after having used this procedure until after you have reverted back to the official install with pulseaudio, and verified that the issue remains.

Note: I have on purpose assumed a certain level of knowledge in the instructions below. If you can't understand them, then you shouldn't be doing this.

The first step is to get a replacement pulseaudio package. This is because the GNOME packages depend upon the pulsaudio package, and won't let you have it installed unless a pulseaudio package is present. You can create it with the tools found in the equivs-package. For convenience I have uploaded one, you can download it from http://zarb.org/~zerodogg/pulseaudio_2.0_all.deb (it is signed with my gpg key).

After that package has been installed, you're essentially pulseaudio-free (after you kill any existing pulseaudio-processes, which you should do now). To get a volume control back in GNOME, install the volumeicon-alsa-package. Then install the Evil Status Icon Forever GNOME-extension. Now edit ~/.local/share/gnome-shell/extensions/EvilStatusIconForever@bone.twbbs.org.tw/extension.js adding 'volumeicon' to the notification-array. Finally, log out and then back in (or start volumeicon, then restart gnome-shell). You should now have a simple volume icon in the shell, and be running without pulseaudio.

GDM3: Set default session/desktop environment in Debian 6 (Squeeze)

Instead of using .dmrc, Debian 6's GDM3 uses /var/cache/gdm/[USER]/dmrc. Setting your current session to the default one is as simple as running cp ~/.dmrc /var/cache/gdm/$USERNAME/dmrc.

Nicer KDE apps when running under a GTK-based environment (ie. GNOME)
kwriteconfig --file kdeglobals --group Icons --key Theme gnome
kwriteconfig --file kdeglobals --group General --key widgetStyle gtk
Using pulseaudio on a second X server (on Fedora 18)

If you want to run a secondary X server (ie. for gaming), you may run into audio troubles. There are several ways to fix it, the one I'm presenting here is the "easy, but hacky" version. It may have side-effects, and you will likely need to reverse it if you want support from the Fedora community.

First, add your user into the "audio" group. This will let your user write directly to your audio device.

Second, add pax11publish -r to the top of the startup script for your secondary X server. This will ensure you get a fresh pulseaudio server.

Using wine on Fedora with SELinux enabled

Note: On recent Fedora releases, this should no longer be needed

SELinux might become very unhappy if you try to run wine, but there's no reason to disable SELinux. You just need to tweak some SELinux booleans.

First, the one you most likely want is to set the wine_mmap_zero_ignore

sudo setsebool -P wine_mmap_zero_ignore 1

See man wine_selinux for more information about wine_mmap_zero_ignore.

Second another one you may encounter, which is more invasive is mmap_low_allowed, see this bugreport on the Fedora bugzilla for a discussion on the issue, and this wiki article on winehq for information about it from wine's perspective. To enable it, run:

sudo setsebool -P mmap_low_allowed 1