Skip to content

Instantly share code, notes, and snippets.

View jmakeig's full-sized avatar

Justin Makeig jmakeig

View GitHub Profile
@jmakeig
jmakeig / example.html
Created November 17, 2017 19:36
Toggleable section formatting
<section class="toggleable">
<h3>This Big Section with a Very Long Title That Should Wrap Over Multiple Lines that Will Break a Brittle Layout Really Badly</h3>
<p>Lorem ipsum dolor amet locavore yuccie PBR&amp;B, palo santo viral quinoa cred. Hot chicken jianbing bitters poutine palo santo banh mi vice food truck. Edison bulb chillwave vegan, cardigan hell of next level green juice hexagon microdosing. VHS disrupt waistcoat air plant yuccie meh la croix butcher adaptogen tilde, meggings paleo keytar bitters venmo. Live-edge lyft sustainable, hell of knausgaard glossier raclette. Aesthetic seitan mlkshk, tattooed kinfolk austin vexillologist cray cold-pressed. Pour-over brooklyn VHS wayfarers lyft meditation.</p>
<p>Put a bird on it air plant keytar yuccie chambray flexitarian. Wayfarers flannel bushwick, skateboard palo santo hammock slow-carb yuccie vape. Master cleanse pickled tumeric unicorn tattooed disrupt, forage bicycle rights crucifix sustainable skateboard yuccie la croix. Actually subway tile
@jmakeig
jmakeig / shallow-clone.js
Created November 15, 2017 00:38
JavaScript shallow clone
/**
* Creates a shallow copy of an Object or an Array, such that,
* `a !== shallowClone(a)`, but `a.b === shallowClone(a).b`, where `b`
* is not a primitive value. Deep cloning is out of scope here.
*
* @param {*} item - any “simple” `Object` or `Array`
* @return {*}
* @throws {TypeError} - if an Object does not directly inherit from
* `Object.prototype` or `null`
*/
@jmakeig
jmakeig / example.html
Last active November 4, 2017 04:31
Create a selectable Range from text offsets, flattening child nodes.
<div id="L1">abcdef<span>gh<span>ijk</span>lmn</span>opqrstuvwxyz0123456789</div>
<div id="L2">ab<span>cdefgh</span>ijk<span>lmnopqrstuvwxyz01234567</span>89</div>
<div id="L3">abcdefghijklmnopqrst<span>uvwxyz0123456789</span></div>
<button id="Range">Range me!</button>
<button id="Select">Select me!</button>
@jmakeig
jmakeig / git-server.md
Last active June 7, 2017 19:47
Setting up a remote SSH git server

This assumes you can already ssh USER@HOST with appropriate public key auth.

On the server

  1. Download and compile git source
    curl -O https://www.kernel.org/pub/software/scm/git/git-2.9.4.tar.gz
    tar -gzvf git-2.9.4.tar.gz
    cd git-2.9.4

make configure

@jmakeig
jmakeig / delete-qc-workspaces.xqy
Created May 11, 2017 23:11
Delete MarkLogic Query Console workspaces
declare namespace qc="http://marklogic.com/appservices/qconsole";
/qc:workspace/xdmp:node-uri(.) ! xdmp:document-delete(.)
@jmakeig
jmakeig / jsearch-slice.sjs
Last active May 11, 2017 21:20
Monkey patch of MarkLogic’s JSearch API to change the default values for slice(). Proof-of-concept. Don’t actually do this.
'use strict';
const jsearch = require('/MarkLogic/jsearch');
// Monkey patch
const proto = Object.getPrototypeOf(
// Doesn’t actually run a query
jsearch.collections('.').documents().where(cts.trueQuery())
);
const _slice = proto.slice;
@jmakeig
jmakeig / insert-update-upsert-move.sjs
Last active March 26, 2019 14:52
True insert, update, upsert, and move functions for MarkLogic
'use strict';
/**
* @class
*/
class DocumentExistsError extends Error {
constructor(uri) {
super();
this.uri = uri;
this.message = `URI ${String(
@jmakeig
jmakeig / invoke-asuser.sjs
Created April 21, 2017 20:25
Invoke a MarkLogic JavaScript function as a particular user
'use strict';
/** Invokes any function as a specific user */
const asUser = (fn, user) =>
xdmp.invokeFunction(fn, { userId: xdmp.user(user) });
/** The actual function that does the work. */
function _doStuff(param) {
return `${param}: ${xdmp.getCurrentUser()}`;
}
@jmakeig
jmakeig / set-eqaulity.js
Created April 13, 2017 21:12
JavaScript ES2015 Set equality
/**
*
*
* @param {Set} aaa
* @param {Set} bbb
* @param {function} [comparator]
* @returns {boolean}
*/
function equalSets(aaa, bbb, comparator = (x, y) => x === y) {
if ('function' !== typeof comparator) {
@jmakeig
jmakeig / toggle-group.html
Last active July 13, 2017 06:22
Minimal HTML toggle group
<!DOCTYPE html>
<html>
<head>
<title>Toggle group</title>
<style type="text/css">
.toggleable:before {
width: 0.75rem;
/* The two arrows have different widths */
display: inline-block;
content: '▾';