Skip to content

Instantly share code, notes, and snippets.

View jmakeig's full-sized avatar

Justin Makeig jmakeig

View GitHub Profile
@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;
@jmakeig
jmakeig / catch-permdenied.xqy
Last active August 17, 2016 12:45
Display roles and privileges when you get a permission denied error
import module namespace sec="http://marklogic.com/xdmp/security" at "/MarkLogic/security.xqy";
(: Don’t use this in production. It leaks security information available to a user with elevated privileges, such as admin. :)
try {
(: … :)
} catch($err) {
if('SEC-PERMDENIED' = $err/error:code/data()) then
xdmp:invoke-function( function() {
for $role in xdmp:user-roles(xdmp:get-current-user()) (: Or a specific user, especially if you’re running as an elevated role :)
@jmakeig
jmakeig / extensions.txt
Last active October 6, 2017 16:03
VSCode user settings
DotJoshJohnson.xml-1.7.0
EditorConfig.EditorConfig-0.6.0
EditorConfig.EditorConfig-0.6.2
alefragnani.Bookmarks-0.12.0
dbaeumer.vscode-eslint-1.2.7
donjayamanne.python-0.5.9
donjayamanne.python-0.6.0
dracula-theme.theme-dracula-1.8.0
eg2.vscode-npm-script-0.1.8
esbenp.prettier-vscode-0.10.1
@jmakeig
jmakeig / timestamp-diff.html
Last active August 3, 2016 23:28
Visually differentiate among timestamps
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Date viewer</title>
<style type="text/css">
body { font-family: Helvetica; font-size: 14pt; }
table {
border: solid 1px #ccc;
border-spacing: 0;
@jmakeig
jmakeig / markloic-download.py
Created July 31, 2016 18:02
Scriptable authenticated download of MarkLogic from developer.marklogic.com
# Python 2.7
import requests
session = requests.Session()
response = session.post('https://developer.marklogic.com/login', data={'email': '[email protected]', 'password': '********'})
# > 200 OK
# > {"status":"ok","name":"Justin Makeig"}
response = session.post('https://developer.marklogic.com/get-download-url', data={'download': '/download/binaries/8.0/MarkLogic-8.0-5.5-x86_64.dmg'})
# > 200 OK
# > {"status":"ok","path":"/download/binaries/8.0/MarkLogic-8.0-5.5-x86_64.dmg?t=*************/&email=whoami%40example.com"}
path = response.json().get('path')
@jmakeig
jmakeig / inheritance.js
Last active July 9, 2018 04:13
JavaScript inheritance with overrides and extensions
'use strict';
/**
* Default implementation. Specialized classes should
* extend and override/extend on their own prototypes.
*/
function Wrapper(wrapped) {
// Factory, not direct constructor
if(!this) { return new Wrapper(wrapped); }
// Internal (not private) property to track the wrapped object