Skip to content

Instantly share code, notes, and snippets.

View bwbroersma's full-sized avatar
🐛
looking for bugs

Benjamin W. Broersma bwbroersma

🐛
looking for bugs
View GitHub Profile
@bwbroersma
bwbroersma / kcni2023.awk
Created March 19, 2023 20:14
🗳️ Voorlopige zetelberekening voor KCNI2023 met AWK
#!/bin/awk
# AUTHOR: Benjamin W. Broersma
# DISCLAIMER: special cases are *NOT* handled correctly
# input: "\d+. \tAanduiding\t123"
# output: pipe to $ column -t -s $'\t' -R 1,3,4 -o ' | '
# call like:
# $ curl -sSfA '' https://www.denhaag.nl/nl/in-de-stad/nieuws/voorlopige-uitslag-verkiezing-kiescollege-niet-ingezetenen-1.htm --compressed | xmllint --html --xmlout - 2>/dev/null | xmlstarlet sel -t -m '/_:html/_:body//_:table/_:tbody/_:tr[position()!=last()]' -c '_:td[1]/text()' -o $'\t' -c '_:td[2]/text()' -n -b | cut -c2- | awk -f kcni2023.awk | column -t -s $'\t' -R 1,3,4 -o ' | '
CREATE EXTENSION pgcrypto;
CREATE OR REPLACE FUNCTION totp(key BYTEA, clock_offset INT DEFAULT 0) RETURNS INT AS $$
DECLARE
c BYTEA := '\x000000000' || TO_HEX(FLOOR(EXTRACT(EPOCH FROM NOW()) / 30)::INT + clock_offset);
mac BYTEA := HMAC(c, key, 'sha1');
trunc_offset INT := GET_BYTE(mac, 19) % 16;
result INT := SUBSTRING(SET_BIT(SUBSTRING(mac FROM 1 + trunc_offset FOR 4), 7, 0)::TEXT, 2)::BIT(32)::INT % 1000000;
BEGIN
RETURN result;
END;
@bwbroersma
bwbroersma / tk-vs-peilingwijzer.awk
Created July 29, 2022 20:29
De 'is het electoraal logisch dat er ontbindingsverkiezingen komen'-AWK script.
BEGIN {
FS=";";
}
function abs(v) {
return v < 0 ? -v : v;
}
function cp(i1, v1, i2, v2) {
if (v1 > v2)
return -1;
else if (v1 == v2)
@bwbroersma
bwbroersma / client-side-air-gap-check.js
Created May 19, 2022 12:44
JS client side check to detect a possible internet connection (breach of air-gap)
/*jslint browser*/
/* Content-Security-Policy: connect-src 'self'
https://enable-cors.org/index.html
https://1.1.1.1/cdn-cgi/trace
https://1.0.0.1/cdn-cgi/trace;
IPv6 is not yet supported by CSP:
https://github.com/w3c/webappsec-csp/issues/224
*/
(function () {
"use strict";
@bwbroersma
bwbroersma / export.sh
Last active February 22, 2022 19:34
How to convert EMLNL candidate lists to CSV and JSON
#!/bin/bash
# c2j can be found here https://github.com/bwbroersma/csv2jsonl/ or be replace with the slower csvjson from csvkit, use --stream! (https://csvkit.readthedocs.io/en/latest/scripts/csvjson.html)
# add -C for the generated xslt (added below)
TS="$(date -u -Iminute|sed 's/+00:00//g;s/:/./')"
CSV="GR2022_alle-kandidaten_$TS.csv";
JSON="GR2022_alle-kandidaten_$TS.json";
(echo -e "\xEF\xBB\xBFGemeenteCode;GemeenteNaam;LijstNummer;LijstNaam;DocumentTaal;PublicatieGeslacht;KandidaatNummer;Initialen;Roepnaam;Tussenvoegsel;Achternaam;Woonplaats;Land;Geslacht";
xmlstarlet sel \
-N eml="urn:oasis:names:tc:evs:schema:eml" \
-N kr="http://www.kiesraad.nl/extensions" \
{"v":"5.7.1","fr":30,"ip":0,"op":151,"w":335,"h":256,"nm":"Fietser_App3","ddd":0,"assets":[{"id":"comp_0","layers":[{"ddd":0,"ind":1,"ty":4,"nm":"Hoofd","parent":5,"hd":true,"sr":1,"ks":{"o":{"a":0,"k":100,"ix":11},"r":{"a":0,"k":-5,"ix":10},"p":{"a":0,"k":[1.251,35.186,0],"ix":2},"a":{"a":0,"k":[0,0,0],"ix":1},"s":{"a":0,"k":[100,100,100],"ix":6}},"ao":0,"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ix":1,"ks":{"a":1,"k":[{"i":{"x":0.67,"y":1},"o":{"x":0.167,"y":0},"t":-31,"s":[{"i":[[23.327,2.845],[4.995,23.158],[0,0],[-3.519,-23.328]],"o":[[-0.593,-0.072],[-2.703,-12.531],[0,0],[2.99,19.82]],"v":[[384.851,-50.454],[393.534,-81.892],[381.104,-98.296],[410.562,-82.062]],"c":true}]},{"i":{"x":0.67,"y":1},"o":{"x":0.167,"y":0},"t":-23,"s":[{"i":[[23.327,2.845],[4.995,23.158],[0,0],[-3.519,-23.328]],"o":[[-0.593,-0.072],[-2.703,-12.531],[0,0],[2.99,19.82]],"v":[[384.851,-50.454],[393.534,-81.892],[381.104,-98.296],[410.562,-82.062]],"c":true}]},{"i":{"x":0.67,"y":1},"o":{"x":0.33,"y":0},"t":-11,"s":[{"i":[[23.
#!/bin/sh
# check https://www.icao.int/Security/FAL/PKD/Pages/ICAO-Master-List.aspx for the URL
curl -OL 'https://www.icao.int/Security/FAL/PKD/MasterListAD3172FF-9D1E-4589-91D5-34C3793053F0/ICAO_ml_2021.04.06.ml'
binwalk ICAO_ml_2021.04.06.ml | awk '{system("dd bs=1 skip="$1" count="($14+4)" if=ICAO_ml_2021.04.06.ml of="$1".cer")}'
# for f in *.cer; do >&2 echo -n "$f:"; openssl x509 -inform DER -subject -noout -in $f 2>/dev/null; done | grep 'C = NL'
#!/bin/sh
if [ "$#" -ne 2 ]; then
>&2 echo "Usage: $0 YEAR audio.mp3"
exit 1
fi
if [ ! -f "$2" ]; then
>&2 echo "$2 does not exist."
exit 1
fi
command -v curl >/dev/null 2>&1 || { echo >&2 "Please install 'curl' first: $ sudo apt install curl."; exit 1; }
@bwbroersma
bwbroersma / details-CSS-only-fallback.html
Last active June 24, 2020 23:24
details fallback with 3 extra (hidden) HTML nodes + copy of all summary inner nodes per detail and 19 lines of CSS (for IE11 and Edge 12-18)
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8>
<title>test</title>
</head>
<body>
<details class="details">
<summary class="summary">click me to open1</summary>
<input type="checkbox" id="toggle1" aria-hidden="true">