Skip to content

Instantly share code, notes, and snippets.

View joshcox's full-sized avatar

Josh Cox joshcox

  • Kansas City, Missouri
View GitHub Profile
@joshcox
joshcox / zsh.md
Last active September 12, 2015 20:53 — forked from tsabat/zsh.md
Getting oh-my-zsh to work in Ubuntu
/* Polyfill indexOf. */
var indexOf;
if (typeof Array.prototype.indexOf === 'function') {
indexOf = function (haystack, needle) {
return haystack.indexOf(needle);
};
} else {
indexOf = function (haystack, needle) {
var i = 0, length = haystack.length, idx = -1, found = false;
@joshcox
joshcox / array-concatenation.md
Created October 30, 2017 00:56
js-things.md

JavaScript Things

Methods for building arrays with conditional elements

Assuming the following variables:

const showFoo = false;
const showBar = true;

Use an intermediate variable to conditionally push values

// @ts-ignore @types/memfs does not exist
import {createFsFromVolume, Volume} from "memfs";
import path from "path";
// Create a mocked filesystem instance
const mockFs = createFsFromVolume(Volume.fromJSON({}));
jest.mock("fs", () => mockFs);
// Import modules that should be using the mocked filesystem
import {proteus} from "@proteus/core";
@joshcox
joshcox / compose.ts
Created September 19, 2018 18:10
Type Safe Function Composition in TypeScript
// Get the type of the first argument of a function
type ArgumentType<T> = T extends (a: infer U) => any ? U : any;
// Get the head type from a tuple of types
type Head<T extends any[]> = T extends [infer H, ...any[]] ? H : never;
// Get the tail type from a tuple of types
type Tail<T extends any[]> = ((...t: T) => void) extends ((h: any, ...rest: infer R) => void) ? R : never;
// Get the Last type from a tuple of types
import { applyMiddleware, createStore, Action, ActionCreator, Middleware, AnyAction } from "redux";
import thunkMiddleware, { ThunkAction, ThunkMiddleware, ThunkDispatch } from "redux-thunk";
interface IRootState {
derp: string;
}
const initialState: IRootState = {
derp: "fug"
};

Introduction

This technical design provides a comprehensive overview on the types and functionality necessary to correlate data gathered by the parsers run over a variable number of contentDirectories into a data structure that can both guide the transformations in the generate phase as well be persisted across NPMify runs.

Table of Contents

@joshcox
joshcox / foo.json
Created November 26, 2018 16:09
vscode-settings
{}
@joshcox
joshcox / EditableChip.tsx
Created June 23, 2021 10:50
Some Scaling Mt. ActivityPlan Musings
import { makeVar } from '@apollo/client';
import { Chip, FormControlLabel, InputBase } from '@material-ui/core';
import React, { useCallback, useEffect, useRef, useState } from 'react';
import { snackbarState } from 'state/snackbarState';
import styled from 'styled-components';
import { onEnterPress } from 'utils/helpers';
import { millisToSeconds, secondsToMillis } from 'utils/time';
const disableOtherChips = makeVar<boolean>(false);
#lang racket
#| What does our valof defunctionalize? |#
;; So far we fully defunctionalized environments and closures. Rather
;; than explicit higher-order function calls, we instead dispatch
;; against the choices, where we have represented each choice with a
;; corresponding data structure.
;; Josh