Skip to content

Instantly share code, notes, and snippets.

@rwirth
rwirth / add-bookmarks.py
Created May 27, 2019 21:19
Script to add bookmarks to a PDF file
#!/usr/bin/env python3
import collections
import io
import re
import PyPDF2.pdf as pdf
ChapterTreeNode = collections.namedtuple('ChapterTreeNode', 'name page children')
@rwirth
rwirth / util.py
Last active August 25, 2017 04:39 — forked from kgriffs/util.py
Deprecated decorator for Python. Uses clever introspection to set a helpful filename and lineno in the warning message, even in complex cases like code being executed via execfile. The warning is properly registered and repeated only once for each 'offending' line (by default).
import functools
import inspect
import warnings
# NOTE(kgriffs): We don't want our deprecations to be ignored by default,
# so create our own type.
class DeprecatedWarning(UserWarning):
pass
@rwirth
rwirth / limitnatbib.sty
Created September 14, 2015 08:56
Limit LaTeX natbib author lists
\newcounter{@maxauthors}
\setcounter{@maxauthors}{3}
\newcounter{@authors}
\def\BibitemOpen{
\setcounter{@authors}{0}
\bibitemOpen
}
%\NewDocumentCommand{\@gobbletoend}{u{,\ }}{\fi\fi\showtokens{#1}}
\NewDocumentCommand{\@gobbletoend}{u{,\ }}{\fi\fi}