Skip to content

Instantly share code, notes, and snippets.

View ap--'s full-sized avatar
🪐

Andreas Poehlmann ap--

🪐
View GitHub Profile
@ap--
ap-- / count_lines.py
Created June 5, 2023 16:57
python: count lines in file
import mmap
def count_lines(fn: str | Path) -> int:
"""count lines in file"""
with open(fn, "rb") as f:
buf = mmap.mmap(f.fileno(), 0, prot=mmap.PROT_READ)
return sum(1 for _ in iter(buf.readline, b""))
"""super quick script for getting the file urls for download"""
import sys
import requests
from bs4 import BeautifulSoup
from itertools import count
url = "https://cytomine.com/collection"
for page_idx in count():
page = requests.get(url, params={"page": page_idx})
@ap--
ap-- / merge_intervals.py
Created January 23, 2022 12:32
simple merge intervals function
from __future__ import annotations
import itertools
def merge_intervals(
intervals: list[tuple[int, int]],
*,
merge_adjacent: bool = False,
inplace: bool = False,
@ap--
ap-- / pep634_fizzbuzz.py
Created February 27, 2021 22:24
pep634 fizzbuzz
# fizzbuzz abusing pep634. run with python 3.10
class ZZMeta(type):
def __new__(mcls, name, bases, attr, **kw):
attr['d'] = kw.get('divisor', None)
return super().__new__(mcls, name, bases, attr)
def __instancecheck__(cls, obj):
if not obj % cls.d:
print(cls.__name__, end="")
return True
@ap--
ap-- / google-cloud-md5-conversion.sh
Last active November 4, 2020 14:47
google cloud base64 encoded md5 to hex
alias md5b64tohex="python -c 'import base64, binascii, sys; print binascii.hexlify(base64.urlsafe_b64decode(sys.argv[1]))'"
@ap--
ap-- / startup.groovy
Created August 10, 2020 14:00
QuPath startup.groovy script that enables per project startup.groovy scripts that can be provided with each project
/**
* Run a per project startup script on project load, if the project ships a
* 'startup.groovy' script in its project scripts directory.
*
* @author Andreas Poehlmann
*/
import java.awt.image.BufferedImage
import javafx.beans.value.ChangeListener
import javafx.beans.value.ObservableValue
import qupath.lib.gui.scripting.DefaultScriptEditor
@ap--
ap-- / setup-ubuntu.sh
Created September 20, 2019 05:45
Python Dev on Ubuntu 19.04 on Android via Termux
#!/bin/bash
#
# Python on 19.04 on Android
# ==========================
#
# Setup an ubuntu dev environment for Python on Android.
#
DEVUSER=poehlmann
# update termux packages
@ap--
ap-- / matplotlib_fruitfly.py
Created March 18, 2017 21:24
Plot a fruit fly
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
def plot_fly(ax, c, s, o):
# center, scale, orientation(deg)
c = np.array(c)
v = np.array([np.cos(np.radians(o)), np.sin(np.radians(o))])
t = np.array([np.cos(np.radians(o+90)), np.sin(np.radians(o+90))])
@ap--
ap-- / binary-wheels.zip
Last active August 29, 2015 14:15
SB-Binary-dep-34-x64
This file has been truncated, but you can view the full file.
@ap--
ap-- / binary-wheels.zip
Last active August 29, 2015 14:15
SB-Binary-dep-34-win32
This file has been truncated, but you can view the full file.