Skip to content

Instantly share code, notes, and snippets.

@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
@joewiz
joewiz / Second Tuesdays.md
Last active November 18, 2021 15:59
Second Tuesdays of the year, with XQuery

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).

@philippn
philippn / create-pipeline.xsl
Last active September 6, 2019 16:47
A XSL transformation that constructs a single bootstrap.xsl from a bunch of XSL files comprising a pipeline. Useful for getting a XSL pipeline to work in Saxon-JS. In order to do so, first run this XSL, then compile the resulting bootstrap.xsl into SEF format, i.e. by using Oxygen.
<xsl:stylesheet
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:variable name="steps" select="collection('./xsl?select=*.xsl')" as="node()*"/>
<xsl:template match="/">
<xsl:for-each select="$steps">
<xsl:sort select="tokenize(base-uri(.), '/')[last()]"/>
<xsl:variable name="filename" select="tokenize(base-uri(.), '/')[last()]" as="xs:string"/>
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
xquery version "3.0";
module namespace r = "http://joewiz.org/ns/xquery/roman-numerals";
(: Converts standard Roman numerals to integers.
: Handles additive and subtractive but not double subtractive.
: Case insensitive.
: Doesn't attempt to validate a numeral other than a naïve character check.
: See discussion of standard modern Roman numerals at:
: http://en.wikipedia.org/wiki/Roman_numerals.
@joewiz
joewiz / restxq-template.xqm
Created November 23, 2014 04:04
A starter template for a RestXQ module
xquery version "3.0";
module namespace my-app = "http://my/app";
(: A starter template for a RestXQ module.
Save this file into eXist anywhere (e.g., /db/restxq-template.xqm or /db/apps/my-app/modules/restxq-template.xqm),
And access at http://localhost:8080/exist/restxq/index.html.
(Why? Because /restxq is the URL space for RestXQ, and the function's %rest:path annotation is for requests to "/index.html".)
Note that the collection configuration file where you store the module must invoke the RestXQ trigger:
<collection xmlns="http://exist-db.org/collection-config/1.0">
@wsalesky
wsalesky / git-sync.xql
Last active August 19, 2019 08:58
Sync remote eXistdb with github repository automatically using github webhooks.
xquery version "3.0";
(:module namespace gitsync = "http://syriaca.org/ns/gitsync";:)
(:~
: XQuery endpoint to respond to Github webhook requests. Query responds only to push requests.

: The EXPath Crypto library supplies the HMAC-SHA1 algorithm for matching Github secret. 

:
: Secret can be stored as environmental variable.
: Will need to be run with administrative privileges, suggest creating a git user with privileges only to relevant app.
// XPath CheatSheet
// To test XPath in your Chrome Debugger: $x('/html/body')
// http://www.jittuu.com/2012/2/14/Testing-XPath-In-Chrome/
// 0. XPath Examples.
// More: http://xpath.alephzarro.com/content/cheatsheet.html
'//hr[@class="edge" and position()=1]' // every first hr of 'edge' class
<project name="gradle-ant" default="" basedir=".">
<!--
Inspired by Ray Myers
https://gist.github.com/raymyers/735788
-->
<property environment="env" />
<condition property="gradle.home.executable" value="${env.GRADLE_HOME}/bin/gradle.bat" else="${env.GRADLE_HOME}/bin/gradle">
@barryvdh
barryvdh / _ide_helper.php
Last active August 5, 2024 20:45
Laravel IDE Helper for Netbeans / PhpStorm / Sublime Text 2 CodeIntel, generated using https://github.com/barryvdh/laravel-ide-helper
<?php
/**
* A helper file for Laravel 5, to provide autocomplete information to your IDE
* Generated for Laravel 5.5.13 on 2017-09-28.
*
* @author Barry vd. Heuvel <barryvdh@gmail.com>
* @see https://github.com/barryvdh/laravel-ide-helper
*/
namespace {
exit("This file should not be included, only analyzed by your IDE");