Skip to content

Instantly share code, notes, and snippets.

View jmakeig's full-sized avatar

Justin Makeig jmakeig

View GitHub Profile
@jmakeig
jmakeig / class-factory.js
Created September 8, 2018 16:58
Factory for classes using a closure to set initial state.
'use strict';
class Component {
constructor(props) {
this._props = props;
}
get props() {
return this._props;
}
set props(p) {
this._props = p;

JSX is not JavaScript. It introduces new syntax to JavaScript as sugar for React’s underlying JavaScript APIs. JSX is problematic—to me, at least—for several reasons. It requires,

  • An extra compilation step
  • Specialized support in your IDE
  • Some mind bending in the fuzzy areas that aren’t quite JavaScript and aren’t quite HTML, for example, the awful <> tag
  • Lock-in to Facebook’s view of the web

The creatively named react-helper library, provides a humane API for creating DOM elements using React that abstracts away React altogether. It’s possible to interoperate with React components, but for pure DOM manipulation, the API does not leak the underlying React implementation.

@jmakeig
jmakeig / about.md
Created August 28, 2018 07:10
Hierarchical table headers, both row and column orientations

Converting a hierarchical tree data structure to HTML table headings is really tricky. Becuase of the way that rowspan and colspan work, it’s not striaghtforwad to traverse the tree in one pass. Moreover, the row-oriented apporach is very different than column-oriented.

Demo

@jmakeig
jmakeig / excel-keyboard-shortcuts.md
Last active March 16, 2020 20:50
Excel keyboard shortcuts
  • Select row: Shift + Space
  • Insert a copy above: Ctl + Shift + =
  • Insert empty rows above: ⌘ + Shift + =
  • Re-order rows: Drag + Shift
  • Indent: ?
@jmakeig
jmakeig / several.js
Created March 19, 2018 19:32
Create arrays of random length, sampled from a specified distribution
/**
* Generate an array from random length between `min` and `max`, calling `fct`
* to populate each item.
*
* @example Creates an array of random length sampled from a Poisson distribution of timestamp-text pair objects.
* several(
* () => ({
* timestamp: f.date.recent(),
* text: f.lorem.sentence(),
* }),
@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(.)