This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xquery version "3.1"; | |
import module namespace sm="http://exist-db.org/xquery/securitymanager"; | |
import module namespace xmldb="http://exist-db.org/xquery/xmldb"; | |
(: these variables need to be set by the caller :) | |
declare variable $collection as xs:string external; | |
declare variable $group as xs:string? external; | |
declare variable $user as xs:string? external; | |
declare variable $mode as xs:string external; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xquery version "3.1"; | |
(: | |
: Parts of gist were taken from by https://mathling.com/code/art/core/utilities.xqy | |
: Copyright Mary Holstege 2020-2021 | |
: Licensed under CC-BY (https://creativecommons.org/licenses/by/4.0/) | |
: | |
: Parts are from the xbow library https://github.com/line-o/xbow | |
: by Juri Leino | |
: Licensed under MIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xquery version "3.1"; | |
(: | |
two possible solutions to @cassidoo's interview question from: | |
https://buttondown.email/cassidoo/archive/it-is-absolutely-imperative-that-every-human/ | |
:) | |
declare function local:product ($result, $next) { $result * $next }; | |
declare function local:grouping ($a, $b, $c) { | |
let $grouped := |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(: thanks to Reece H. Dunn for hinting at the fn:path function :) | |
//node()!(.,@*)!path() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xquery version "3.1"; | |
declare function local:distinct-order ($to-sort, $order) { | |
for $item in $to-sort[.=$order] | |
let $group-key := $item | |
group by $group-key | |
order by index-of($order, $group-key)[1] | |
return $group-key | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xquery version "3.1"; | |
declare namespace dicey="http://line-o.de/ns/dicey"; | |
declare function dicey:sequence ($n as xs:integer, | |
$generator as map(xs:string, item())) as item()* { | |
fold-left( | |
1 to $n, | |
map { "sequence": (), "generator": $generator}, | |
dicey:reducer#2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xquery version "3.1"; | |
module namespace qs="http://line-o.de/ns/qs"; | |
(:~ | |
: Append nothing to names of parameters with multiple values | |
: ?single=v1&multi=v2&multi=v3 | |
:) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xquery version "3.1"; | |
map { | |
"date" : current-dateTime(), | |
"packages" : array { | |
for $get-package-event in collection("/db/apps/public-repo-data/logs")//type[.="get-package"]/.. | |
group by $name := $get-package-event/package-name/string() | |
let $event-count := count($get-package-event) | |
order by $event-count descending | |
return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xquery version "3.1"; | |
declare variable $local:millisecond := xs:dayTimeDuration('PT0.001S'); | |
declare variable $local:max := 3000; | |
declare variable $local:reference := for-each(1 to $local:max, xs:string(?)); | |
declare variable $local:test := for-each((3 to 400, 402 to 2900), xs:string(?)); | |
declare function local:one () { | |
let $as-map := |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xquery version "3.1"; | |
(: adapted from https://stackoverflow.com/a/4936099 :) | |
declare function local:fib-reducer ($r, $n) { $r[1] + $r[2], $r[1] }; | |
declare function local:fib($n as xs:integer) { | |
fold-left((1 to $n), (0,1), local:fib-reducer#2)[1] | |
}; | |
let $results := |