Skip to content

Instantly share code, notes, and snippets.

View akleemans's full-sized avatar

Adrianus Kleemans akleemans

View GitHub Profile
#!/usr/bin/python
# -*- coding: utf-8 -*-
'''Download the current Spotify Top 50 from Youtube.'''
import urllib.request
import subprocess
# fetch charts
print('Downloading charts...')
req = urllib.request.Request('https://spotifycharts.com/regional/global/weekly/latest/download', headers={'User-Agent': 'Mozilla/5.0'})
@akleemans
akleemans / puzzle.py
Created August 15, 2024 19:30
Script to solve a pentomino jigsaw puzzle
import time
all_pieces = [
(0, [('-', 0, 0), ('|', 1, 0), ('-', 2, 0), ('|', 2, 1), ('|', 3, 0)]),
(1, [('-', 1, 0), ('|', 1, 1), ('-', 0, 1), ('|', 0, 2), ('-', 0, 3)]),
(2, [('|', 0, 0), ('-', 0, 1), ('|', 0, 2), ('-', 0, 3), ('|', 0, 4)]),
(3, [('|', 0, 0), ('-', 0, 1), ('|', 1, 1), ('-', 2, 1), ('|', 2, 2)]),
(4, [('-', 2, 0), ('|', 2, 1), ('-', 1, 1), ('|', 1, 2), ('-', 0, 2)]),
(5, [('-', 0, 0), ('|', 0, 1), ('-', 0, 2), ('|', 0, 3), ('-', 0, 4)]),
(6, [('-', 0, 0), ('|', 0, 1), ('-', 0, 2), ('-', 1, 1), ('|', 2, 1)]),
@akleemans
akleemans / generate_diary.py
Created October 15, 2024 18:32
Create a plant diary from an excursion using the Pl@ntNet API. More details at https://kleemans.ch/classifying-plants-creating-an-excursion-diary
from typing import List, Tuple
import requests
import json
import glob
import os
from PIL import Image, ImageOps
"""
This script will automically pick up images from a subfolder 'img' and try to classify them against
the Pl@ntNet API. (You have to provide your API key below.)
@akleemans
akleemans / count_jigsaw_kmeans.py
Created February 3, 2025 20:01
Count jigsaw puzzle pieces using k-means clustering
# Counts jigsaw puzzle pieces
# See https://www.kleemans.ch/counting-jigsaw-puzzle-pieces
# Uses opencv-python==4.11.0.86 and numpy==2.2.2
import statistics
import cv2
import numpy as np