Skip to content

Instantly share code, notes, and snippets.

View ableasdale's full-sized avatar

Alex Bleasdale ableasdale

View GitHub Profile
@ableasdale
ableasdale / document-assign.xqy
Created December 11, 2020 09:54
MarkLogic: In Forest Eval - adding xdmp:document-assign back into the evaluation
let $forest :=
let $forests := xdmp:database-forests(xdmp:database())
let $index := xdmp:document-assign("document-1.xml", count($forests))
return $forests[$index]
return local:in-forest-eval("xdmp:document-insert('/foo1.xml', <foo>1</foo>)", (), xs:unsignedLong($forest))
@ableasdale
ableasdale / in-forest-eval.xqy
Last active December 11, 2020 14:37
MarkLogic: In Forest Eval example
xquery version "1.0-ml";
(:
The following XQuery code demonstrates a technique to force an "in forest eval" of a call to xdmp:document-insert().
This code will force a document insert to get evaluated within the context of a specific forest (Documents2)
Note that the practice outlined in this code (or similar) can have the potential to lead to an increased chance of
XDMP-DBDUPURI URIs as the code effectively bypasses the normal xdmp:document-assign() process that assigns a URI to
a given forest based on the hash of it's URI key.
This code is for demonstration purposes only.
@ableasdale
ableasdale / pstack.sh
Last active October 12, 2020 18:47
MarkLogic: Simple pstack script
#!/bin/bash
# root check
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root" 1>&2
exit 1
fi
# default argument check
if [[ -z $1 ]]; then
@ableasdale
ableasdale / process-json.xqy
Created June 1, 2020 08:52
MarkLogic: processing JSON using XPath
xquery version "1.0-ml";
(: Taken from:
https://www.linkedin.com/posts/kurtcagle_informatix8gulp-saxon-xslt-activity-6673109285721010176-hDYU/
See also:
https://www.npmjs.com/package/@informatix8/gulp-saxon-xslt
The above example was modified from Kurt's example to work with MarkLogic Server.
:)
@ableasdale
ableasdale / remove-replicas.xqy
Created May 26, 2020 08:18
MarkLogic: Removing multiple replica forests from their respective master forests
xquery version "1.0-ml";
import module namespace admin = "http://marklogic.com/xdmp/admin" at "/MarkLogic/admin.xqy";
declare variable $CONFIG := admin:get-configuration();
let $CONFIG := admin:forest-remove-replica($CONFIG, xdmp:forest("Documents"), xdmp:forest("Documents-R"))
let $CONFIG := admin:forest-remove-replica($CONFIG, xdmp:forest("Extensions"), xdmp:forest("Extensions-R"))
return admin:save-configuration($CONFIG)
@ableasdale
ableasdale / v8.md
Last active August 26, 2021 01:02 — forked from kevincennis/v8.md
V8 Installation and d8 shell usage

Installing V8 on a Mac

My Troubleshooting Notes

I had issues which I initially believed were related to python 3 but may have been XCode issues - I got it to work by doing all of these things but I'm not sure what was actually necessary - so I'll put all the steps in that I can recall.

Ultimately, I was seeing python stack traces when running tools/dev/v8gen.py x64.optdebug; the resulting stack trace looked like this:

tools/dev/v8gen.py x64.optdebug
@ableasdale
ableasdale / create-db-elem-range-idx-list.xqy
Last active April 15, 2020 12:08
MarkLogic: Parse a support dump, extract all databases in order and create an unordered list containing their configured element range indexes
xquery version "1.0-ml";
declare namespace db = "http://marklogic.com/xdmp/database";
declare variable $path as xs:string := 'e:\Downloads\support_dump.txt';
declare variable $support as document-node()* := xdmp:document-get(
$path,
<options xmlns="xdmp:document-get">
<format>xml</format>
<repair>full</repair>
@ableasdale
ableasdale / multipart-decode.xqy
Created April 6, 2020 13:52
MarkLogic: xdmp:multipart-decode example for decoding the parts of an outlook .eml file
xquery version "1.0-ml";
declare variable $BIN := xdmp:document-get("/Users/ableasdale/Downloads/Mail Attachment.eml", <options xmlns="xdmp:document-get"><format>binary</format></options>);
xdmp:multipart-decode("_006_130CEAC8798504479C0F9760840E6AAA068FD0CDEXCHG10BE01mark_",
$BIN/node(),
<options xmlns="xdmp:zip-get"><format>binary</format></options>)
@ableasdale
ableasdale / marklogic-restapi-trace-events.xqy
Created April 3, 2020 12:31
MarkLogic: Enable the MarkLogic ReST API Diagnostic Trace Events
xquery version "1.0-ml";
(:
Enable ReST API Diagnostic Trace Events
See: https://help.marklogic.com/Knowledgebase/Article/View/692/
:)
import module namespace admin = "http://marklogic.com/xdmp/admin" at "/MarkLogic/admin.xqy";
declare variable $config := admin:get-configuration();
@ableasdale
ableasdale / fn-filter-example.xqy
Created January 10, 2020 12:41
MarkLogic - XQuery fn:filter example
(: Given a sequence from a range lexicon (on the right), pass the sequence to fn:matches and return all instances containing "A7" :)
fn:filter(function($a) { fn:matches($a, "A7") }, cts:element-values(xs:QName("Template")))