Skip to content

Instantly share code, notes, and snippets.

@kbauer
kbauer / _rescale.py
Created September 9, 2017 15:04
Rescale Mount & Blade maps - A python 3.6+ script for rescaling the world map. Performed by multiplying the positions of all "parties" (cities, spawn points, bridges, ..., and actual parties) and map vertices (the geometry of the world map) by a factor. Factors below 0.7 will look cramped. Used by running the script in the module directory. The …
#!/usr/bin/env python3
import os
import shutil
import re
import sys
import contextlib as cl
import time
@kbauer
kbauer / tree.bash
Last active August 11, 2017 09:55
A pure bash implementation of the `tree` utility, for when the `tree` binary isn't available. Avoids subshells or subprocesses to improve performance.
#!/usr/bin/env bash
# A fallback, when GNU tree isn't installed.
# Example:
# >>> mkdir -p {A1,A2}/{B1,B2/C1}
# >>> touch A2/B3
# >>> my-tree
# .
# |-- A1
@kbauer
kbauer / display-spotlight.bash
Created August 10, 2017 15:02
Display the uncropped images from Windows Spotlight (lockscreen) in a temporary directory with Windows Explorer. Implemented as `bash` script to be run in Cygwin. Requires image-magick to be installed.
#!/usr/bin/env bash
# -*- coding: iso-safe-unix -*-
set -e -E -u
#### SETTINGS
SPOTLIGHT_PATH="$(cygpath $LOCALAPPDATA)/Packages/Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy/LocalState/Assets"
OUTPUT_PATH='/tmp/SPOTLIGHT_DISPLAY'
#### CODE
@kbauer
kbauer / unicode.ahk
Created June 20, 2017 11:30
Autohotkey-script for converting LaTeX-like input to unicode characters. "Ctrl+Alt+Shift+U" toggles it on and off.
;; -*- mode: text; coding: utf-8 -*-
;;
;; DO NOT EDIT MANUALLY!
;;
;; FILE IS GENERATED BY EMACS LISP SCRIPT
;; `%((file-name-nondirectory qta-ahkdata:generator-script-file)%)'
;;
;;
;; Writing LaTeX glyphs with
;; AutoHotKey (unicode versions only)
@kbauer
kbauer / matrixform.py
Last active March 21, 2017 16:22
An equivalent to Mathematica's MatrixForm[] for pretty-printing sympy.tensor.array.Array
import sympy
from sympy import Matrix, Symbol
from sympy.tensor.array import Array
def matrixform(data):
"""
Translates an Array or nested list, or anything that behaves
similarly, into a structure of nested matrices.
"""
try:
@kbauer
kbauer / Comic Rocket New Pages Sorted.js
Last active October 8, 2016 19:37
Bookmarklet for sorting the comic-list on http://www.comic-rocket.com/ (after logging in) by the number of unread pages. Confirmed to work in Chrome for Desktop and Chrome for iOS.
/* Comic Rocket New Pages Sorted.js */
var NW = 4; /* number width */
var MODE = 0; /* 1 for reordering the divs, 2 for creating a new format, 0 for dialog */
function g(x,y){return Array.from(x.getElementsByClassName(y))};
function ce(e,tag){var x=document.createElement(tag); if(e){e.appendChild(x)}; return x;}
function lpad(s,n){ s = ""+s;while(s.length<n){s=" "+s;} return s;}
function rpad(s,n){ s = ""+s;while(s.length<n){s=s+" ";} return s;}
var divs = g(document,"comics-item");
var data = divs.map(function(c){
var [current,total] = g(c,"progress-label")[0].textContent.split("/");
@kbauer
kbauer / FORVARARGS.h
Last active February 19, 2016 15:40
A c preprocessor macro allowing to iterate over an argument list `A1, A2, ...` to produce `M(1, A1), M(2, A2), ...` or the reverse. Depends on ONEARG.h, see https://gist.github.com/kbauer/d651bae52ab2f72b8d1e . Tested with `gcc -E -std=c99`.
// Usage: _FORVARARGS(M,A0[,A1[,A2[...]]])
//
// Equivalent to M(0,A0) M(1,A1) M(2,A2) ...
// Supports up to 32 Varargs. Emacs lisp code for generating included.
// Define the macro M(N, ARG) to generate useful code.
//
// Usage: _FORVARARGS_R(M,A0[,A1[,A2[...]]])
//
// Equivalent to ... M(2,A2) M(1,A1) M(0,A0), i.e. reverse of _FORVARARGS.
//
@kbauer
kbauer / ONEARG.h
Last active February 19, 2016 15:42
A C preprocessor macro that allows executing code depending on the number of arguments in `__VA_ARGS__`. Test with `gcc -std=c99 -E`. Original version of an `_IFEMPTY` macro was discarded because it depended on the GCC extension syntax `## __VA_ARGS__`.
/// Usage: _ISONEARG() -> 1
/// _ISONEARG(A) -> 1
/// _ISONEARG(A,B,...) -> 0
///
/// Alternative to _IFEMPTY, that works with standard C.
/// Works for up to 100 arguments.
///
/// Examples:
///
/// "_ISONEARG()" -> 1
@kbauer
kbauer / boogie-board-daemon
Last active August 28, 2022 16:02
A companion script for the BoogieBoard Sync 9.7 eWriter. The main purpose is to put the latest Bluetooth-synced page into the clipboard as image data. Depends on the `imagemagick-scan-to-mono.sh` script (see https://gist.github.com/kbauer/e5bd0dc12142e7a6c97f).
#!/usr/bin/env bash
source libstacktrace || true
set -e -E -u
BOOGIEDIR="$(cygpath "$LOCALAPPDATA")/BoogieBoardSync/Downloads"
cd "$BOOGIEDIR"
MANUAL="
@kbauer
kbauer / emacs-lines-of-code
Created August 20, 2015 11:51
Calculate the number of non-empty, non-commented code lines in an emacs lisp project or configuration file. For simple configurations run `emacs-lines-of-code ~/.emacs`
#!/usr/bin/env bash
set -e -E -u
source libstacktrace || true
DEBUG=false
MANUAL="
USAGE: $0 ( DIRECTORY | FILE ) ...