Skip to content

Instantly share code, notes, and snippets.

Avatar

Simon Legner simon04

  • Innsbruck, Austria
View GitHub Profile
@simon04
simon04 / leaflet-fullscreen-control.js
Created February 2, 2023 12:06
A Leaflet Control, to request fullscreen for map (no CSS, no image)
View leaflet-fullscreen-control.js
/**
* 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.
View leaflet-collapsable-layer-control.js
/**
* 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 / Application.java
Last active January 29, 2023 11:12
Lightweight REST API using Jersey on embedded Jetty server
View Application.java
package root;
import root.resources.HelloResource;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.servlet.ServletContainer;
public class Application {
@simon04
simon04 / parse_timedelta.py
Created December 10, 2022 17:08
Python: parses strings as ISO 8601 timedelta (License: CC0)
View parse_timedelta.py
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
View HTTPS.java
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
View JwtTest.java
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;
@simon04
simon04 / git.sh
Created January 14, 2020 07:16
Git merge/replace orphan branch into master
View git.sh
git checkout --orphan new-framework
# completely rewrite your application in new framework
git merge --strategy=ours --allow-unrelated-histories master
git commit-tree -p HEAD^2 -p HEAD^1 -m "Merge branch 'new-framework'" "HEAD^{tree}"
git reset --hard $OUTPUT_FROM_PREVIOUS_COMMAND
git checkout master
git merge --ff-only new-framework
View OSMSchema.xsd
<?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
View m4a2ogg
#!/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"
@simon04
simon04 / index.html
Created June 9, 2021 11:50
Leaflet example using JavaScript modules
View index.html
<!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>