dev
tools for programmers: login tokens, URLs, version numbers and file permissions, plus networks, IDs, colors, binaries and hardware
Small tools for programming work. They cover login tokens, URLs, version numbers and file permissions, and the submodules add networking, IDs, colors, binary files and hardware.
jwtdecode a JSON Web Token, the login token many websites and APIs send, into {header, payload, signature}jwt_signsign claims as a JSON Web Token with an HMAC key, which jwt reads backjwt_verifywhether a JSON Web Token’s HMAC signature matches the keyurl_parsesplit a URL into its parts: {scheme, host, port, path, query, fragment}url_buildput a URL together from a map of its parts, the reverse of url_parsesemverparse a semantic version like “1.2.3-beta+5” into {major, minor, patch, pre, build}bumpthe next versionchmodconvert Unix file permissions between the number form, like 755, and the letters ls -l shows, like “rwxr-xr-x”
Functions
Section titled “Functions”jwt(s: str) -> map
decode a JSON Web Token, the login token many websites and APIs send, into {header, payload, signature}
The payload holds claims like who the user is, and its exp, iat and nbf times (expires, issued at, not before) become dates. The signature is not checked, so use this to read a token, never to decide whether to trust one
1jwt("eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhZGEiLCJleHAiOjE5MjQ5OTIwMDB9.c2ln").payload.exp2030-12-31 18:00:00 -06:00Tags: crypto
jwt_sign
Section titled “jwt_sign”jwt_sign(claims: map, key: str, alg: str = “HS256”) -> str
sign claims as a JSON Web Token with an HMAC key, which jwt reads back
alg is “HS256”, “HS384” or “HS512”. Dates under exp, iat and nbf become Unix seconds, as tokens store them
1jwt_sign({sub: "ada", admin: true}, "secret")"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhZGEiLCJhZG1pbiI6dHJ1ZX0.LG5jqWCrAAWbUMv6IIF_kHEjmYwSQrtDQajAELdwFLs"2jwt(jwt_sign({sub: "ada", exp: now + 1 h}, "secret")).payload{sub: "ada", exp: 2026-11-04 13:12:41 -06:00}Tags: crypto
See also jwt, jwt_verify, hmac
jwt_verify
Section titled “jwt_verify”jwt_verify(token: str, key: str) -> bool
whether a JSON Web Token’s HMAC signature matches the key
Only HS256, HS384 and HS512 tokens can match, so one with alg “none” or anything else is false. The exp and nbf times aren’t checked, so look at jwt(token).payload too
1jwt_verify(jwt_sign({sub: "ada"}, "secret"), "secret")true2jwt_verify(jwt_sign({sub: "ada"}, "secret"), "guess")falseTags: crypto
url_parse
Section titled “url_parse”url_parse(s: str) -> map
split a URL into its parts: {scheme, host, port, path, query, fragment}
The query string becomes a map, and a key that appears more than once gets a list of its values
1url_parse("https://example.com:8080/a/b?x=1&y=two%20words#top"){scheme: "https", host: "example.com", port: 8080, path: "/a/b", query: {x: "1", y: "two words"}, fragment: "top"}Tags: parsing
url_build
Section titled “url_build”url_build(m: map) -> str
put a URL together from a map of its parts, the reverse of url_parse
Parts that are missing are left out
1url_build({scheme: "https", host: "example.com", path: "/search", query: {q: "a b"}})"https://example.com/search?q=a%20b"Tags: formatting
See also url_parse
semver
Section titled “semver”semver(s: str) -> map
parse a semantic version like “1.2.3-beta+5” into {major, minor, patch, pre, build}
Three numbers, then an optional pre-release tag after - and build info after +. Compared as plain text, “1.10.0” sorts before “1.9.0”. The result compares by the versioning rules instead, against another semver or a plain version string, so 1.10.0 is newer and 2.0.0-rc.1 comes before 2.0.0
1semver("1.2.3") < semver("1.10.0")true2semver("1.0.0-beta") < "1.0.0"true3semver("v2.1.0-rc.1+build5"){major: 2, minor: 1, patch: 0, pre: "rc.1", build: "build5"}Tags: parsing
See also bump
bump(v: str|map, part: str) -> str|map
the next version
From 1.2.3, “major” gives 2.0.0, “minor” 1.3.0 and “patch” 1.2.4. A pre-release of the version you’d bump to, like 2.0.0-rc.1 with “major”, becomes that release, 2.0.0
1bump("1.2.3", "minor")"1.3.0"2bump("2.0.0-rc.1", "major")"2.0.0"See also semver
chmod(mode: int) -> str / chmod(mode: str) -> int
convert Unix file permissions between the number form, like 755, and the letters ls -l shows, like “rwxr-xr-x”
Each digit, or group of three letters, is read (r), write (w) and execute (x) for the file’s owner, its group, and everyone else
1chmod(755)"rwxr-xr-x"2chmod("rw-r--r--")0o6443chmod(0o4755)"rwsr-xr-x"Tags: files
More examples
Section titled “More examples”1# what's in this token?2jwt("eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhZGEiLCJpYXQiOjE1MTYyMzkwMjJ9.c2ln").payload{sub: "ada", iat: 2018-01-17 19:30:22 -06:00}3# query string of a URL4url_parse("https://example.com/search?q=zil&page=2").query{q: "zil", page: "2"}5# is 1.10 newer than 1.9?6semver("1.10.0") > "1.9.3"true7# chmod 640 means8chmod(640)"rw-r-----"Example results generated on 2026-11-04. Ones using now, today or randomness will differ when you run them.