Skip to content

Instantly share code, notes, and snippets.

@lcahlander
lcahlander / tsgen.xqm
Last active May 29, 2019 14:00
This library module walks an XML Schema and generates the stubs for a typeswitch transform to process a document from that schema.
(:
Copyright (c) 2017. EasyMetaHub, LLC
This work is licensed under a
<a rel="license" href="https://creativecommons.org/licenses/by/4.0/">Creative Commons Attribution 4.0 International License</a>.
:)
xquery version "3.1";
(:~
This library module walks an XML Schema and generates the stubs for a typeswitch
@joewiz
joewiz / README.md
Last active February 13, 2018 14:01
Full text search of Chinese text, with eXist-db and Lucene

Full text search of Chinese text, with eXist-db and lucene

Note: This gist has been superseded by https://github.com/joewiz/exist-cjk but is left here should it be useful to anyone. Please post questions in an issue there.

This gist contains some sample files showing how to configure full text queries on Chinese text with eXist.

It assumes you have already installed eXist 3.5.0+.

Set up

@joewiz
joewiz / unparsed-text.xqm
Last active September 30, 2017 19:01
An implementation of XQuery 3.1's fn:unparsed-text* functions for eXist
xquery version "3.1";
(:~
: An implementation of XQuery 3.1's fn:unparsed-text* functions for eXist, which does not support them natively as of 3.4.0.
: Known limitations:
: - Does not enforce encoding aspects of the XQuery spec beyond functionality natively supplied by the EXPath HTTP Client and eXist's internals.
:
: @author Joe Wicentowski
: @version 0.2
: @see https://www.w3.org/TR/xpath-functions-31/#func-unparsed-text
@lcahlander
lcahlander / encchars.xqy
Last active April 24, 2018 20:15
The module contains variables for each of the unicode escape sequences at https://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references
xquery version "1.0";
(:~
The module contains variables for each of the unicode escape sequences at
<a href="https://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references">https://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references</a>
:)
module namespace encchars="http://w3.org/encoded/characters";
(: Name Escape Sequence Description :)
declare variable $encchars:quot := "&#34;"; (: quotation mark (APL quote) :)
@joewiz
joewiz / web-scraping-with-xquery.md
Last active March 9, 2023 07:18
Web Scraping with XQuery

Web Scraping with XQuery

Overview

Learning how to web scrape empowers you to apply your XQuery skills to any data residing on the web. You can fetch data from remote sites and services—for example, entire web pages or just the pieces of a page that matter to you. Once fetched, you can perform further analysis on the data, clean it up, mash it up with other data, transform it into different formats, etc.

Built-in functions for making HTTP requests

XPath-based languages like XQuery offer an standard function for accessing remote documents, the fn:doc() function. However, a limitation of this function is that it only works if the URI returns a well-formed XML document.

xquery version "3.1";
import module namespace http = "http://expath.org/ns/http-client";
(: For generating the personal access token to be used in this script, please select "public_repo | Access public repositories". :)
let $git-token := "<your-github-token>"
let $user-name := "<your-github-username>"
let $repo-name := "<your-repo-name>"
let $file-path := "<file=path>"
let $message := "<commit-message>"
let $new-file-content := serialize(<a/>)
@timotgl
timotgl / uninstall-razer-synapse.sh
Last active May 30, 2024 16:57
How to fully uninstall Razer Synapse 2 on OS X (10.11-10.13) (El Capitan, Sierra, High Sierra) without using Razer's official uninstall tool
# How to uninstall Razer Synapse 2 ( https://www.razerzone.com/synapse-2 )
# on OS X (10.11-10.13) (El Capitan, Sierra, High Sierra)
# without using Razer's official uninstall tool.
# Tested on OS X 10.11.5 in July 2016.
# Edited with additional steps for later OS X versions,
# contributed by commenters on this gist.
# Step 1: In your terminal: stop and remove launch agents
launchctl remove com.razer.rzupdater
@wsalesky
wsalesky / git-commit.xql
Created June 22, 2015 16:25
Proof of Concept: eXist DB module to commit files to github repository via github API
xquery version "3.0";
(:~
: POC: eXist DB module to commit files to github reop via github API
: Prerequisites:
: In order to run the module, you will need a github Authorization token.
: When you create authorization token your OAuth Scope will need to include repo, allowing you to update files.
: @see https://github.com/blog/1509-personal-api-tokens
:
: @Notes
@joewiz
joewiz / json-xml.xqm
Last active June 6, 2021 00:33
An implementation of XQuery 3.1's fn:json-to-xml and fn:xml-to-json functions for eXist
xquery version "3.1";
(:~
: An implementation of XQuery 3.1's fn:json-to-xml and fn:xml-to-json functions for eXist, which does not support them natively as of 4.3.0.
:
: @author Joe Wicentowski
: @version 0.4
: @see http://www.w3.org/TR/xpath-functions-31/#json
:)
module namespace jx = "http://joewiz.org/ns/xquery/json-xml";
@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.