Skip to content

Instantly share code, notes, and snippets.

Avatar

Justin Makeig jmakeig

View GitHub Profile
@jmakeig
jmakeig / example.js
Last active Jan 6, 2023
JSDoc can’t describe some generic functions declared in Typescript
View example.js
/** @typedef {{name: string; title: string; description: string; sets: any[]; }} Workout */
/** @typedef {{name: string; instructions: string;}} Exercise */
/** @typedef {"en" | "fr" | "de" | "jp" | "zh" | "he"} Lang */
/** @typedef {string | {[L in Lang]?: string}} Message */
/** @typedef {{for: string, message?: Message}} ValidationResult */
/**
* @template Entity
* @typedef {{(condition: {(entity: Entity): boolean}, id: string, message: Message): {(entity: Entity): ValidationResult[]}}} RuleCreator<Entity>
@jmakeig
jmakeig / timer.css
Created Dec 29, 2021
Timer CSS animation
View timer.css
svg {
display: inline-block;
height: 90px;
width: 90px;
}
svg.timer {
transform: rotate(-90deg);
overflow: visible;
}
circle.gague {
@jmakeig
jmakeig / fy-date-converter.xlsx
Created Jul 2, 2020
Calendar date to MarkLogic fiscal year conversion
View fy-date-converter.xlsx
="FY"&IF(MONTH(G2)=1, YEAR(G2), YEAR(G2)+1) & "Q"&IF(MONTH(G2)=1, 4, FLOOR((MONTH(G2)+1)/3,1))
@jmakeig
jmakeig / split-json-array.sh
Last active Jul 1, 2020
Split a file containing a JSON Array into one file per item
View split-json-array.sh
#!/usr/bin/env bash
# Splits a file that contains a top-level JSON Array
# into individual files, one per item, named sequentially
# https://stedolan.github.io/jq/download/
jq -c .[] "$1" | awk '{print > (NR ".json")}'
@jmakeig
jmakeig / transform.js
Created Mar 15, 2020
Recursive descent transformation with visitor
View transform.js
#!/usr/bin/env node
/**
* Depth-first copy with selective transformation.
* For each of the `Iterable` selected by the selector function, it
* applies the `visitor` function and continues recursively.
*
*
* @param {object} node the tree structure
* @param {function} [visitor] the function to apply to selected children
@jmakeig
jmakeig / values.js
Last active Feb 27, 2020
MarkLogic’s cts.frequency function is magic. Could we do something more explicit? (Spoiler: probably not by much)
View values.js
// https://github.com/jmakeig/iterant/issues/30
function head(itr) {
if (itr[Symbol.iterator]) return itr[Symbol.iterator]().next().value;
}
function* values(ref, options) {
const sequence = cts.values(ref, options);
for (const value of sequence) {
yield {
value: value.valueOf(),
@jmakeig
jmakeig / table.html
Last active Feb 12, 2022
Default table CSS
View table.html
<!DOCTYPE html>
<html>
<head>
<title>Progenitor Mock-up</title>
<style type="text/css">
table {
position: relative; /* Needed for sticky headers */
width: 100%;
View machine.js
//import { Machine, assign } from './xstate.js';
// Ensure correct dirty checks when Svelte is running in immutable mode.
function clone(object) {
if ('object' === typeof object) {
if (null === object) return object;
if (Array.isArray(object)) return [...object];
if (object instanceof Set) return new Set(object);
if (object instanceof Map) return new Map(object);
return Object.assign({}, object);
@jmakeig
jmakeig / nested-tables.html
Last active Feb 12, 2020
Display complex tree data structures as nested HTML tables.
View nested-tables.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Nested Tables</title>
<style>
html {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
font-size: 14px;
View machine.js
function clone(...rest) {
return Object.assign({}, ...rest);
}
/**
* Builder for confirmation states.
*
* @param {String} onConfirm State to transition to on confirmation
* @param {String} onCancel State to transition to on cancel
*/