Skip to content

Instantly share code, notes, and snippets.

View simon04's full-sized avatar

Simon Legner simon04

  • Innsbruck, Austria
View GitHub Profile
@simon04
simon04 / leaflet-collapsable-layer-control.js
Last active February 2, 2023 12:03
A Leaflet Layer Control, which may be expanded by default, but may be collapsed using a button.
/**
* A Leaflet Layer Control, which may be expanded by default, but may be collapsed using a button.
*
* @example new CollapsableLayerControl(layers, {}, { collapsed: false })
*/
export class CollapsableLayerControl extends L.Control.Layers {
onAdd(map) {
L.Control.Layers.prototype.onAdd.call(this, map);
const div = document.createElement("div");
div.style.textAlign = "right";
@simon04
simon04 / parse_timedelta.py
Created December 10, 2022 17:08
Python: parses strings as ISO 8601 timedelta (License: CC0)
from datetime import timedelta
import re
import unittest
def parse_timedelta(delta: str) -> timedelta:
"""Parses the given string as ISO 8601 timedelta"""
# https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/time/Duration.html#parse(java.lang.CharSequence)
match = re.compile(
r"(?P<sign>[-+]?)P"
@simon04
simon04 / HTTPS.java
Last active November 28, 2022 09:01
Java 17: SSLContext/X509TrustManager which only accepts a server certificate with the given SHA-256 fingerprint
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import java.security.KeyManagementException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.HexFormat;
@simon04
simon04 / JwtTest.java
Created February 10, 2021 10:54
Configure RSA512 algorithm for com.auth0.jwt.JWT using an RSA private/public key generated by openssl
import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import org.bouncycastle.util.io.pem.PemReader;
import org.junit.Test;
import java.io.BufferedReader;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.security.KeyFactory;
import java.security.interfaces.RSAPrivateKey;
<?xml version="1.0" encoding="UTF-8"?>
<!-- Using optional BOM (0xEF 0xBB 0xBF) -->
<!-- From http://forum.openstreetmap.org/viewtopic.php?id=7186 -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://openstreetmap.org/osm/0.6"
xmlns="http://openstreetmap.org/osm/0.6">
<xs:element name="osm">
<xs:complexType>
<xs:sequence>
@simon04
simon04 / m4a2ogg
Created February 15, 2015 17:39
Converts m4a files to Ogg Vorbis using ffmpeg
#!/bin/bash
# Author: Simon Legner <Simon.Legner@gmail.com>
convert () {
in="$1"
out="${in%.m4a}.ogg"
ffmpeg -i "$in" \
-acodec libvorbis -aq 4 -vn -ac 2 \
-map_metadata 0 \
"$out"
> neofetch
                    c.'          simon@simon-mac 
                 ,xNMM.          --------------- 
               .OMMMMo           OS: macOS Monterey 12.3 21E230 x86_64 
               lMM"              Host: MacBookAir10,1 
     .;loddo:.  .olloddol;.      Kernel: 21.4.0 
   cKMMMMMMMMMMNWMMMMMMMMMM0:    Packages: 242 (brew), 48 (nix-user) 
 .KMMMMMMMMMMMMMMMMMMMMMMMWd.    Shell: fish 3.4.1 
 XMMMMMMMMMMMMMMMMMMMMMMMX. Resolution: 2560x1600 , 3440x1440 @ -Hz 
@simon04
simon04 / gist:6865179
Last active February 15, 2022 06:14
Gradle, Java plugin, Jar MANIFEST, Class-Path is empty

Gradle, Java plugin, Jar MANIFEST, Class-Path is empty

I struggled with with the jar MANIFEST file built with Gradle containing an empty Class-Path. I traced down the problem to the order of the dependencies and jar blocks in the build.gradle file:

Wrong (jar before dependencies):

jar {
    manifest.attributes(
@simon04
simon04 / Caddyfile
Last active January 11, 2022 07:44
Nextcloud via Docker and Caddy
# /etc/caddy/Caddyfile
cloud.example.com {
root /srv/http/nextcloud/
fastcgi / localhost:7070 php {
root /var/www/html/
}
timeouts 30m
}
@simon04
simon04 / JwtAuthenticator.java
Created December 30, 2021 14:52
Jetty Authenticator for JWT/JWKS
package at.tbbm.manual_input.util;
import com.auth0.jwk.Jwk;
import com.auth0.jwk.JwkException;
import com.auth0.jwk.JwkProvider;
import com.auth0.jwk.UrlJwkProvider;
import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import com.auth0.jwt.exceptions.JWTVerificationException;
import com.auth0.jwt.interfaces.DecodedJWT;