Skip to content

Instantly share code, notes, and snippets.

View apb2006's full-sized avatar

Andy Bunce apb2006

  • Quodatum
  • London, UK
View GitHub Profile
@apb2006
apb2006 / expire-test.xq
Last active May 10, 2022 17:46
BaseX Redis (with Jedis)
(: Redis interface test: expiring keys :)
declare namespace JedisPooled = "java:redis.clients.jedis.JedisPooled";
declare variable $REDIS:=JedisPooled:new("odroid.local", 6379);
let $_:=JedisPooled:set($REDIS,"name", "andy") (: create key :)
let $_:=JedisPooled:expire($REDIS,"name",10) (: expire in 10 secs :)
let $_:=JedisPooled:set($REDIS,"calls", "0")
(: query Redis as fast as possible until key disappears, returns number of queries made before expiry :)
return
@apb2006
apb2006 / b.xqm
Last active November 24, 2021 17:55
Module imports are not transitive https://www.w3.org/TR/xquery-30/#id-module-import
module namespace b = 'b';
import module namespace c = 'c' at 'c.xqm';
@apb2006
apb2006 / fib.xq
Created October 9, 2020 19:31
XQuery tail recursive Fibonacci function
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)
};
declare function local:fib($n as xs:integer){
local:fib($n,0,1)
};
@apb2006
apb2006 / cors.html
Last active August 8, 2020 17:01
BaseX CORS sample
<html>
<head>
<meta charset="utf-8" />
<title>BaseX CORS test (with Vue.js)</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="description" content="BaseX CORS test, (with Vue.js)" />
<meta name="author" content="andy bunce" />
</head>
<body>
<h1>BaseX CORS test, (with Vue.js)</h1>
@apb2006
apb2006 / subrip.xqm
Last active November 18, 2019 17:00
subtitle manipulation
(:~
:process srt subtitles
: @see https://en.wikipedia.org/wiki/SubRip
:)
module namespace s = 'quodatum.text.format.subrip';
declare function s:with-numbers($lines as xs:string*)
as xs:string*
@apb2006
apb2006 / sample.vtt
Last active August 15, 2019 13:54
bright cove test
WEBVTT
00:00:00.500 --> 00:00:02.000
Captions are always changing
00:00:02.500 --> 00:00:04.300
and the APIs we access it are changing
xquery version "3.0";
(:
Various Date String Parser
- Parses various flavors of date strings, returns as xs:dateTime or xs:date
- Key functions: dates:parseDateTime() and dates:parseDate()
- adapted to an eXist-compatible module from date-parser.xqy from
http://xqzone.marklogic.com/svn/commons/trunk/dates/date-parser.xqy
- by Joe Wicentowski
@apb2006
apb2006 / gist:b8b61319f1de4ebd795ebad5715317ac
Created January 17, 2019 21:57
basex error with service?
Exception in thread "Thread-305" Exception in thread "Thread-324" Exception in thread "Thread-326" Exception in thread "Thread-307" Exception in thread "Thread-308" Exception in thread "Thread-300" Exception in thread "Thread-286" java.lang.NullPointerException
at org.basex.core.locks.Locking.release(Locking.java:153)
at org.basex.core.jobs.Job.unregister(Job.java:59)
at org.basex.core.jobs.QueryJob.run(QueryJob.java:183)
at java.lang.Thread.run(Unknown Source)
java.lang.NullPointerException
at org.basex.core.jobs.QueryJob.run(QueryJob.java:186)
at java.lang.Thread.run(Unknown Source)
java.lang.NullPointerException
at org.basex.core.jobs.QueryJob.run(QueryJob.java:186)
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="description" content="BaseX socket test" />
<meta name="author" content="andy bunce." />
<title>BaseX Socket test v2</title>
</head
<body>
<h1>BaseX Socket test</h1>
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<!-- Force all communication over secure channels. -->
<Set name="handler">
<New id="Handlers" class="org.eclipse.jetty.server.handler.HandlerCollection">
<Set name="handlers">
<Array type="org.eclipse.jetty.server.Handler">
<Item>