Skip to content

Instantly share code, notes, and snippets.

View stefanschmidt's full-sized avatar

Stefan stefanschmidt

  • Hamburg, Germany
View GitHub Profile
stefanschmidt /
Last active August 13, 2023 09:16
Resolve symbolic link chains to files and containing folders step-by-step

Gradually resolving symbolic link chains

Let's say one wants to know where pdflatex is located.

$ type pdflatex
pdflatex is /Library/TeX/texbin/pdflatex

We can see that this path is a symbolic link to pdftex.

$ ls -ld /Library/TeX/texbin/pdflatex

stefanschmidt /
Created June 20, 2023 11:22
Fix logical page numbering of a PDF document
# cover (1 page)
# table of contents (14 pages)
# result: C1,i,ii,...,xiv,1,2,...
pip install pagelabels
python -m pagelabels --delete doc.pdf
python -m pagelabels --startpage 1 --prefix C doc.pdf
python -m pagelabels --startpage 2 --type 'roman lowercase' doc.pdf
python -m pagelabels --startpage 16 --type arabic doc.pdf
stefanschmidt /
Created June 10, 2023 19:26
Extract embedded fonts from a PDF file as OpenType file
# show information about pdf resources (shows font names used in PDF)
mutool info file.pdf
# extract font and image resources
mutool extract file.pdf
# convert a CFF file (Compact Font Format) to OTF format (OpenType Font)
fontforge -lang=ff -c 'Open($1); Generate($1:r + ".otf")' font.cff
stefanschmidt /
Created May 15, 2023 17:58
Simple linear regression in NumPy

Simple linear regression in NumPy

The verbosity of performing a simple linear regression in the current stable release has increased by an astonishing amount.1

In the documentation it is recommended to not use [numpy.polyfit][polyfit].

As noted above, the poly1d class and associated functions defined in numpy.lib.polynomial, such as numpy.polyfit and numpy.poly, are considered legacy and should not be used in new code. Since NumPy version 1.4, the numpy.polynomial package is preferred for working with polynomials.

For polynomial regression, the the documentation [recommends][polynomials] to replace [numpy.polyfit][polyfit] with [][polynomial].

stefanschmidt /
Created May 15, 2023 17:56
Reading a CSV file with Python

Reading a CSV file with Python

For anything < 50 MB

import csv

with open("data.csv") as fp:
    reader = csv.reader(fp, delimiter=",", quotechar='"')
    csv_data = [row for row in reader]
stefanschmidt /
Created May 10, 2023 21:27
Convert BBC subtitles to plain text

Convert BBC subtitles to plain text

Install prerequisites

brew install youtube-dl
pip install pysrt beautifulsoup4
pip install --pre ttconv

Download the subtitles

stefanschmidt /
Last active May 5, 2023 11:31
Filter rule for matching a text in a div tag with an apostrophe/quote/quotation mark with uBlock Origin

Test with Chrome 112.0.5615.137 and uBlock Origin 1.49.2

Doesn't work (hides all divs)"It looks like there aren't many great matches for your search") looks like there aren\'t many great matches for your search/)


Use a more specific filter rule

Possibly because it narrows down the number of divs to consider.

stefanschmidt /
Created May 1, 2023 00:37
Running ChromiumOS on macOS

Running ChromiumOS on macOS

The ChromiumOS distribution CloudReady was discontinued some time after Google acquired the company that offered it. The successor is ChromeOS Flex but there don't seem to be any official virtual machine images available.

Downloading the virtual machine image

The CloudReady OVA file mentioned in the knowledge base article is available on the Wayback Machine (direct download).

$ sha256sum CloudReady-Home-v83-x64.ova

7e4c7304c4b7363dfd778d3a58765c4d03fcd9fb3a1e5ae97c2582b42e4b66ad CloudReady-Home-v83-x64.ova

stefanschmidt / anti_clickjacking.user.js
Created April 6, 2023 16:35
Restore cmd+click to open an article in a new tab on MIT Technology Review
// ==UserScript==
// @name Anti-Clickjacking
// @namespace
// @version 1.0
// @description restore cmd+click on article links to open new tab
// @author Stefan
// @match
// @icon
// @grant none
// ==/UserScript==
stefanschmidt / date_add_to_mod.c
Created March 19, 2023 01:51
Set "Date Added" in macOS Finder to match "Date Modified"
#include <stdlib.h>
#include <string.h>
#include <sys/attr.h>
#include <unistd.h>
#include <stdio.h>
* For a list of files set "Date Added" in
* macOS Finder to match "Date Modified"