Skip to content

Instantly share code, notes, and snippets.

View jmakeig's full-sized avatar

Justin Makeig jmakeig

View GitHub Profile
jmakeig / sparse_timeseries.sql
Last active September 15, 2023 22:51
Use case: Timeseries data that’s stored densely, but needs to be reported sparsely, i.e. with explicit zeros for missing periods. (RIGHT JOIN for the win!)
View sparse_timeseries.sql
-- PostgreSQL 14
days AS observation_date,
-- Explicitly coalescing missing values to zero.
-- This logic will be use case-dependent.
coalesce(metrics.metric, 0) AS metric
-- Replace this with the dense metrics table
(values ('2023-01-01'::date, 111111), ('2023-06-15'::date, 222222)) AS metrics (observation_date, metric)
jmakeig / example.js
Last active January 6, 2023 06:30
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 / timer.css
Created December 29, 2021 20:56
Timer CSS animation
View timer.css
svg {
display: inline-block;
height: 90px;
width: 90px;
svg.timer {
transform: rotate(-90deg);
overflow: visible;
circle.gague {
jmakeig / fy-date-converter.xlsx
Created July 2, 2020 22:54
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 /
Last active March 23, 2023 15:43
Split a file containing a JSON Array into one file per item
#!/usr/bin/env bash
# Splits a file that contains a top-level JSON Array
# into individual files, one per item, named sequentially
jq -c .[] "$1" | awk '{print > (NR ".json")}'
jmakeig / transform.js
Created March 15, 2020 18:15
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 / values.js
Last active February 27, 2020 07:37
MarkLogic’s cts.frequency function is magic. Could we do something more explicit? (Spoiler: probably not by much)
View values.js
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 / table.html
Last active February 12, 2022 19:30
Default table CSS
View table.html
<!DOCTYPE html>
<title>Progenitor Mock-up</title>
<style type="text/css">
table {
position: relative; /* Needed for sticky headers */
width: 100%;
jmakeig / machine.js
Last active February 18, 2020 06:18
Generated by XState Viz:
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 / nested-tables.html
Last active February 12, 2020 06:34
Display complex tree data structures as nested HTML tables.
View nested-tables.html
<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8" />
<title>Nested Tables</title>
html {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
font-size: 14px;