Skip to content

Instantly share code, notes, and snippets.

@bholloway
bholloway / README.md
Last active May 1, 2024 06:11
Split a single file into multiple files in the directory

Git-spit

Split a single file into multiple files under a directory name based on the original.

Maintain git history.

Usage

prerequisites

Create a file names.txt that contains one line for each of the files that are the targets of the split.

@bholloway
bholloway / cleanup branches
Last active February 14, 2023 05:49
Remove references to remote branches without removing from remote
git branch -r | grep -v "origin/master$" | tr -d "[:blank:]" | tr "\n" "\0" | xargs -0 git branch -d -r
@bholloway
bholloway / promise-all-with-timing.js
Created February 21, 2020 00:58
Flow typed decorator for promise.all() with timing
/**
* Creates a new "outer" async function with the same signature as the given `promiseFactoryFn`.
*
* When the outer function is invoked the `promiseFactoryFn` is passed the same arguments and must return a Promise or
* array thereof.
*
* When all promises complete the `callback` is invoked with the duration of each, in milliseconds. The result of the
* promises is returned from the outer function.
*/
export const promiseAllWithTiming = <T: $ReadOnlyArray<mixed>, U: mixed>(
@bholloway
bholloway / walk-webpack-statgroups.js
Created December 11, 2019 22:28
visitor for webpack stat groups
const walk = (text) => (v) => {
if (Array.isArray(v)) {
return walk(text)({ groups: v });
} else {
const { label, path, gzipSize, groups } = v;
if (label && label.includes(text)) {
return [{label, path, gzipSize}];
} else if (groups && groups.length) {
return groups.map(walk(text)).reduce((r, v) => r.concat(v), []);
} else {
const { basename } = require('path');
const { ConcatSource } = require('webpack-sources');
const ModuleFilenameHelpers = require('webpack/lib/ModuleFilenameHelpers');
/**
* Loosely based on wrapper-webpack-plugin
* https://www.npmjs.com/package/wrapper-webpack-plugin
*
* Chunk deletion based on webpack-remove-empty-js-chunks-plugin
@bholloway
bholloway / babel-plugin-instrument-promises.js
Created November 7, 2019 01:46
babel plugin to instrument promises with performance marks
const { relative } = require('path');
module.exports = babel => {
const {
types: {
stringLiteral,
callExpression,
identifier,
isMemberExpression,
isCallExpression,
@bholloway
bholloway / regex-template-literal.js
Last active May 21, 2024 12:36
Template literal for multiline regex with comments
/**
* Simple custom template literal that removes comments and whitespace in regex
*/
const regex = ({ raw }, ...substitutions) =>
new RegExp(
String.raw(
{ raw: raw.map(v => v.replace(/\s+#.*$/gm, '').replace(/[\s\r\n]+/g, '')) },
...substitutions,
),
);
@bholloway
bholloway / permute.js
Created October 18, 2019 04:05
permutations of arrays for jest test.each
/**
* Give all permutations of the values of the given arrays.
*
* Each given array implies at least on column in the output. Array elements are spread to create multiple columns.
* This may yeild variable length elements in the final output.
*/
const permute = (...arrays) =>
arrays.reduceRight(
(previous, array) =>
array.reduce(
@bholloway
bholloway / nonmaybe.flow
Created July 23, 2019 11:27
convert object fields to non-maybe types
type NonMaybe<T> = $ObjMap<T, <U>(param: U) => $NonMaybeType<U>>;
@bholloway
bholloway / index.html
Last active July 10, 2018 10:13
Sankey Labels: JS Bin// source https://jsbin.com/kehucuy
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<style id="jsbin-css">
.container {
display: flex;
flex-direction: row;