Skip to content

Instantly share code, notes, and snippets.

Avatar

Joe Wicentowski joewiz

  • Arlington, Virginia
View GitHub Profile
@joewiz
joewiz / json-ignore-whitespace-text-nodes-param.xq
Created January 25, 2023 18:43
Sample code using eXist-db json-ignore-whitespace-text-nodes parameter
View json-ignore-whitespace-text-nodes-param.xq
xquery version "3.1";
(: @see https://github.com/eXist-db/exist/commit/53bdb54c664a8063e43392e0b0fb9eac57baf67d#diff-fc5225a3545e6b6807e7810bc9e40219500842a68dbb49a7eb83670016b160ab :)
declare boundary-space preserve;
let $json-ignore-whitespace-text-nodes-param-xml :=
<output:serialization-parameters xmlns:output="http://www.w3.org/2010/xslt-xquery-serialization">
<output:method value="json"/>
<exist:json-ignore-whitespace-text-nodes value="yes"/>
@joewiz
joewiz / latest-package-versions-csv.xq
Last active January 12, 2023 19:02
Generate a CSV containing the latest versions of packages for different
View latest-package-versions-csv.xq
xquery version "3.1";
import module namespace versions="http://exist-db.org/apps/public-repo/versions" at "/db/apps/public-repo/modules/versions.xqm";
let $exist-versions := ("4.11.0", "5.5.1", "6.1.0")
let $abbrevs := ("shared-resources", "dashboard", "doc", "eXide", "functx", "fundocs", "markdown", "monex", "usermanager")
let $header-row := ("package", $exist-versions ! ("eXist " || .)) => string-join(", ")
let $body-rows :=
for $abbrev in $abbrevs
let $packages := doc("/db/apps/public-repo-data/metadata/package-groups.xml")//package-group[abbrev = $abbrev]//package
@joewiz
joewiz / list-packages.xq
Last active January 3, 2023 17:50
List EXPath Packages installed on an eXist-db system
View list-packages.xq
xquery version "3.1";
declare namespace output="http://www.w3.org/2010/xslt-xquery-serialization";
declare namespace pkg="http://expath.org/ns/pkg";
declare option output:method "html";
declare option output:html-version "5.0";
declare option output:media-type "text/html";
declare function local:sort-packages($packages as element(pkg:package)*) as element(pkg:package)* {
@joewiz
joewiz / system-properties.xq
Created March 10, 2022 18:32
Display all system properties and their values - for eXist-db
View system-properties.xq
xquery version "3.1";
(: @see https://exist-db.org/exist/apps/fundocs/index.html?q=util:system-property
: @see https://github.com/eXist-db/exist/blob/develop/exist-core/src/main/resources-filtered/org/exist/system.properties
:)
let $exist-properties :=
(
"vendor",
"vendor-url",
"product-name",
@joewiz
joewiz / merge-fragments.xq
Last active January 5, 2022 17:03
Merge XML fragments into a composite document
View merge-fragments.xq
xquery version "3.1";
(:~ Merge XML fragments with the same root node into a composite document.
: Based on a question from the exist-open mailing list.
:
: @see https://markmail.org/message/gdrhscaobyya44we
:)
(: Compare the fragment to the composite document. If the node names match,
@joewiz
joewiz / Second Tuesdays.md
Last active November 18, 2021 15:59
Second Tuesdays of the year, with XQuery
View Second Tuesdays.md

Today in exist-open, Slav asked:

Hi, anyone have function for calculate all second Tuesdays for year?

(That is, Patch Tuesdays.)

Below are two approaches—one that solves the problem directly (finding only 2nd Tuesdays) and one more generally (finding any combination of week of the month and day of the week, e.g., 5th Sundays).

@joewiz
joewiz / chmod-recursive.xq
Created June 3, 2021 20:54
Batch change permissions on resources and collections in eXist-db
View chmod-recursive.xq
xquery version "3.1";
import module namespace dbutil="http://exist-db.org/xquery/dbutil";
dbutil:scan(
xs:anyURI("/db/apps/airlock-data"),
function($col, $res) {
if ($res) then
(: Set permissions on resources here :)
(
@joewiz
joewiz / list-packages-with-dependency.xq
Created June 2, 2021 15:50
Find which EXPath packages declare a particular dependency, in eXist-db
View list-packages-with-dependency.xq
xquery version "3.1";
declare namespace pkg="http://expath.org/ns/pkg";
array {
for $app in xmldb:get-child-collections("/db/apps")
let $package-metadata := doc("/db/apps/" || $app || "/expath-pkg.xml")
where $package-metadata//pkg:dependency[@package eq "http://exist-db.org/apps/shared"]
order by $app
return
@joewiz
joewiz / fib-exist.xq
Last active October 10, 2020 16:51 — forked from apb2006/fib.xq
XQuery tail recursive Fibonacci function, with timing, for eXist-db
View fib-exist.xq
xquery version "3.1";
(: forked from https://gist.github.com/apb2006/4eef5889017be4a50685a467b2754d27
: with tests returned in the style of https://so.nwalsh.com/2020/10/09-fib :)
declare function local:fib($n as xs:integer, $a as xs:integer, $b as xs:integer){
switch ($n)
case 0 return $a
case 1 return $b
default return local:fib($n - 1, $b, $a + $b)
@joewiz
joewiz / check-text-for-ocr-typo-patterns.xq
Last active April 9, 2021 03:30
Check a text for OCR typo patterns, using XQuery
View check-text-for-ocr-typo-patterns.xq
xquery version "3.1";
(:~
: Find possible OCR errors in a text by checking for patterns that an OCR
: process is known to misread, e.g., "day" misread as "clay", or "France"
: misread as "Prance." If the OCR engine just misread some instances of these
: words but got other instances correct, then this query will highlight
: candidates for correction.
:
: The query lets you configure a source text and define pattern sets to be used.