Skip to content

Instantly share code, notes, and snippets.

View joewiz's full-sized avatar

Joe Wicentowski joewiz

  • Arlington, Virginia
View GitHub Profile
@joewiz
joewiz / 01-secretary-of-state-travels-to-a-country.xq
Last active August 28, 2015 16:21
Travels of the Secretary of State, grouped by secretary, showing duration of visits in a country, using XQuery
xquery version "3.0";
let $results :=
for $trip in collection('/db/cms/apps/travels/data/secretaries')/trips/trip[country/@id = 'israel']
let $duration := days-from-duration(sum($trip ! (./xs:date(end-date) - ./xs:date(start-date) + xs:dayTimeDuration('P1D'))))
group by $secretary := $trip/name
return
<trips secretary="{$secretary}" trips="{count($trip)}" days="{$duration}">{
$trip !
<trip>{
@joewiz
joewiz / generate-xfdf.xq
Created February 13, 2014 05:40
Generate XFDF data for use in filling a PDF form, with XQuery; see http://joewiz.org/2014/02/13/filling-pdf-forms-with-pdftk-xfdf-and-xquery/
xquery version "3.0";
import module namespace functx="http://www.functx.com";
(: Prepare XFDF data to use with PDFtk to populate a blank form SF702,
e.g., http://www.archives.gov/isoo/security-forms/sf702.pdf,
with data for each month of the year :)
let $data-collection := xmldb:create-collection('/db', 'sf702')
let $year := 2014
<?xml-model href="../../schemas/frus.rnc" type="application/relax-ng-compact-syntax"?>
@joewiz
joewiz / days-since-date.xq
Created April 21, 2014 14:01
How many days have you been alive, with XQuery
xquery version "3.0";
declare function local:days-since-date($date as xs:date) {
let $duration := current-date() - $date
let $days := days-from-duration($duration)
return
$days
};
local:days-since-date(xs:date('2012-10-12'))
@joewiz
joewiz / principal-officers-and-chiefs-of-mission-from-massachusetts.xq
Created April 21, 2014 20:12
Principal Officers and Chiefs of Mission from Massachusetts; using XQuery
xquery version "3.0";
(: Displays a list of Principals & Chiefs hailing from Massachusetts. :)
declare namespace output="http://www.w3.org/2010/xslt-xquery-serialization";
declare option output:method "html5";
declare option output:media-type "text/html";
let $all-people := collection('/db/cms/apps/principals-chiefs/data/')/person
let $state := 'ma'
@joewiz
joewiz / principal-officers-and-chiefs-of-mission-terminations-since-date.xq
Created May 22, 2014 17:02
Principals & Chiefs whose positions ended after a certain date; using XQuery
xquery version "3.0";
(: Displays a list of Principals & Chiefs whose positions ended after a certain date. :)
declare namespace output="http://www.w3.org/2010/xslt-xquery-serialization";
declare option output:method "html5";
declare option output:media-type "text/html";
let $all-people := collection('/db/cms/apps/principals-chiefs/data/')/person
let $cut-off := '2008-06-01'
@joewiz
joewiz / generate-bookworm.xq
Last active August 29, 2015 14:06
Generate a Culturomics Bookworm file from FRUS TEI XML data, using XQuery and eXist
xquery version "3.0";
(: Transform volumes from the FRUS series (TEI XML) into a zip file containing JSON and text files
formatted for Bookworm http://bookworm.culturomics.org/. The resulting data can be accessed at:
http://static.history.state.gov/temp/frus-all.zip (140 MB)
A link to the running demo of the resulting data awaits fixes to the bookworm server,
but @bmschmidt kindly posted one volume's worth of data at
http://benschmidt.org/joewiz/
:)
@joewiz
joewiz / 2012-palm-01.xml
Last active August 29, 2015 14:14
Coterminous appointments
<!--
This is a sample data file for capturing coterminous appointments
Store in the /db/cms/apps/principals-chiefs/data/coterminous-appointments collection.
The rule for deriving the file's <id> (and file basename) is to join the following elements with a hyphen:
YYYY: the year of the first appointment
ABCD: the first four letters of the appointee's last name (unless fewer than 4 letters
NN: usually 01, but increment to 02, 03, etc. to prevent id collisions
In this example:
2012: all appointments started in 2012
palm: from Palmer
@joewiz
joewiz / de-redirect.js
Created March 2, 2015 21:29
de-redirect bookmarklet for inaccessible redirect servers, e.g., redirect.mycompany/?url=
javascript:(function(){window.location=loadTimeData.data_.summary.failedUrl.replace(/.*\?url=/,'');})()
@joewiz
joewiz / slowest-queries.xq
Created March 13, 2015 04:17
Examine query duration from JMX logs collected by monex #existdb
xquery version "3.0";
(: Examine query duration from JMX logs collected by monex :)
declare namespace jmx="http://exist-db.org/jmx";
declare function local:milliseconds-to-time($timestamp as xs:long) as xs:dateTime {
let $days := xs:int($timestamp div 1000 div 24 div 60 div 60)
let $remainder := $timestamp - ($days * 24 * 60 * 60 * 1000)
let $hours := xs:int($remainder div 1000 div 60 div 60)