Skip to content

Instantly share code, notes, and snippets.

View jmakeig's full-sized avatar

Justin Makeig jmakeig

View GitHub Profile
@jmakeig
jmakeig / marklogic-restart-notification.sh
Last active August 29, 2015 14:02
Bell notification when a MarkLogic restart has completed
#!/usr/bin/env bash
# Need the max-time so it will actually retry in a reasonable amount of time
until curl -fsS \
--max-time 1 \
--digest --user admin:'********' \
--head \
http://localhost:8001/admin/v1/timestamp
do
sleep 2
@jmakeig
jmakeig / marklogic-reinitialize.sh
Created June 26, 2014 06:54
One-liner to restore an OS X MarkLogic instance it its uninitialized state.
~/Library/StartupItems/MarkLogic/MarkLogic stop; rm -rf ~/Library/Application\ Support/MarkLogic/Data; ~/Library/StartupItems/MarkLogic/MarkLogic start
@jmakeig
jmakeig / tx-eval.js
Last active August 29, 2015 14:05
Multiple transactions in a single JavaScript statement
function tx(f, vars, opts) {
opts = opts || {};
if(!opts.isolation) { opts.isolation = "different-transaction"; }
//opts.transactionMode = "update"; // Not sure what this does here.
return xdmp.eval('(' + f.toString() + ')();', vars, opts);
}
tx(
function() {
declareUpdate();
@jmakeig
jmakeig / for-each-dir-git.sh
Created September 15, 2014 18:23
Run a git command on every git repo in a directory
find . -name '.git' -type d -exec git --git-dir {} diff --exit-code \;
@jmakeig
jmakeig / tar-child-exclude.sh
Created November 7, 2014 19:22
tar up a Subversion directory
# -f needs to be the last param or you'll get "Cannot stat: No such file of directory"
# --exclude-vcs doesn't work on OS X 10.9.5, thus --exclude=.svn
# * means all child files/directories, but not this one. This is useful for excluding "trunk".
tar --exclude=.svn -czvf ~/Desktop/archive.tar.gz *
# Verify the above worked
tar -tzvf ~/Desktop/archive.tar.gz | less
@jmakeig
jmakeig / all-props.js
Created November 10, 2014 20:08
Get all properties, enumerable and not, of the prototype of an object
Object.getOwnPropertyNames(Object.getPrototypeOf(obj));
@jmakeig
jmakeig / readstream.sh
Created November 11, 2014 18:11
Pipe input or get from param
#!/usr/bin/env bash
# From <http://linux.byexamples.com/archives/474/bash-script-that-process-input-from-pipeline-or-file-redirection/>
# If there is not param read from stdin else get from the input
# TODO: Get input from a specific parameter inline or from a file specified in a parameter.
if [ -e $1 ] ;then read str; else str=$1;fi
echo "$str"
@jmakeig
jmakeig / password-keychain.sh
Created November 11, 2014 17:14
Get internet password from OS X keychain
security find-internet-password -gs example.com 2>&1 | grep "password" | cut -d \" -f 2
@jmakeig
jmakeig / asObjects.sjs
Created November 12, 2014 23:29
Generator to get objects from MarkLogic ValueIterator instances
function* asObjects(itr) {
for(var doc of itr) {
yield doc.toObject();
}
}
var a = [];
for(var obj of asObjects(fn.collection())) {
a.push(obj.name = "Generated: " + obj.name);
}
@jmakeig
jmakeig / jeopardy-marklogic.sjs
Created November 15, 2014 08:26
Load Jeopardy data
declareUpdate();
// Hopefully this link doesn't go away.
var loc="https://doc-0s-1s-docs.googleusercontent.com/docs/securesc/ha0ro937gcuc7l7deffksulhg5h7mbp1/108nt093kbmcafeksihop0r1pcmkkvtr/1416031200000/14044389733472591834/*/0BwT5wj_P7BKXb2hfM3d2RHU1ckE?e=download";
var qs=xdmp.documentGet(loc, {format: "json"});
var shows = {};
qs.next().value.toObject().forEach(
function(q) {
shows["" + q.show_number] = (shows["" + q.show_number]) ? shows["" + q.show_number] + 1 : 1;
var uri = "/" + q.show_number + "_" + shows["" + q.show_number] + ".json";
// Has no one actually watched the show?