Skip to content

Instantly share code, notes, and snippets.

View habi's full-sized avatar

David Haberthür habi

View GitHub Profile
# Das ist das Programm für die PLZ von Sörenberg zu
postleitzahl = 1
while True:
try:
postleitzahl = int(input("Gib eine Schweizerische Postleitzahl ein: "))
if postleitzahl < 1000 or postleitzahl >= 10000:
print("Die Zahl muss zwischen 1000 und 9999 liegen.")
continue
if str(postleitzahl)[0] == str(postleitzahl)[1] == str(postleitzahl)[2] == str(postleitzahl)[3]:
print('Du darfst keine Schnapszahl eingeben!')
@habi
habi / output
Last active May 14, 2025 06:14
Terminal output
...
Processed 1730/2141
Processing settlement Corcelles-près-Concise (bezirk 2224)
relations found for maticni_broj 5555: 1
polygons found 1
2224 Corcelles-près-Concise Corcelles-près-Concise 99.89750086911707 0.0027331111249940675
Processed 1731/2141
Processing settlement Saint-Sulpice (VD) (bezirk 2229)
relations found for maticni_broj 5648: 1
polygons found 1
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@habi
habi / shrinkpdf.py
Created March 12, 2025 08:01
A *very* old script to <del>munge</del> reduce the file size of PDFs
#!/usr/bin/python
# -*- coding: utf-8 -*-
'''
Script to reduce the size of a pdf, handy for emailing to collaborators
Based on command found on http://www.ehow.com/how_6823473_reduce-pdf-file-size-
linux.html
First version 22.01.2013, David Haberthür
Second version 07.05.2013, David Haberthür: Cleanup
'''
@habi
habi / befehle
Created March 10, 2025 07:51
Bahnhofstrassen in Deutschland
cd
date
# Mon Mar 10 08:33:45 AM CET 2025
cd Dev/
mkdir deutschland-bahnhofstrassen
cd deutschland-bahnhofstrassen/
cargo install osm-lump-ways
wget https://download.geofabrik.de/europe/germany-latest.osm.pbf
osm-lump-ways -i germany-latest.osm.pbf -f highway -f highway≠pedestrian -f name~"ahnhofs" -o de-bahnhof.geojson
date
def centralizeslice(image, threshold=None, verbose=False):
'''
Move detected region centroid to center of image
This function can successively be applied to 'verticalize' slices of a tomographic dataset of a cylindrical object not scanned perfectly vertical
'''
if not threshold:
print('Calculating threshold')
threshold = skimage.filters.threshold_otsu(image)
label_img = skimage.measure.label(image > threshold)
# Detect centroid
# CDDB options
CDDBMETHOD=cddb,musicbrainz
CDDBURL="http://gnudb.gnudb.org/~cddb/cddb.cgi"
[email protected]
CDDBPROTO=6
HELLOINFO="$(whoami)@$(hostname)"
# The following options control whether or not fetched CDDB entries
# are cached locally in $CDDBLOCALDIR
@habi
habi / checkstyle.sh
Last active September 11, 2024 06:47
`pycodestyle` all Jupyter notebooks in a folder
for i in *.ipynb
# Tell us what we are doing
do echo Checking $i
# Convert the Jupyter notebook to .py and run through pycodestyle
jupyter nbconvert $i --to script && pycodestyle *.py --ignore=E501,E402,W391,W503 --show-source;
# Remove the converted file, thanks to https://stackoverflow.com/a/12152997
echo Removing "${i%.*}.py"
rm "${i%.*}.py"
done
@habi
habi / arrow
Created September 6, 2024 11:40
def ourarrow(x, y, linestyle='solid', yaw='left', pitch='up', color='white'):
# usually, the arrow points to the left
horizontaldisplacement = 75
verticaldisplacement = horizontaldisplacement
if 'right' in yaw:
horizontaldisplacement = horizontaldisplacement * -1
if 'down' in pitch:
verticaldisplacement = verticaldisplacement * -1
plt.gca().annotate('', xy=(x, y),
xytext=(x + horizontaldisplacement, y + verticaldisplacement),
@habi
habi / function.py
Created September 5, 2024 14:05
Orthoslicer in Python
def orthoslicer(stack, direction, coordinates, verbose=False):
'''Works like "orthogonal view" (CTRL+Shift+H in ImageJ'''
if verbose:
print('The input stack has a size of %s x %s x %s px' % (stack.shape[0],
stack.shape[1],
stack.shape[2]))
print('Extracting a slice centered %s, %s, %s px in direction %s' % (coordinates[0],
coordinates[1],
coordinates[2],
direction))