Skip to content

Instantly share code, notes, and snippets.

@hoel-zr-o
hoel-zr-o / functions.jq
Created May 30, 2025 16:34
Some jq functions
def parse_duration:
[scan("(?:(\\d+)m)|(?:(\\d+[.]\\d+)s)|(?:(\\d+[.]\\d+)ms)") | (60000 * ((.[0] // "0") | tonumber)) + (1000 * ((.[1] // "0") | tonumber)) + ((.[2] // "0") | tonumber) ] | reduce .[] as $item (0; . + $item) ;
def logfmt:
[ scan("(\\w+)=(?:(?:\"([^\"]+)\")|(\\S+))\\s*") | {key: .[0], value: (.[1] // .[2])}] | from_entries ;
@hoel-zr-o
hoel-zr-o / go.mod
Created April 24, 2025 21:55
PromQL → JSON AST tool
module example.com/alert-rule-experiment
go 1.23.6
require github.com/prometheus/prometheus v0.301.0
require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/dennwc/varint v1.0.0 // indirect