Skip to content

Instantly share code, notes, and snippets.

View stefanschmidt's full-sized avatar

Stefan stefanschmidt

  • Hamburg, Germany
View GitHub Profile
@stefanschmidt
stefanschmidt / clean_arxiv_pdf.py
Created March 18, 2023 02:56
Remove link borders and watermark from arXiv papers
import pikepdf
import re
def remove_link_borders(pdf):
'''remove link borders on all pages'''
removed = 0
for p, page in enumerate(pdf.pages):
if '/Annots' in page:
for a, annot in enumerate(page['/Annots']):
page['/Annots'][a]['/BS']['/W'] = 0
@stefanschmidt
stefanschmidt / remove_metadata_and_links.py
Created March 9, 2023 00:05
Remove all metadata and links matching a URL pattern from a PDF document
@stefanschmidt
stefanschmidt / download_all_tweets.go
Created November 26, 2022 17:02
Download all tweets of a user without requiring an API key
// To my knowledge the only solution available that:
// - does not require an API key with "elevated access" (most other solutions need this, requires an application)
// - does not require an API key with "essential access" (requires a valid cell phone number to enable)
// - does not require any type of API key
// - isn't outdated or otherwise broken
//
// Can (probably) download up to 3200 tweets
//
// brew install go
// go run download_all_tweets.go
@stefanschmidt
stefanschmidt / chrome_extension_download.md
Created October 22, 2022 18:43
Chrome Web Store extension update API

Using the URL returned by Charles Proxy when installing an extension from the Chrome Web Store to download the extension (inspired by paulirish).

$ extension_id=jifpbeccnghkjeaalbbjmodiffmgedin
$ curl --output "$extension_id.crx" --silent --location "https://clients2.google.com/service/update2/crx?response=redirect&os=mac&arch=x64&os_arch=x86_64&nacl_arch=x86-64&prod=chromecrx&prodchannel=canary&prodversion=107.0.5304.0&lang=en-GB&acceptformat=crx3&x=id%3D$extension_id%26installsource%3Dondemand%26uc"
$ file "$extension_id.crx"
jifpbeccnghkjeaalbbjmodiffmgedin.crx: Google Chrome extension, version 3

The SHA-256 checksum of the downloaded file matches the value returned by the API.

$ sha256sum "$extension_id.crx"

@stefanschmidt
stefanschmidt / brewman.sh
Created October 21, 2022 10:48
Show man page for keg-only Homebrew formulae
# show man page for keg-only Homebrew formulae (e.g. strings of binutils)
# usage: brewman name (name is the name of the manual page)
# example: brewman strings
# resolve symbolic link pointing to cellar of Homebrew formula
function cellar ()
{
formula_name=$1
pushd /usr/local/opt >/dev/null
pushd $(readlink /usr/local/opt/$1) >/dev/null
@stefanschmidt
stefanschmidt / delete-addon-prefs.py
Created April 23, 2022 15:51
Delete Firefox Addon preferences
import sys
import glob
import os
import configparser
import json
import sqlite3
# Functions for finding Firefox default profile folder adapted from
# https://github.com/1dot75cm/browsercookie
@stefanschmidt
stefanschmidt / setup.py
Created April 22, 2022 12:49
Clean Python build directory
import os
import glob
import shutil
from io import open
from setuptools import Command, setup
# Slightly modified and extended version of this approach:
# https://github.com/pypa/setuptools/issues/1347#issuecomment-387802255
@stefanschmidt
stefanschmidt / download-file-selenium-firefox.py
Created April 14, 2022 20:42
Download file in headless Firefox with Selenium and geckodriver on macOS
# install requirements
# brew install python@3.10 # Python 3.7+ required
# brew install geckodriver # To access Firefox
# pip install --upgrade selenium
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
options = Options()
options.headless = True
@stefanschmidt
stefanschmidt / install-opencv-python-mojave.sh
Last active March 31, 2022 08:38
Install latest built distribution of OpenCV python bindings on macOS Mojave with Homebrew and pip
brew install python@3.9
pip3.9 install opencv-python==4.5.1.48