Skip to content

Instantly share code, notes, and snippets.

View akleemans's full-sized avatar

Adrianus Kleemans akleemans

View GitHub Profile
@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
@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 / 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)]),
#!/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'})
import {Component, OnInit} from '@angular/core';
import {HttpClient} from "@angular/common/http";
@Component({
selector: 'app-root',
template: 'Called API and got: "{{greeting}}"'
})
export class AppComponent implements OnInit {
public greeting: string;
package ch.kleemans.demoapp;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
@akleemans
akleemans / README
Last active January 15, 2020 12:31
Simple flask web server
# install flask
sudo pip3 install flask
# run script
python3 server.py
@akleemans
akleemans / dice_throw.py
Created January 13, 2018 23:06
Simulate throwing a dice and waiting until all numbers appear
''' Simple script for throwing a dice over and over until all numbers appeared at least once. '''
from __future__ import division
import random
import time
n = 10**5
r = random.SystemRandom()
def number_of_dice_throws():
count = 0
@akleemans
akleemans / route.js
Created November 9, 2016 09:31
Routing configuration for vocabulario app
angular.module('VociTrainer', ['ngRoute'])
.config(['$routeProvider', '$locationProvider',
function ($routeProvider, $locationProvider) {
$routeProvider
.when('/home', {
templateUrl: 'views/home/home.html',
controller: 'HomeCtrl',
controllerAs: 'home'
})
.when('/impressum', {
@akleemans
akleemans / example-controller.spec.js
Created November 9, 2016 06:08
Tests for example controller
describe("ExampleController", function () {
var exampleCtrl, $httpBackend, $filter;
beforeEach(module('myapp'));
beforeEach(inject(function ($controller, _$httpBackend_, _$filter_, _Users_) {
$filter = _$filter_;
$httpBackend = _$httpBackend_;
// respond with some mocked data
$httpBackend.whenGET(/...\/users/).respond([{ username: "foo", email: "[email protected]" }, { username: "bar", email: "[email protected]" }]);
exampleCtrl = $controller('ExampleController', { Users: _Users_ });