Skip to content

Instantly share code, notes, and snippets.

View CliffordAnderson's full-sized avatar

Clifford Anderson CliffordAnderson

View GitHub Profile
xquery version "3.0";
declare namespace mdc = "http://mdc";
declare function mdc:add-check-digit-to-partial-barcode ($partial-barcode as xs:string) as xs:string {
(: the next two variables compute the Codabar barcode sum for 14-digit library barcodes according to the Luhn algorithm:)
let $barcode-sum :=
(: add up the even sequence :)
sum(string-to-codepoints($partial-barcode)[position() mod 2 eq 0] ! xs:integer(codepoints-to-string(.)))
+
(: add up the odd sequence :)
@fordmadox
fordmadox / stage-directions.xq
Last active August 29, 2015 14:02
updated to output well-formed XML, rather than just an XML fragment; also, the return clause in the previous query output all of the stage elements, not the filtered list
declare namespace tei = "http://www.tei-c.org/ns/1.0";
(:
for each person, show stage directions involving that
person
:)
<people-plus-stage-directions>
{
for $person in //tei:person
(: using a map isn't required here, I don't think :)
@joewiz
joewiz / 01-library.xql
Last active June 8, 2018 06:10
Unit testing XQuery with XQSuite in eXist-db: tests for a sample function, how to run tests, and test results
xquery version "3.0";
(: This sample library module contains a single function, iu:analyze-date-string().
: The purpose of the sample is to demonstrate XQSuite tests, a unit test framework that uses
: XQuery 3.0's Annotations facility to embed testing assertions and parameters in XQuery functions.
:
: By writing unit tests and running them after each new change to an application, we can spot new bugs
: right away and prevent regressions.
:
: The XQSuite tests in this example are stored in a separate module, 02-tests-xql.

#The Functional Programmers Cheat Sheet for NDC Oslo 2014

This year NDC Oslo has a full three-day functional programming track with an amazing lineup. If you agree that the future of programming is FP, use this as your "auto pilot" guide on what sessions to attend.

Cheer for sessions on Twitter using the #ndcoslo and #fptrack hashtags.

[The full agenda (including non-fp sessions) is here].

@joewiz
joewiz / collection.xconf.xml
Created April 7, 2012 19:33
My XQuery snippets
<collection xmlns="http://exist-db.org/collection-config/1.0">
<index>
<!-- Old full text index configuration. Deprecated. -->
<fulltext default="none" attributes="false"/>
<!-- New full text index based on Lucene -->
<lucene>
<text qname="SPEECH">
<ignore qname="SPEAKER"/>
</text>
@nimbupani
nimbupani / index.html
Created December 2, 2011 05:00
Showing latest post on home page with Jekyll
---
layout: default
---
<div class="blog-index">
{% assign post = site.posts.first %}
{% assign content = post.content %}
{% include post_detail.html %}
</div>
@rohanbk
rohanbk / Knapsack
Created December 6, 2010 21:06
Python implementation of classic Knapsack problem
from sys import stdin
from sys import stdout
'''
Knapsack Problem implementation
Created on Dec 6, 2010
@author: rohanbk
'''
capacity=10;
num_of_items=6;