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 / MapCSS.peggy
Last active April 10, 2023 21:56
MapCSS grammar written for @peggyjs (a parser generator for JavaScript)
/*
* Parser definition for the main MapCSS parser:
*
* <pre>
*
* rule
* _______________________|______________________________
* | |
* selector declaration
* _________|___________________ _________|____________
@simon04
simon04 / leaflet-fullscreen-control.js
Created February 2, 2023 12:06
A Leaflet Control, to request fullscreen for map (no CSS, no image)
/**
* A Leaflet Control, to request fullscreen for map (no CSS, no image)
*
* @example new FullscreenControl({ position: "topleft" }).addTo(map);
*/
export class FullscreenControl extends L.Control {
onAdd() {
const container = L.DomUtil.create("div", " leaflet-bar");
const link = L.DomUtil.create("a", undefined, container);
link.innerHTML = "⛶";
@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 / 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;
@simon04
simon04 / README.md
Created December 7, 2021 11:09
IntelliJ IDEA // external tools // javap
@simon04
simon04 / README.md
Last active December 7, 2021 11:08
IntelliJ IDEA // external tools // oxipng
@simon04
simon04 / index.html
Created June 9, 2021 11:50
Leaflet example using JavaScript modules
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link
rel="stylesheet"
href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css"
/>
</head>