Skip to content

Instantly share code, notes, and snippets.

View pschichtel's full-sized avatar

Phillip Schichtel pschichtel

View GitHub Profile
#!/usr/bin/env bash
set -euo pipefail
target_dir="${1?no target dir!}"
if [ -e "$target_dir" ]
then
echo "$target_dir already exists!" >&2
exit 1
fi
@pschichtel
pschichtel / unpack-legacy-p12.sh
Last active November 17, 2022 19:05
pfSense generates legacy p12 files which are not compatible with latest OpenSSL 3. This script unpacks the p12 file into separate PEM files, which work nicely with GNOME's network management stuff. See: https://github.com/openssl/openssl/commit/15c9aa3aef77c642ef2b6c84bba2b57b35ed083e
#!/usr/bin/env bash
input="${1?no input}"
key_output="${2?no key output}"
crt_output="${3?no crt output}"
ca_output="${4?no ca output}"
openssl pkcs12 -legacy -in "$input" -out "${key_output}" -nocerts -nodes
openssl pkcs12 -legacy -in "$input" -out "${crt_output}" -clcerts -nokeys
openssl pkcs12 -legacy -in "$input" -out "${ca_output}" -cacerts -nokeys
@pschichtel
pschichtel / CustomLocalValidatorFactoryBean.kt
Created August 17, 2021 14:53
SuspendAwareKotlinParameterNameDiscoverer
import org.hibernate.validator.internal.engine.DefaultClockProvider
import org.springframework.core.LocalVariableTableParameterNameDiscoverer
import org.springframework.core.PrioritizedParameterNameDiscoverer
import org.springframework.core.StandardReflectionParameterNameDiscoverer
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean
import java.lang.reflect.Constructor
import java.lang.reflect.Method
import javax.validation.ClockProvider
import javax.validation.Configuration
import javax.validation.ParameterNameProvider
@pschichtel
pschichtel / saml_helpers.sh
Created March 7, 2021 19:59
Keycloak SAML helpers
keycloak_to_pem() {
input="$(mktemp)"
echo "-----BEGIN $1-----" > "$input"
echo "$2" >> "$input"
echo "-----END $1-----" >> "$input"
output="$(mktemp)"
case "$1" in
"CERTIFICATE")
openssl x509 -inform PEM -in "$input" -out "$output"
;;
@pschichtel
pschichtel / .gitlab-ci.yml
Created February 7, 2021 02:10
Gitlab CI setup to build the discourse docker image on a docker-based gitlab-runner
services:
- name: postgres:12-alpine
alias: bootstrap-postgres
- name: redis:6
alias: bootstrap-redis
variables:
POSTGRES_DB: bootstrap
POSTGRES_USER: bootstrap
POSTGRES_PASSWORD: ''
@pschichtel
pschichtel / howto.md
Last active January 11, 2021 18:53
Batch script to enable IP forwarding on Windows. I use this to (ab)use Windows PCs as a Gateway into a site-to-site VPN.

Steps to setup external site

  1. Run setup_ip_forwarding.bat script to enable IP forwarding on Windows.
  2. Configure Windows firewall to accept traffic from all remote networks.
  3. Install wireguard and setup connection to central wireguard server with all remote networks as part of AllowedIPs and a unique IP within the wireguard network.
  4. Setup fritzbox to a custom local IP address range (e.g. 192.168.110.0/24) that is unique in all sites.
  5. Setup a static DHCP lease or a static IP for the local wireguard system.
  6. Setup static routes in fritzbox for each remote network using the local wireguard system's IP as the gateway/nexthop.
  7. For central wireguard server setup route for the network address range of the new external site.
@pschichtel
pschichtel / synthesize.sh
Created October 23, 2020 17:59
Small bash script that synthesizes text to speech using Google's services. The script expects the gcloud CLI tool, curl and jq installed in the path.
#!/usr/bin/env bash
voice="${1?no voice given!}"
gender="${2?no gender given!}"
text="${3?no text given!}"
file_name="${4:-"-"}"
access_token="$(gcloud auth application-default print-access-token)"
if echo "$text" | grep -q "<speak>"
then
@pschichtel
pschichtel / control_screen.sh
Last active January 1, 2021 19:33
Small script to control a screen using CEC
#!/usr/bin/env bash
device="${CEC_DEVICE:-0.0.0.0}"
command="${1?no command given}"
case "$command" in
on)
cec_command="on $device"
;;
@pschichtel
pschichtel / fourier.html
Created August 16, 2020 18:50
A simple FFT (fast fourier transform) implementation in browser JS
<!DOCTYPE html>
<html>
<head>
<title>Fourier</title>
<meta charset="UTF-8">
</head>
<body>
<textarea></textarea>
<table>
<thead>
@pschichtel
pschichtel / jsonpath.ts
Created July 14, 2020 21:53
A simple typescript script that parses json paths and composes a lense function
function extractorFor(selector: String): (x: any) => any {
function composeAccess(f: (x: any) => any, field: string): (x: any) => any {
return (x: any) => {
let r = f(x)
if (field in r) return r[field]
else return null
}
}