Skip to content

Instantly share code, notes, and snippets.

View stefanschmidt's full-sized avatar

Stefan stefanschmidt

  • Hamburg, Germany
View GitHub Profile
@stefanschmidt
stefanschmidt / authenticate-ldap.sh
Last active April 25, 2024 07:23
Authenticate via LDAP on the command line
# Using an LDAP test server we will authenticate the user newton
# http://www.forumsys.com/tutorials/integration-how-to/ldap/online-ldap-test-server/
# method 1: using ldapwhoami
# should return "Result: Success (0)" if authentication was successful
ldapwhoami -vvv -h ldap.forumsys.com -D "uid=newton,dc=example,dc=com" -x -w password
# method 2: using ldapsearch
# should return "result: 0 Success" if authentication was successful
ldapsearch -h ldap.forumsys.com -x -D uid=newton,dc=example,dc=com -w password -b "dc=example,dc=com" "(uid=newton)"
@stefanschmidt
stefanschmidt / remove-annotations.sh
Last active February 1, 2024 17:01
Remove all annotations from a PDF document
pdftk original.pdf output uncompressed.pdf uncompress
LANG=C sed -n '/^\/Annots/!p' uncompressed.pdf > stripped.pdf
pdftk stripped.pdf output final.pdf compress
@stefanschmidt
stefanschmidt / fix-homebrew-owner-perms.sh
Created April 12, 2016 21:19
Fix ownership and permissions of a multi-user Homebrew installation
# fix owner of files and folders recursively
sudo chown -vR $(whoami) /usr/local /opt/homebrew-cask /Library/Caches/Homebrew
# fix read/write permission of files and folders recursively
chmod -vR ug+rw /usr/local /opt/homebrew-cask /Library/Caches/Homebrew
# fix execute permission of folders recursively
find /usr/local /opt/homebrew-cask /Library/Caches/Homebrew -type d -exec chmod -v ug+x {} +
@stefanschmidt
stefanschmidt / toggle-screen-sharing
Last active November 29, 2023 22:21
Enable/Disable Screen Sharing on OSX
# Enable Screen Sharing
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.screensharing.plist
# Disable Screen Sharing
sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.screensharing.plist
@stefanschmidt
stefanschmidt / osx-software-update-urls.txt
Created January 4, 2014 01:22
URLs of the index files used by the software update client on OS X
10.3 (Panther): http://swscan.apple.com/scanningpoints/scanningpointX.xml
10.4 (Tiger): http://swscan.apple.com/content/catalogs/index-1.sucatalog
10.5 (Leopard): http://swscan.apple.com/content/catalogs/others/index-leopard.merged-1.sucatalog
10.6 (Snow Leopard): http://swscan.apple.com/content/catalogs/others/index-leopard-snowleopard.merged-1.sucatalog
10.7 (Lion): http://swscan.apple.com/content/catalogs/others/index-lion-snowleopard-leopard.merged-1.sucatalog
10.8 (Mountain Lion): http://swscan.apple.com/content/catalogs/others/index-mountainlion-lion-snowleopard-leopard.merged-1.sucatalog
10.9 (Mavericks): http://swscan.apple.com/content/catalogs/others/index-10.9-mountainlion-lion-snowleopard-leopard.merged-1.sucatalog
10.9 (Mavericks incl. seeds): http://swscan.apple.com/content/catalogs/others/index-10.9seed-10.9-mountainlion-lion-snowleopard-leopard.merged-1.sucatalog
@stefanschmidt
stefanschmidt / realpath_verbose.md
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
stefanschmidt / fix-page-labels-pdf.sh
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
stefanschmidt / extract_fonts_from_pdf.sh
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
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 / linear_regression_numpy.md
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 [numpy.polynomial.polynomial.Polynomial.fit][polynomial].