Skip to content

Instantly share code, notes, and snippets.

View ableasdale's full-sized avatar

Alex Bleasdale ableasdale

View GitHub Profile
@ableasdale
ableasdale / tr.sh
Created August 31, 2016 09:40
Use tr -d to remove newlines ("\n" from a file
tr -d '\n' < file.txt > file2.txt
@ableasdale
ableasdale / sed.sh
Created August 31, 2016 09:37
Using sed to add/remove characters to lines in a large file
# Add characters to end of line
sed 's/$/",/' file1.txt > file2.txt
# Add characters to beginning of line
sed 's/^/"/' file1.txt > file2.txt
@ableasdale
ableasdale / remove-blank.sh
Created August 31, 2016 08:54
Grep to remove empty lines from a file
grep '[^[:blank:]]' < file.txt > file2.txt
@ableasdale
ableasdale / host-status.js
Created August 24, 2016 14:08
Getting the host status in JSON format
xdmp.hostStatus(xdmp.host())
@ableasdale
ableasdale / timestamps-for-transactions.xqy
Created August 24, 2016 13:46
Get the wallclock times for all transactions in-flight per host
xquery version "1.0-ml";
declare namespace hs = "http://marklogic.com/xdmp/status/host";
xdmp:host-status(xdmp:host())/hs:transactions/hs:transaction/hs:transaction-timestamp ! xdmp:timestamp-to-wallclock(.)
@ableasdale
ableasdale / databases-currently-in-transactions.xqy
Created August 24, 2016 13:44
Use the host-status builtin to monitor transactions across databases
xquery version "1.0-ml";
declare namespace hs = "http://marklogic.com/xdmp/status/host";
xdmp:host-status(xdmp:host())/hs:transactions/hs:transaction/hs:database-id ! xdmp:database-name(.)
@ableasdale
ableasdale / host-name-from-status.xqy
Created August 24, 2016 13:25
Getting the host name from xdmp:host-status
xquery version "1.0-ml";
declare namespace hs = "http://marklogic.com/xdmp/status/host";
xs:string(xdmp:host-status(xdmp:host())/hs:host-name)
@ableasdale
ableasdale / simple-host-status.xqy
Created August 24, 2016 13:23
Simple Host Status for current host
xquery version "1.0-ml";
declare namespace hs = "http://marklogic.com/xdmp/status/host";
xdmp:host-status(xdmp:host())
@ableasdale
ableasdale / unzip.sh
Created August 8, 2016 13:37
Unpack individual zip files to separate directories
#!/bin/sh
for zip in *.zip
do
dirname=`echo $zip | sed 's/\.zip$//'`
if mkdir $dirname
then
if cd $dirname
then
unzip ../$zip
cd ..
@ableasdale
ableasdale / http-multipart-post.xqy
Created July 28, 2016 12:25
MarkLogic: HTTP Multipart Post Example
xquery version "1.0-ml" encoding "utf-8";
(:~
: Mark Logic multi-part POST Library
: Assembles a multi-part POST and performs an xdmp:post() sending the data to a webservice URI.
:
: The document can be read from the database or the filesystem. First the database is checked -
: if the information provided does not resolve a document in the database, it will fall back to
: trying to get the document from the filesystem
:
: @author <a href="mailto:[email protected]">Alex Bleasdale</a>