Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / _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 / Adblock Simple.js
Last active June 6, 2024 11:56
A simple adblocker bookmarklet, removing suspicious iframes. To install, copy-paste the source to a bookmark (will automatically remove newline characters). Extend the array ``exceptOrigins`` in order to create new exceptions. Careful: If bookmarklets get too long, they might stop working. This methods provides on-demand adblocking (as opposed t…
javascript:/* Adblock Simple */
(function(){
const exceptOrigins = [
'https://disqus.com',
document.origin
];
function remIF(e){
try{
var orgn = new URL(e.src || 'http://unknown-src').origin;
@kbauer
kbauer / html2bbcode.py
Created November 20, 2017 13:38
A simple python3 script that takes html input and converts it to (an approximation in) BBCODE. Usage described in header comment. Also useful with markdown, preprocessed to html by pandoc. Allows customizing replacement rules for html-tags, which should also allow converting xml documents to some degree.
#!/usr/bin/env python3
#### USAGE
##
## python3 <scriptname> INPUTFILE [ EXTRARULE ... ]
##
## Output is written to stdout.
##
## INPUTFILE must be a html file. Xml should work too, but will like
## require redefining all replacement rules.
javascript:/* MailToSelf */ (function(){target = "mailto:[email protected]?subject=" + encodeURIComponent(document.title) + "&body=" + encodeURIComponent(location.href); location.href = target;})()

On mobile devices, I often use "mail-to-self" type apps to quickly send me a webpage for later reading; Funnelling everything into my mailbox is simply the only way I will actually look at it again. On mobile, these apps integrate with the OS-provided "Share" menus, but on the desktop I had to manually write an email. Hence this bookmarklet, to automate creation of the reminder Email.

Installation

  1. Create a new bookmark.
@kbauer
kbauer / myjs-compile-bookmarklet.el
Last active May 30, 2025 16:45
Emacs-lisp command for compiling a javascript file into a bookmarklet, by stripping unnecessary characters and adding a wrapper.
;;; myjs-compile-bookmarklet.el --- strip javascript code as bookmarklet -*- lexical-binding: t; coding: utf-8; lisp-indent-offset: nil; -*-
;; Copyright (C) 2018 Klaus-Dieter Bauer
;; Author: Klaus-Dieter Bauer <[email protected]>
;; Keywords: javascript, bookmarklet
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or

Reader Mode.js

Add as bookmarklet (see below):

javascript:/* Reader Mode.js /(function(){ const IFWL=['gfycat.com','disqus.com','www.youtube.com',location.host,];const ifbl=new RegExp('derstandard\.at\/AdServer\/');const startupTasks=[disableViewport,];const periodicTasks=[disableStaticFloaters,removeIframes,];function disableStaticFloaters(){for(let e of document.getElementsByTagName('')){if(window.getComputedStyle(e).position.startsWith('fixed')){e.style.setProperty('position','static','important');}}}function removeIframes(){const iframes=getAllIframesRecursively();for(const e of getAllIframesRecursively().reverse()){try{const doRemove=(!e.src)? false : IFWL.indexOf(new URL(e.src).host)==-1 ? true : e.src.match(ifbl)? true : false;if(doRemove&&e.parentElement){e.parentElement.removeChild(e);}}catch(err){reportError(err,['FAILED TO REMOVE IFRAME',e]);}}window.readerModeRemainingIframes=getAllIframesRecursively();}function disableViewport(){const vp=document.querySelector('meta[name=v