Skip to content

Instantly share code, notes, and snippets.

View line-o's full-sized avatar
🌱
weeding the garden

Juri Leino line-o

🌱
weeding the garden
View GitHub Profile
xquery version "3.1";
import module namespace xbow="http://line-o.de/xq/xbow";
let $length := 100000
let $sequence-of-maps := (1 to $length) ! map { "n": ., "values": ("a" || util:random(100), "b" || util:random(100), "c" || util:random(100)) }
let $keyed-sequence :=
@line-o
line-o / find-document-by-id.xq
Created March 29, 2020 08:05
Retrieve full path to a document in an exist-db collection when only its document ID is known
xquery version "3.1";
declare
function local:find($path, $document-id as xs:integer) as xs:string* {
local:find-in-collection($path, (), $document-id)
};
declare
function local:resource ($collection as xs:string, $resource as xs:string, $document-id as xs:integer) as xs:string? {
let $path := $collection || '/' || $resource
@line-o
line-o / mod-fn-stats.xq
Created February 16, 2020 21:35
existdb module and function name lengths
xquery version "3.1";
import module namespace xbow = "http://line-o.de/xq/xbow";
declare namespace xqdoc="http://www.xqdoc.org/1.0";
declare variable $local:length-category-rules := [
xbow:le(2), xbow:le(4), xbow:le(8), xbow:le(12), xbow:gt(12) ];
declare function local:gather-and-count ($names) {
$names
@line-o
line-o / random-number-generator.xq
Last active October 27, 2019 10:02
polyfill `fn:random-number-generator`
xquery version "3.1";
declare function local:random-number () {
util:random(1000000000) div 1000000000
};
declare function local:random-number-generator () {
map {
'number': local:random-number(),
'next': local:random-number-generator#0,
@line-o
line-o / example.xq
Last active June 19, 2019 13:27
xquery implementation to format dateTime in Internet Message Format
xquery version "3.1";
import module namespace imfd='http://existsolutions.com/apps/imfd' at '/db/temp/imfd.xqm';
let $now := current-dateTime()
let $tz := timezone-from-dateTime($now)
let $imfd := imfd:format($now)
let $gmt := imfd:to-dateTime($imfd)
let $reversed := adjust-dateTime-to-timezone($gmt + $tz, $tz)
xquery version "3.1";
declare namespace io = "http://io";
(: IO version of get-char :)
declare function local:get-char() as map(*) {
local:create-io(function($realworld as element(io:realworld)) {
($realworld, 123)
})
};
@line-o
line-o / boolean-sequence-tests.xqm
Last active January 8, 2019 16:31
Set of tests for filtering/ counting sequences of boolean values.
xquery version "3.1";
(:~
these tests were created because of
https://github.com/eXist-db/exist/issues/2308
~:)
module namespace boolseq="http://exist-db.org/xquery/xqsuite/boolseq";
declare namespace test="http://exist-db.org/xquery/xqsuite";
declare variable $boolseq:sequence := (true(), false(), true());
xquery version "3.1";
module namespace xg="http://existdb.org/xq/grammar";
declare namespace test="http://exist-db.org/xquery/xqsuite";
declare
%test:pending
%test:assertEquals("<root a='a'/>")
function xg:literalString() {
(:
: since the line below raises a static error, it cannot be tested this way
@line-o
line-o / console.log.js
Created December 10, 2018 11:52
`node console.log.js` will output process information, give a little insight on the inner workings and a ghost in between
__=`${![]}`
___=`${!![]}`
____=`${''[[]]}`
_____=`${{}}`
$={_:[]|[],$:!![]|[],$_:!![]<<!![],$$:!![]<<!![]|!![],$__:!![]<<!![]<<!![],$_$:!![]<<!![]<<!![]|!![],$$_:!![]<<!![]<<!![]|!![]<<!![],$$$:!![]<<!![]<<!![]|!![]<<!![]|!![],$___:!![]<<!![]<<!![]<<!![],$__$:!![]<<!![]<<!![]<<!![]|!![],$_$_:__[!![]|[]],$_$$:_____[!![]<<!![]],$$__:_____[!![]<<!![]<<!![]|!![]],$$_$:____[!![]<<!![]],$$$_:__[!![]<<!![]<<!![]],$$$$:__[[]|[]]}
$_=_$=>_$[`${_____[$.$$]}${_____[$.$]}${____[$.$_$]}${____[$.$]}`]('')
$$=$_([_____[$.$_$],_____[$.$],____[$.$],__[$.$$],___[$._],___[$.$],____[$._],_____[$.$_$],___[$._],_____[$.$],___[$.$]])
_=_$=>[][$$][$$]($_([___[$.$],__[$.$__],___[$._],___[$.$_],___[$.$],____[$.$],'"\\',___[$.$_],'{',$_(_$),'}"']))()
![][$$][$$]($_([_____[$.$_$],_____[$.$],____[$.$],__[$.$$],_____[$.$],__[$.$_],__[$.$__],'.',__[$.$_],_____[$.$],_([$.$$_,$.$$$]),'(',_([$.$$$,$._]),___[$.$],_____[$.$],_____[$.$_$],___[$.$$],__[$.$$],__[$.$$],',"',_([$.$,$.$$$$,$.$__,$.$$$,$.$_$$]),'",$,`${_}`,`${$_}`)']))()
@line-o
line-o / pw-reset.xq
Last active November 8, 2018 04:34
Rough sketch of a password reset for eXist-db
xquery version '3.1';
(:~
this script must be run with a user in the DBA group
add this line to your post-install script or run it manually
it will set the GID sticky bit
chown('/path/to/this/script.xq', 'admin', 'dba')
chmod('/path/to/this/script.xq', 'rwxr-S---')
:)