Skip to content

Instantly share code, notes, and snippets.

View ableasdale's full-sized avatar

Alex Bleasdale ableasdale

View GitHub Profile
@ableasdale
ableasdale / role-privilege-mappings.xqy
Created June 27, 2014 09:43
MarkLogic/XQuery : Generate an HTML page for all roles all associated privileges with that role
xquery version "1.0-ml";
import module namespace sec="http://marklogic.com/xdmp/security" at
"/MarkLogic/security.xqy";
(xdmp:set-response-content-type("text/html; charset=utf-8"),
'<!DOCTYPE html>',
element html {
element head {
element title {"Role / Privilege mappings for security database version: ", xs:string(//sec:version)}
aws ec2 run-instances --image-id ami-XXXXXXX --instance-type m3.medium --security-groups XXXXX --key-name XXXXXX --monitoring Enabled=true --iam-instance-profile Name=MarkLogic --block-device-mappings "[{\"DeviceName\": \"/dev/sdf\",\"Ebs\":{\"VolumeSize\":10,\"VolumeType\":\"gp2\" }}]"
@ableasdale
ableasdale / parse-support-dump.xqy
Created January 6, 2015 19:44
Parse a MarkLogic support dump and XPath to a specific node
xquery version "1.0-ml";
(:
: Example for locally loading a MarkLogic support dump as a sequence
: of document-node() elements for reporting and analysis
:)
declare variable $path as xs:string := 'C:\Users\ableasdale\Desktop\dump.txt';
declare variable $support as document-node()* := xdmp:document-get (
@ableasdale
ableasdale / ml-plan.xqy
Created January 16, 2015 08:39
MarkLogic Plan Manager (Incomplete)
xquery version "1.0-ml";
declare variable $path-segment := "E:\plan-docs\";
declare variable $query := xdmp:plan(cts:search(doc(), cts:word-query("test")));
declare variable $query2 := xdmp:plan(cts:search(doc(), cts:word-query(("test", "time", "language", "gas", "police", "politics"))));
declare function local:get-distinct-term-keys($query) as xs:unsignedLong* {
distinct-values($query//xs:unsignedLong(*:key))
};
@ableasdale
ableasdale / squid.xqy
Last active August 29, 2015 14:14
MarkLogic: xdmp:http-get() with Squid
xquery version "1.0-ml";
declare function local:http-get-proxy($proxy as xs:string, $uri as xs:string) {
let $host := tokenize($uri,'/')[3]
let $proxyuri := resolve-uri(substring-after($uri, $host), $proxy)
return
xdmp:http-get($proxyuri,
<options xmlns="xdmp:http">
<headers>
@ableasdale
ableasdale / forest-mem-use.xqy
Created January 30, 2015 15:07
Get total memory usage per forest
xquery version "1.0-ml";
(:
: Get the Forest in-memory usage
:)
declare default element namespace "http://marklogic.com/xdmp/status/forest";
declare variable $path as xs:string := 'C:\Users\Public\Documents\ML_status_only_support_dump_20110118';
@ableasdale
ableasdale / average-forest-size.xqy
Created January 30, 2015 15:17
Average Size of a forest
xquery version "1.0-ml";
(:
: Example: calculate the average size of a forest
:)
declare default element namespace "http://marklogic.com/xdmp/status/forest";
declare variable $path as xs:string := 'C:\Users\Public\Documents\ML_status_only_support_dump_20110118';
@ableasdale
ableasdale / on-disk-sizes.xqy
Created January 30, 2015 15:24
Forest aggregate disk size
xquery version "1.0-ml";
(:
: Example: calculate the on-disk size of each forest
:)
declare default element namespace "http://marklogic.com/xdmp/status/forest";
declare variable $path as xs:string := 'E:\support_qa_60.dmp';
@ableasdale
ableasdale / default.xqy
Last active August 29, 2015 14:16
Basic XSD Viewer
xquery version "1.0-ml";
declare variable $filename := xdmp:get-request-field("file");
declare variable $dir-base as xs:string := "C:\Program Files\MarkLogic\Config\";
declare function local:bootstrap-shim($title, $content){
xdmp:set-response-content-type("text/html; charset=utf-8"),
("<!DOCTYPE html>",
<html lang="en">
<head>
@ableasdale
ableasdale / ratios.xqy
Created March 5, 2015 11:54
Limits, Sizes and Ratios
xquery version "1.0-ml";
declare namespace admin = "http://marklogic.com/xdmp/admin";
declare variable $strings := ( "size", "ratio", "threshold", "max", "min", "limit", "rate", "throttle" );
declare variable $dir-base as xs:string := "C:\Program Files\MarkLogic\Config\";
declare function local:display($it as item()*) {
(
" ******************* ",