Skip to content

Instantly share code, notes, and snippets.

View jmakeig's full-sized avatar

Justin Makeig jmakeig

View GitHub Profile
@jmakeig
jmakeig / require-override.sjs
Last active December 3, 2016 19:13
Proof-Of-Concept that overrides the global require() function in MarkLogic to (eventually) operate like Node
// IIFE to avoid polluting global scope.
(function() {
/** {@link https://nodejs.org/api/modules.html#modules_all_together}
/*
require(X) from module at path Y
1. If X is a core module,
a. return the core module
b. STOP
2. If X begins with './' or '/' or '../'
a. LOAD_AS_FILE(Y + X)
@jmakeig
jmakeig / json-stringify.xqy
Created December 1, 2016 19:21
Pretty print JSON nodes from XQuery in MarkLogic (>=8)
(: NOTE: In a production system you should amp json:stringify to avoid arbitrary JavaScript execution. :)
declare function json:stringify($json as node(), $spaces as xs:int) as xs:string? {
xdmp:javascript-eval("JSON.stringify($json.toObject(), null, $spaces)", ('$json', $json, '$spaces', $spaces))
};
declare function json:stringify($json as node()) as xs:string? {
json:stringify($json, 2)
};
let $node := xdmp:unquote('["B", "B"]')
@jmakeig
jmakeig / callback.js
Last active April 7, 2026 13:15
JSDoc/Documentation.js examples
/**
* A success callback for {@link ResultProvider} that receives the result from
* the {@link documents#probe}.
* @callback documents#probeResult
* @since 1.0
* @param {documents.DocumentDescriptor} document - a sparse document descriptor with an exists
* property that identifies whether the document exists
*/
/**
* Probes whether a document exists; takes a configuration
@jmakeig
jmakeig / recursive-lock.sh
Created October 6, 2016 23:05
Recursively lock PowerPoint files in OS X
#! /usr/bin/evn bash
# <http://hints.macworld.com/article.php?story=20031017061722471>
find . -name '*.pptx' -exec chflags uchg {} \; # nouchg is the antidote
@jmakeig
jmakeig / runner.js
Last active October 3, 2016 16:53
Minimal Tape implementation for MarkLogic 8
var harness = {
items: [],
register: function(test) {
this.items.push(test);
return this;
},
run: function() {
return new TestOutcomes(
this.items.map(function(test) {
//return test.call(null, 'Hi!');
@jmakeig
jmakeig / example.sjs
Created September 26, 2016 17:38
Synchronous pseudo-promises in MarkLogic
fetch('http://www.marklogic.com')
.then(console.log);
@jmakeig
jmakeig / osx-defaults.sh
Created September 19, 2016 14:43
OS X default configuration
#! /usr/bin/env bash
defaults write com.apple.screencapture type png
defaults write com.apple.screencapture location ~/Screenshots
killall SystemUIServer
@jmakeig
jmakeig / backup.sh
Last active September 15, 2016 06:16
Backup and restore with rsync
rsync -e 'ssh' -avlt --delete \
--exclude 'Microsoft User Data' \
--exclude '.parallels-vm-directory' \
--exclude 'Personal' \
--exclude '.DS_Store' \
--exclude '.git/' \
--exclude 'Virtual Machines.localized' \
--exclude 'WebEx' \
--exclude 'Web Receipts' \
--exclude 'Workspaces' \
@jmakeig
jmakeig / invoke.sjs
Last active August 26, 2016 06:38
“Flatten” class instances so they can be copied across xdmp:invoke boundaries in MarkLogic
'use strict'
const ctx = {modules: 0, root: '/modules/root/path'};
const obj = fn.head(
//xdmp.invoke('main.sjs')
xdmp.invoke('main.sjs', ctx)
);
obj.say();
// ==> "Bob says: Hi!""
@jmakeig
jmakeig / visitor.js
Created August 22, 2016 23:12
Recursive descent visitor pattern in JavaScript
'use strict'
const json = {
"a": ["A", "A", {"b": "B"} ],
"c": { "d": "D", "e": ["E", "E"]},
"f": "F"
}
function isPrimitive(obj) {
if(null === obj) return true;
if(undefined === obj) return true;