Skip to content

Instantly share code, notes, and snippets.

Joe Wicentowski joewiz

View GitHub Profile
@joewiz
joewiz / 01-secretary-of-state-travels-to-a-country.xq
Last active Aug 28, 2015
Travels of the Secretary of State, grouped by secretary, showing duration of visits in a country, using XQuery
View 01-secretary-of-state-travels-to-a-country.xq
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 Feb 13, 2014
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/
View generate-xfdf.xq
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
View FRUS RelaxNG Import.xml
<?xml-model href="../../schemas/frus.rnc" type="application/relax-ng-compact-syntax"?>
@joewiz
joewiz / principal-officers-and-chiefs-of-mission-from-massachusetts.xq
Created Apr 21, 2014
Principal Officers and Chiefs of Mission from Massachusetts; using XQuery
View principal-officers-and-chiefs-of-mission-from-massachusetts.xq
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 / days-since-date.xq
Created Apr 21, 2014
How many days have you been alive, with XQuery
View days-since-date.xq
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-terminations-since-date.xq
Created May 22, 2014
Principals & Chiefs whose positions ended after a certain date; using XQuery
View principal-officers-and-chiefs-of-mission-terminations-since-date.xq
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 Aug 29, 2015
Generate a Culturomics Bookworm file from FRUS TEI XML data, using XQuery and eXist
View generate-bookworm.xq
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 Aug 29, 2015
Coterminous appointments
View 2012-palm-01.xml
<!--
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 Mar 2, 2015
de-redirect bookmarklet for inaccessible redirect servers, e.g., redirect.mycompany/?url=
View de-redirect.js
javascript:(function(){window.location=loadTimeData.data_.summary.failedUrl.replace(/.*\?url=/,'');})()
@joewiz
joewiz / slowest-queries.xq
Created Mar 13, 2015
Examine query duration from JMX logs collected by monex #existdb
View slowest-queries.xq
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)
You can’t perform that action at this time.