Skip to content

Instantly share code, notes, and snippets.

View adamretter's full-sized avatar
🎩
Down the Code Mine

Adam Retter adamretter

🎩
Down the Code Mine
View GitHub Profile
@adamretter
adamretter / cats-effect-mock-service-app.scala
Created May 31, 2023 11:49
Mock Scala cats-effect Service that runs forever in a CLI App
package uk.gov.nationalarchives.omega.api
import cats.effect.std.Supervisor
import cats.effect.{ExitCode, IO, IOApp}
import scala.concurrent.duration.DurationInt
object MockApp extends IOApp {
@adamretter
adamretter / QueueIO
Last active November 15, 2022 14:55
package uk.gov.nationalarchives.omega.api
import cats.effect.{ExitCode, IO, IOApp, Temporal}
import cats.effect.std.Queue
import java.util.UUID
import scala.concurrent.duration.DurationInt
object QueueExample extends IOApp {
let $permArray := function($myAr as array(*))
{
let $extend := function($ar as array(*), $mem as item()*)
{
array{
for $i in 1 to (array:size($ar) +1)
return
array:insert-before($ar, $i, $mem)
}
}
@adamretter
adamretter / flatten-array.xqm
Created July 27, 2022 12:17
flatten-array.xqm
declare function local:flatten-once($ar as array(*)) as array(*) {
array:fold-left($ar, array{}, function($x, $y){
array:join(($x,
if ($y instance of array(*))
then
array { $y?* }
else
array { $y } (: for array(t) -> array(t) :)
))
})
@adamretter
adamretter / permutations.xqm
Created July 27, 2022 12:16
permutations.xqm
declare function local:permutations($list as array(*)) as array(array(*)) {
if (array:size($list) eq 0)
then
array {}
else if (array:size($list) eq 1)
then
array { $list }
else
@adamretter
adamretter / xdm-type.xqm
Last active January 7, 2023 06:22
xdm-type.xqm
declare function local:xdm-type($value as item()?) as xs:QName? {
typeswitch($value)
case array(*) return xs:QName("array")
case map(*) return xs:QName("map")
case function(*) return xs:QName("function")
case document-node() return xs:QName("document")
case element() return xs:QName("element")
case attribute() return xs:QName("attribute")
case comment() return xs:QName("comment")
case processing-instruction() return xs:QName("processing-instruction")
```
[ERROR] Exit code: 1 - /Users/aretter/code/exist.maven2/exist-core/src/main/java/org/exist/test/TransactionTestDSL.java:84: error: unterminated inline tag
[ERROR] * <pre>{@code
[ERROR] ^
[ERROR] /Users/aretter/code/exist.maven2/exist-core/src/main/java/org/exist/test/TransactionTestDSL.java:89: error: unknown tag: Test
[ERROR] * @Test
[ERROR] ^
[ERROR] /Users/aretter/code/exist.maven2/exist-core/src/main/java/org/exist/test/TransactionTestDSL.java:93: error: malformed HTML
@adamretter
adamretter / dtx.xqm
Last active January 22, 2020 21:22
Date/Time/DateTime XQuery functions
import module namespace functx = "http://www.functx.com";
(: NOTE -- functx uses 1 to 7 to represent MON-SUN, whereas eXist-db's datetime module used 1 to 7 to represent SUN-SAT :)
declare variable $local:MON := 1;
declare variable $local:TUES := 2;
declare variable $local:WEDS := 3;
declare variable $local:THURS := 4;
declare variable $local:FRI := 5;
declare variable $local:SAT := 6;
@adamretter
adamretter / exist-message-digest-algs.txt
Last active November 13, 2018 03:31
MessageDigest algorithms offered by eXist-db
PROVIDER | ALGORITHM
-----------|------------
SUN
MD2
MD5
SHA
SHA-224
SHA-256
SHA-384
SHA-512
@adamretter
adamretter / JMXServletTest.java
Created August 17, 2018 06:55
org.exist.management.client.JMXServletTest
/*
* eXist Open Source Native XML Database
* Copyright (C) 2001-2018 The eXist Project
* http://exist-db.org
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*