Skip to content

Instantly share code, notes, and snippets.

View jmakeig's full-sized avatar

Justin Makeig jmakeig

View GitHub Profile
@jmakeig
jmakeig / gist:1008795
Created June 5, 2011 08:39
Data URL from a binary document in MarkLogic
xquery version "1.0-ml";
let $img := doc("/binaries/12250.png")
let $ct := xdmp:uri-content-type(xdmp:node-uri($img/node()))
return <img src="{concat('data:', $ct, ';', 'base64,', xs:base64Binary($img/node()))}"/>
@jmakeig
jmakeig / bootstrap.sh
Created October 22, 2012 04:32
HDFS Storage Technology Preview - REST bootstrapping
#! /bin/bash
# Bootstraps a REST interface for a database
# Customize database, host, port and authentication to fit your environment
DB="test-hdfs"
HOST="localhost"
PORT="8010"
AUTH="admin:admin"
@jmakeig
jmakeig / box-muller.xqy
Created December 11, 2012 21:40
Box-Muller algorithm to transform a uniform distribution to a normal distribution.
declare namespace local="local";
declare function local:random() as xs:double {
xdmp:random(10000) div 10000
};
(: http://www.exceluser.com/explore/statsnormal.htm :)
declare function local:box-muller() as xs:double {
math:sqrt(-2 * math:log(local:random())) *
math:sin(2 * math:pi() * local:random())
};
@jmakeig
jmakeig / gist:4263040
Created December 11, 2012 22:46
Select every other line
awk 'NR % 2 == 1'
@jmakeig
jmakeig / gist:4263631
Created December 12, 2012 00:11
Aliases for pretty printing XML and JSON
alias json="python -mjson.tool"
alias xml="xmllint --format --encode utf-8 -"
#! /bin/bash
# Script to bootstrap an instance of timbrrr with actual data.
# Author: Justin Makeig <jmakeig@marklogic.com>
# Assumptions:
# - UNIX and bash. This should also be possible for Windows, but the syntax might be slightly different
# - Ports 9001 is available for an HTTP app server and 9002 is available for an XDBC server
# - mlcp is downloaded and installed at $MLCPPATH below
@jmakeig
jmakeig / gist:5977750
Created July 11, 2013 18:07
MarkLogic BugTrack automation: Sets the status and fix-in versions. Seems to only work on the Chrome JavaScript console that makes a $ selector function available.
function sel(name, val, $) {Array.prototype.slice.call($("select[name="+name+"]").options).forEach(function(opt) {if(opt.value === val) opt.selected = true;})}; sel("status", "will not fix", $); sel("new-fix-in-version", "", $);
@jmakeig
jmakeig / spaces-to-asterisks.sh
Created August 2, 2013 18:13
Converts leading double spaces into asterisks mostly for converting to Markdown.
perl -pe '1 while s/\G {2}/*/gc' | perl -pe 's/^(.)/*\1/' | perl -pe 's/^(\*+)/\1 /'
@jmakeig
jmakeig / say-Word-selection.applescript
Last active December 24, 2015 14:19
Have the OS speak the selected text from Word. This is a system service in most Mac apps, but not in Office.
tell application "Microsoft Word"
activate
tell selection
set myText to content of text object
end tell
end tell
tell application "System Events"
-- Fork it to another process so it doesn't prevent you from doing other stuff in the foreground in Word
do shell script "echo " & myText & " | say > /dev/null 2>&1 &"
@jmakeig
jmakeig / distinct-element-paths.xqy
Created January 8, 2014 22:20
From a random sample of all documents in a MarkLogic database, returns a list of distinct paths to the leaf element whose local name matches a regular expression. You wouldn’t want to do this on the whole database because the XPath is very expensive.
xquery version "1.0-ml";
distinct-values(
cts:search(collection(), cts:and-query(()), ("unfiltered","score-random"))[1 to 100]
//*[matches(local-name(.), "Address$")]/xdmp:path(.)
)