Skip to content

Instantly share code, notes, and snippets.

Joe Wicentowski joewiz

Block or report user

Report or block joewiz

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@joewiz
joewiz / zip-barebones.xq
Created Jan 17, 2020
Construct a zip file and stream it to a browser, with XQuery & eXist
View zip-barebones.xq
xquery version "3.1";
let $node := <root><x/></root>
let $entry := <entry name="test.xml" type="xml">{$node}</entry>
let $zip := compression:zip($entry, true())
let $name := "test.zip"
return
response:stream-binary($zip, "media-type=application/zip", "test.zip")
@joewiz
joewiz / pay-periods-between-dates.xq
Created Jan 6, 2020
Generate a list of pay periods (two per month) between two dates, using XQuery
View pay-periods-between-dates.xq
xquery version "3.1";
import module namespace functx="http://www.functx.com";
(: Calculate the number of months between two dates, rounding down :)
declare function local:months-between-dates-floor($start-date as xs:date, $end-date as xs:date) {
local:months-between-dates-floor($start-date, $end-date, xs:yearMonthDuration("P0M"))
};
(: A helper function for local:months-between-dates-floor :)
@joewiz
joewiz / export-eXide-tabs.xq
Last active Dec 31, 2019
Save eXide editor tabs to disk
View export-eXide-tabs.xq
xquery version "3.1";
(:
# Save eXide editor tabs to disk
1. Install "LocalStorage Manager" Chrome extension
https://chrome.google.com/webstore/detail/localstorage-manager/fkhoimdhngkiicbjobkinobjkoefhkap
@joewiz
joewiz / group-by.xq
Last active Dec 31, 2019
How variables in XQuery FLWOR expressions change when using the "group by" clause
View group-by.xq
xquery version "3.1";
(:
## How variables in XQuery FLWOR expressions change when using the `group by` clause
Sometimes, when working with a `group by` clause, an XQuery FLWOR expression
might suddenly seem to act strangely, or at least unintuitively. In particular,
variables defined before the `group by` clause might suddenly seem to go haywire.
@joewiz
joewiz / show-http-request-headers.xq
Created Oct 22, 2019
Display all HTTP request headers for the current request (eXist-db)
View show-http-request-headers.xq
xquery version "3.1";
array {
request:get-header-names() ! map { . : request:get-header(.) }
}
@joewiz
joewiz / youngest-principal-officers-by-position.xq
Created Oct 21, 2019
Sort Principal Officers in a position by age at time of appointment
View youngest-principal-officers-by-position.xq
xquery version "3.1";
(: For a given Principal Officer position, calculate the age of the official at the time of
: appointment; sort the results by age. For officials missing birth or appointment dates,
: return the age as 0 to identify these as outliers with incomplete information.
:)
array {
let $principal-id := "assistant-secretary-legislative-affairs"
let $principal-doc := doc("/db/apps/pocom/positions-principals/" || $principal-id || ".xml")
@joewiz
joewiz / create-travels-tsv.xq
Last active Mar 14, 2019
Generate a TSV of Travels of the Secretary of State
View create-travels-tsv.xq
xquery version "3.1";
(: Generate a TSV of Travels of President and Secretary of State.
: Assumes https://github.com/HistoryAtState/travels has been installed.
:)
(:~
: A function for constructing a TSV (tab-separated value) file
:
: @param A sequence of column headings
@joewiz
joewiz / xquery-3.1-boilerplate.xq
Created Mar 4, 2019
XQuery 3.1 module boilerplate
View xquery-3.1-boilerplate.xq
xquery version "3.1";
(: Standard namespaces from https://www.w3.org/TR/xpath-functions-31/#namespace-prefixes :)
declare namespace array="http://www.w3.org/2005/xpath-functions/array";
declare namespace err="http://www.w3.org/2005/xqt-errors";
declare namespace fn="http://www.w3.org/2005/xpath-functions";
declare namespace map="http://www.w3.org/2005/xpath-functions/map";
declare namespace math="http://www.w3.org/2005/xpath-functions/math";
declare namespace output="http://www.w3.org/2010/xslt-xquery-serialization";
declare namespace xs="http://www.w3.org/2001/XMLSchema";
@joewiz
joewiz / package-library.md
Created Feb 5, 2019
Thoughts on a "package library" to replace eXist's "public repo"
View package-library.md

package-library

API

  1. add package
    • receive uploaded xar(s)
    • store upload(s) in "temp" folder
    • for each new package:
      • extract package metadata
      • validate package metadata
@joewiz
joewiz / data-composition.xqy
Last active Jun 4, 2019 — forked from xquery/data-composition.xqy
This works in BaseX and Saxon, but eXist returns an error: `exerr:ERROR cannot convert function(*)('') to a node set [at line 59, column 15]`
View data-composition.xqy
xquery version "3.0";
(: discovered via https://twitter.com/_james_fuller/status/1087706435176288257, updated with HTTP URL for data.xq :)
(: the power of algebraic data types in xquery
This example shows how we can composite up data models
which 'carry' their own operations along with them.
:)
You can’t perform that action at this time.