Skip to content

Instantly share code, notes, and snippets.

View ableasdale's full-sized avatar

Alex Bleasdale ableasdale

View GitHub Profile
@ableasdale
ableasdale / flip-forests.xqy
Created September 11, 2013 10:45
Flexible replication: revert failed over forests
xquery version "1.0-ml";
(: This script looks for forests configured as master on this host that
are currently acting as a replica. This implies that a failover has
occurred and a replica for the forest has taken over as master, and
also that the master is now back online but is in the role of replica.
Restarting the acting master will cause the configured master to
resume its role as master. That will allow the server node that
owns the master forest to resume handling query load for it.
@ableasdale
ableasdale / strip-items.sh
Created October 2, 2013 08:11
Removes common messages from a MarkLogic ErrorLog.txt file including stand update information (Save/Merge/Delete), replication information, forest mounting / unmounting
grep -vE '(\ to\ domestic\ forest\ |\ to\ domestic\ replica\ forest\ |Info:\ Unmounted\ forest|Info:\ Mounted\ forest|Info:\ Merging|Info:\ Merged|Info:\ Saving|Info:\ Saved|Info:\ Deleted)' supportDumpFileName > newFileName
@ableasdale
ableasdale / gist:7235855
Created October 30, 2013 16:39
Cut | Sort | Uniq example
cut -d " " -f 3- filename.txt | sort -n | uniq -c
@ableasdale
ableasdale / gist:7235967
Created October 30, 2013 16:46
Pulling some number values out of a text file and creating a total from all items found.
grep "STRING" FILENAME | cut -d " " -f4 | awk '{total = total + $1}END{print total}'
@ableasdale
ableasdale / gist:7378508
Created November 8, 2013 22:12
External binary support in MarkLogic
(: From Filesystem :)
xdmp:document-insert("/zip-test.zip",
xdmp:external-binary("C:\Users\ableasdale\Downloads\downloaded.zip")
)
(: From a Variable - it's this simple! :)
xdmp:document-insert("/binary", $var)
@ableasdale
ableasdale / gist:8716999
Created January 30, 2014 19:34
MarkLogic - Amped email
xquery version "1.0-ml";
module namespace amped = "http://marklogic.com/kb/amp";
declare variable $SUBJECT as xs:string := "Email from a Module";
declare variable $FROM-NAME as xs:string := "MarkLogic (AMPED)";
declare variable $FROM-EMAIL as xs:string := "marklogic@example.com";
declare variable $TO-NAME as xs:string := "Example Recipient";
declare variable $TO-EMAIL as xs:string := "recipient@example.com";
declare variable $EMAIL-BODY as element(div) := <div>This email was sent from an <strong>amped</strong> function</div>;
@ableasdale
ableasdale / gist:8824644
Created February 5, 2014 14:25
Extracting information from the Sysinternals "Process Monitor" tool and inserting selected nodes into MarkLogic
xquery version "1.0-ml";
(:
Step 1
Get the necessary data - around the two times where we see Journal Errors getting logged.
To extract all the nodes from the text files,
do something like this on the Performance Monitor output files:
grep -B3 -A7 "of_Day>8:48:54" Logfile-scrubbed > cut3.txt
grep -B3 -A7 "of_Day>7:34:28" Logfile-scrubbed > cut4.txt
:)
@ableasdale
ableasdale / gist:8858255
Created February 7, 2014 06:36
Sync Music Library to NAS using rsync
rsync -ruv Music /Volumes/Public/iTunes\ Backup
@ableasdale
ableasdale / recursive-rename
Created April 18, 2014 17:22
Bulk rename files in multiple drectories (Windows)
for /r %x in (*) do if exist "%x" ren "%x" *.xml
@ableasdale
ableasdale / sample-data.xqy
Created May 14, 2014 14:47
Create sample data in a given database quickly
xquery version "1.0-ml";
declare private function local:random-hex($length as xs:integer) as xs:string {
fn:string-join(for $n in 1 to $length
return xdmp:integer-to-hex(xdmp:random(15)),
""
)
};
declare function local:generate-uuid-v4() as xs:string {