Skip to content

Instantly share code, notes, and snippets.

View stefanschmidt's full-sized avatar

Stefan stefanschmidt

  • Hamburg, Germany
View GitHub Profile
@stefanschmidt
stefanschmidt / download-pdfs.sh
Last active August 29, 2015 14:22
Download all PDF documents from a web page
# depends on wget and GNU Parallel (available via Homebrew)
wget -e robots=off -nd -r --spider -l1 -A pdf http://foo.net/bar 2>&1 | grep -Eio http.+pdf | parallel -L 1 wget -nc --no-verbose
@stefanschmidt
stefanschmidt / parfor-print.m
Last active August 29, 2015 14:23
Continuous screen output in parfor loop
% to enable continuous screen output in a parfor loop place a
% pause of 2-3 seconds before each fprintf or disp statement.
% it seems this flushes the stdout buffer of the worker nodes.
% tested with a local parpool in Matlab R2014b on OS X 10.9.5.
fprintf('pre\n')
parfor n = 1:5
pause(2)
fprintf('start %i\n',n)
pause(10)
fprintf('end %i\n',n)
@stefanschmidt
stefanschmidt / dekerned-pdf-search.sh
Created July 8, 2015 21:43
Find raw line numbers of text snippets in PDFs with manual kerning
# qpdf converts the PDF into a readable text file
# depends on GNU sed and GNU grep (available via Homebrew)
# GNU sed because BSD grep throws an "illegal byte sequence" error
# GNU grep because BSD grep omits lines
# iconv to properly display non-UTF8 encodings
# doesn't find hyphenated words or words with ligatures
qpdf --qdf doc.pdf - | iconv -f ISO-8859-1 -t UTF-8 | gsed -E 's/\)-?[0-9]+(\.[0-9]+)?\(//g' | ggrep -ian foobar
# usage example
#
@stefanschmidt
stefanschmidt / concat-img.sh
Created July 9, 2015 17:03
Horizontally or vertically concatenate images
# depends on Imagemagick (available via Homebrew)
# horizontal concatenation
convert +append img1.png img2.png img3.png out.png
# vertical concatenation
convert -append img1.png img2.png img3.png out.png
@stefanschmidt
stefanschmidt / concat-gs.sh
Last active August 29, 2015 14:24
Concatenate PDFs with Ghostscript without decreasing image quality
# depends on Ghostscript (available via Homebrew)
# copied from: http://superuser.com/questions/360216
gs \
-o output.pdf \
-sDEVICE=pdfwrite \
-dColorConversionStrategy=/LeaveColorUnchanged \
-dDownsampleMonoImages=false \
-dDownsampleGrayImages=false \
-dDownsampleColorImages=false \
-dAutoFilterColorImages=false \
@stefanschmidt
stefanschmidt / pynumpy.sh
Last active September 14, 2015 11:27
Install Python and NumPy with inline matrix operator on OS X
# to avoid errors concerning libraries linked against former versions of libgfortran.3.dylib
brew remove --force suite-sparse-julia arpack-julia openblas-julia arpack64-julia openblas64-julia
brew update && brew install python3
pip3 install --upgrade pip setuptools
# the @ operator is available starting from Python 3.5 / NumPy 1.10
# https://docs.python.org/3.5/whatsnew/3.5.html#whatsnew-pep-465
pip3 install http://sourceforge.net/projects/numpy/files/NumPy/1.10.0b1/numpy-1.10.0b1.tar.gz/download
@stefanschmidt
stefanschmidt / startup.m
Last active September 23, 2015 14:17
Workaround for graphical glitch in tab bar of Matlab 2014b on iMac
% see also: http://undocumentedmatlab.com/blog/setting-the-matlab-desktop-layout-programmatically
if not(isdeployed) && usejava('jvm') && feature('ShowFigureWindows')
desktop = com.mathworks.mde.desk.MLDesktop.getInstance;
pause(0.7) % wait for gui to load
desktop.restoreLayout('foobar');
clear desktop
end
@stefanschmidt
stefanschmidt / vimeo-downlaoder.sh
Last active September 25, 2015 12:38
Vimeo Downloader
#!/bin/sh
#
# Vimeo Downloader
#
# Copyright (C) 2008, 2010 Denver Gingerich
# Copyright (C) 2009 Jori Hamalainen
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
@stefanschmidt
stefanschmidt / speedtest.js
Last active September 27, 2015 17:37
Ookla Speedtest CLI customization
// available at https://github.com/sindresorhus/speed-test
function render() {
logUpdate([
'↻ ' + stats.ping + getSpinner('ping'),
'↓ ' + stats.download + getSpinner('download'),
'↑ ' + stats.upload + getSpinner('upload')
].join('\n'));
}
// to select a specific server for testing get a server id
@stefanschmidt
stefanschmidt / remote-management.sh
Last active October 3, 2015 08:58
Enable Remote Management on OS X
# Configure Remote Management
kickstart -configure -allowAccessFor -allUsers -privs -all
# Enable Remote Management
kickstart -activate -restart -agent
# Disable Remote Management
kickstart -deactivate -stop