Skip to content

Instantly share code, notes, and snippets.

@kbauer
kbauer / lyx-header-util.py
Last active April 1, 2016 19:29
A script for extracting and overwriting headers in lyx files.
#!/usr/bin/env python3
import sys
import tempfile
import io
import os
MANUAL="""
Usage: my-lyx-headerutil.py COMMAND ARG ...
@kbauer
kbauer / Meaning
Created July 15, 2015 15:52
For debugging/learning LaTeX internals it is useful to dump the definition of commands. Reading the output of `\show` from the console however is inconvenient. The command `\meaning` is useful here (as it prints the definition to the document) but limited. `\mymeaning` is a wrapper, where you specifiy the name of a macro rather than the `\macro`…
% \mymeaning{command} -> Definition of \command
\makeatletter
\newcommand{\mymeaning}[1]{
\begingroup%
\setlength{\parindent}{0em}
\setlength{\hangindent}{1em}
\edef\@tmp{\ifmmode\noexpand\mathtt\else\noexpand\texttt\fi}
\@tmp{%
\expandafter\string\csname #1\endcsname->%
\expandafter\meaning\csname #1\endcsname;%
@kbauer
kbauer / chrome-comic-rocket-navigation.ahk
Last active December 15, 2015 16:22
An AutoHotKey script for navigating comic-rocket. For use with other Browsers than Chrome, change the RegEx in the #IfWinActive line accordingly.
SetTitleMatchMode RegEx
#IfWinActive .*Comic Rocket webcomic list - Google Chrome
ComicRocketChangePage(bynum)
{
oldclip := clipboard
Send ^l
Sleep 50
Send ^c
Sleep 50
@kbauer
kbauer / imagemagick-scan-to-mono.sh
Last active May 31, 2021 17:26
A tool for converting scanned or photographed pages into a fax-style bi-level png with minimal storage use. Also removes background color gradients. See also my other gist `imagemagick-scan-pdf-to-mono.sh`
#!/usr/bin/env bash
# -*- mode: sh; coding: us-ascii-unix -*-
source libstacktrace || true
set -e -u -E
MANUAL="
Usage: $0 INFILE OUTFILE [BLURRADIUS;default:20px]
Takes a document scan INFILE (an image) and produces a monochromatized
@kbauer
kbauer / imagemagick-scan-pdf-to-mono.sh
Last active May 16, 2019 02:23
Converts a PDF obtained from scanning into a fax-like monochrome PDF. Assumes that the PDF consists of only a sequence of page-filling images. Requires my other gist imagemagick-scan-to-mono.sh
#!/usr/bin/env bash
# -*- mode: sh; coding: us-ascii-unix -*-
source libstacktrace || true
# set -e -u -E
MANUAL="
Usage: $0 [options] INPUT OUTPUT
$0 --inplace [options] INPUT
@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 ) ...
@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 / 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 / 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 / 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("/");