Skip to content

Instantly share code, notes, and snippets.

View ableasdale's full-sized avatar

Alex Bleasdale ableasdale

View GitHub Profile
@ableasdale
ableasdale / get-last-incremental-backup-for-a-given-database.xqy
Created July 26, 2016 18:20
MarkLogic: get the most recently completed incremental backup for a given database
xquery version "1.0-ml";
declare namespace fs = "http://marklogic.com/xdmp/status/forest";
declare variable $DATABASE as xs:string := xdmp:get-request-field("db")
max(xdmp:forest-status(xdmp:database-forests(xdmp:database($DATABASE)))/fs:last-incr-backup)
max(xdmp:forest-status(xdmp:database-forests(xdmp:database("test")))/fs:last-incr-backup)
@ableasdale
ableasdale / last-incremental-backup.xqy
Created July 26, 2016 18:15
MarkLogic: get the status of all last incremental backups across all forests in a given database
xquery version "1.0-ml";
declare namespace fs = "http://marklogic.com/xdmp/status/forest";
xdmp:forest-status(xdmp:database-forests(xdmp:database("test")))/fs:last-incr-backup
max(xdmp:forest-status(xdmp:database-forests(xdmp:database("test")))/fs:last-backup)
@ableasdale
ableasdale / last-backup.xqy
Created July 26, 2016 18:08
Get the backup status from all forests in a given database
xquery version "1.0-ml";
declare namespace fs = "http://marklogic.com/xdmp/status/forest";
xdmp:forest-status(xdmp:database-forests(xdmp:database("test")))/fs:last-backup
@ableasdale
ableasdale / forest-status.xqy
Created July 26, 2016 18:03
MarkLogic: Forest statuses for all forests in a given database (with an XPath to the Forest name)
xquery version "1.0-ml";
declare namespace fs = "http://marklogic.com/xdmp/status/forest";
xdmp:forest-status(xdmp:database-forests(xdmp:database("test")))/fs:forest-name
@ableasdale
ableasdale / boto3-list-instances.py
Created July 16, 2016 09:57
Using Boto 3 to list out AWS EC2 instance information
import boto3
from termcolor import colored
ec2 = boto3.resource('ec2')
for i in ec2.instances.all():
print("Id: {0}\tState: {1}\tLaunched: {2}\tRoot Device Name: {3}".format(
colored(i.id, 'cyan'),
colored(i.state['Name'], 'green'),
@ableasdale
ableasdale / basic-database.xqy
Created July 15, 2016 15:45
Basic Database Creation Template
xquery version "1.0-ml";
import module namespace info = "http://marklogic.com/appservices/infostudio" at "/MarkLogic/appservices/infostudio/info.xqy";
declare variable $DATABASE as xs:string := "DB-NAME-HERE";
info:database-create($DATABASE, 2)
@ableasdale
ableasdale / concurrent-http.py
Created July 12, 2016 15:55
Python: using httplib2 and ThreadPoolExecutor to create a large number of concurrent HTTP requests
import httplib2
import concurrent.futures
EMPTY_REQ_BODY = body = ""
URI = "http://0.0.0.0:8001/admin/v1/timestamp"
REQ_HEADERS = headers = {'Accept': 'text/plain'}
EXECUTOR = concurrent.futures.ThreadPoolExecutor(max_workers=64)
@ableasdale
ableasdale / httplib2-ml.py
Created July 12, 2016 14:27
Using the Python httplib2 to connect to MarkLogic's ReST API
import httplib2
h = httplib2.Http()
h.add_credentials('username', 'password')
TIMESTAMP_URI = "http://localhost:8001/admin/v1/timestamp"
REST_URI = "http://localhost:8002/LATEST/rest-apis"
BODY = body = ""
ACCEPT_JSON = headers = {'Accept': 'application/json'}
ACCEPT_XML = headers = {'Accept': 'application/xml'}