Skip to content

Instantly share code, notes, and snippets.

@kwsp
kwsp / SanePowerShell.ps1
Last active April 11, 2024 19:30
Person PowerShell config to restore some unix sanity. This complements the unix utilities provided by Git for Windows.
Set-PSReadlineOption -EditMode Emacs
Set-Alias vim nvim
Set-Alias python3 python
# Some unix shell hacks
Function which([string]$Name) { Get-Command $Name }
Function open($Name) { start $name }
Function l() {ls -Force}
# Git shortcuts from zsh git plugin
@kwsp
kwsp / Add "outline" to a PDF file.md
Last active November 6, 2021 04:38
Add outline/bookmark to a PDF file for easy navigation.

Add "outline" to a PDF file

Install pdftk

Dump the metadata of the pdf file:

pdftk [pdf_to_update] dump_data_utf8 > meta.txt
@kwsp
kwsp / gpu_mon.py
Last active March 23, 2021 14:06
nvidia-smi in the browser, useful for monitoring a remote GPU server
import asyncio
import subprocess
from fastapi import FastAPI, WebSocket
from fastapi.responses import HTMLResponse
def nvidia_smi():
try:
msg = subprocess.run(
@kwsp
kwsp / Nginx jupyter lab proxy
Created March 23, 2021 13:57
Nginx jupyter lab proxy setup. Use CertBot to get SSL encryption.
upstream nb {
server 10.19.0.10:1234;
}
server {
server_name example.com;
location / {
proxy_pass http://nb;
proxy_set_header Host $host;
@kwsp
kwsp / install_neovim_nightly.sh
Created March 7, 2021 07:47
Script to install NeoVim nightly appimage on a distro that does not package it.
#!/bin/bash
# Installs the nightly NeoVim app image to /opt and symlink to /usr/local/bin
# This is the easiest way to install NeoVim nightly on a distro that doesn't package it.
# Should be run as root
if [ "${EUID:-$(id -u)}" -ne 0 ]; then
echo Please run as root.
exit 1
fi
@kwsp
kwsp / async_downloader.py
Created February 21, 2021 08:05
Asycio bulk file download
#!/usr/bin/env python3
"""Asynchronously download a list of links."""
from typing import Iterable
import asyncio
import logging
import pathlib
import sys
import aiofiles
@kwsp
kwsp / grub_set_kernel_version.md
Last active November 1, 2020 14:21
GRUB boot into a specific version of the linux kernel on Debian Testing (Bullseye)

Nvidia drivers don't yet support linux kernel 5.9.* and a power outage in my house caused my server running Debian Testing (Bullseye) to reboot and upgrade to the latest kernel. The prices I pay for up-to-date software . . .

To use my Nvidia card I have to downgrade to the 5.8.0 kernel. I use the simple and reliable solution below. You need to be able to plug a display and keyboard into your machine though for the last part.

  1. Add the following line to /etc/default/grub. This tells GRUB to save whatever setting you change on the GRUB screen during boot.
GRUB_SAVEDEFAULT=true
GRUB_DEFAULT=saved
@kwsp
kwsp / cuda_debian.md
Last active November 1, 2020 14:05
Fix broken cuda install on Debian Testing (Bullseye, Linux 5.8.0)

Remove any existing nvidia packages. (Note: Run this in bash, as the wildcard input to apt-get doesn't work in zsh)

sudo apt-get purge nvidia*

Update package listing and upgrade packages.

sudo apt update