Skip to content

Instantly share code, notes, and snippets.

@hoehrmann
hoehrmann / README.md
Last active May 3, 2024 22:21
SDMX-ML 2.0, SDMX-ML 2.1, SDMX-ML 3.0.0 structure messages to SDMX-JSON conversion rules

Missing:

  • A few elements allow infinite nesting, that is not yet represented
  • Some TODOs are mentioned in the YAML files directly.
  • Where XML paths have more variables than the JSON paths, variables have to be reviewed; Usually that means the first [n] in the JSON path would become [n,o] (SDMX-ML 3.0.0 distributes artefacts in a way that requires aggregation in SDMX-JSON 2.0)

Note:

  • SDMX 2.0 and SDMX 2.1 are converted to SDMX-JSON 1.0
  • SDMX 3.0.0 is converted to SDMX-JSON 2.0.0.
@hoehrmann
hoehrmann / xml-to-json-rules.yaml
Created April 21, 2024 23:14
XML to JSON mapping rule definitions
#
# In a JSON document, there is a unique normalized JSON Path for everything,
# so you can write out a JSON document as a combination of paths and values:
#
# $.meta.id = "ID123"
#
# Given some JSON schema document, you can write out all possible paths. To
# handle infinite nesting, part of the path could be described using a regular
# expression.
#
@hoehrmann
hoehrmann / json-to-json-path-lines.py
Last active April 16, 2024 22:07
Convert a JSON document into ndjson arrays with URI, RFC 9535 JSON Path (normalized and unique) and JSON value
import click
import ijson
import ijson.common
import json
import pathlib
import functools
def escape(s: str):
esc = {
"\u0000": "\\u0000",
@hoehrmann
hoehrmann / sqlite3_profile.c
Last active March 15, 2023 23:02
Quick and dirty LD_PRELOAD SQLite query logger/profiler
// This is now https://github.com/federlieb/federprof
@hoehrmann
hoehrmann / c11-lexer-grammar
Created June 22, 2018 22:10
C11 Lexer grammar
token = _
/ keyword
/ identifier
/ constant
/ string-literal
/ punctuator
preprocessing-token = _
/ header-name
/ identifier
@hoehrmann
hoehrmann / sqlite.abnf
Created June 9, 2019 18:57
ABNF for SQLite 3.28 SQL
; FIXME: The grammar has been transformed so that `w` appears after a
; token, but there is no way in ABNF to define it as token-separator
; that can optionally contain a mix of comments and white-space. Take
; `;;` as an example, for that to match `sql-stmt-list` `w` would
; have to match the empty string. But if `w` matches the empty string
; then `ISNOT` is the same as `IS NOT`.
sql-stmt-list = [ sql-stmt ] *( ";" w [ sql-stmt ] )
sql-stmt = [ "EXPLAIN" w [ "QUERY" w "PLAN" w ] ] ( alter-table-stmt / analyze-stmt / attach-stmt / begin-stmt / commit-stmt / create-index-stmt / create-table-stmt / create-trigger-stmt / create-view-stmt / create-virtual-table-stmt / delete-stmt / delete-stmt-limited / detach-stmt / drop-index-stmt / drop-table-stmt / drop-trigger-stmt / drop-view-stmt / insert-stmt / pragma-stmt / reindex-stmt / release-stmt / rollback-stmt / savepoint-stmt / select-stmt / update-stmt / update-stmt-limited / vacuum-stmt )
alter-table-stmt = "ALTER" w "TABLE" w [ schema-name w "." w ] table-na
@hoehrmann
hoehrmann / ucdxml2sqlite.pl
Created May 26, 2013 10:56
Unicode Database XML dump to SQLite database. The attached script takes the ucd.all.flat.xml database and turns it into a SQLite database. Originally http://lists.w3.org/Archives/Public/www-archive/2009Feb/0014.html
#!perl -w
use strict;
use warnings;
use DBI;
use IO::File;
use XML::Parser;
my %fields;
my @fields;
@hoehrmann
hoehrmann / commatools.pl
Created May 31, 2013 11:01
Perl script implementing "Comma tools" that can be chained. Originally http://lists.w3.org/Archives/Public/public-qa-dev/2004May/0023.html
#!perl -w
use strict;
use warnings;
use URI::Escape 'uri_escape';
sub tool
{
my $req = shift;
return unless defined $req;
@hoehrmann
hoehrmann / scriptrec.sh
Created April 26, 2016 22:47
Automatically record bash sessions
#####################################################################
#
# This script starts an automatically recorded session using `script`
# storing logs in `$log_dir`. Care should be taken to secure records
# generated by this script as they may easily contain passwords and
# other sensistive information.
#
#####################################################################
# FIXME(bh): make this configurable
#!/bin/bash
#####################################################################
# Copyright (c) 2016 Bjoern Hoehrmann <bjoern@hoehrmann.de>. GPLv3+.
#
# Given image + color, creates mask encoding pixel's LAB color diff.
#####################################################################
path_in="$1"
color_rgb="$2"
path_out="$3"