Skip to content

Instantly share code, notes, and snippets.

View phdesign's full-sized avatar

Paul Heasley phdesign

View GitHub Profile
@phdesign
phdesign / sort_json.sh
Created May 28, 2019 19:15
Sort JSON properties on the command line using python
cat /dev/clipboard | python -c 'import json, sys; json.dump(json.load(sys.stdin), sys.stdout, indent=4, sort_keys=True);'
@phdesign
phdesign / build.js
Last active August 19, 2020 14:41
Create react app no chunking, single file embedded CSS
// npm install rewire
const rewire = require('rewire');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const defaults = rewire('react-scripts/scripts/build.js');
const config = defaults.__get__('config');
// Consolidate chunk files instead
config.optimization.splitChunks = {
cacheGroups: {
default: false,
@phdesign
phdesign / use-safe-context.js
Created September 5, 2022 05:32
A wrapper around `React.useContext` that throws an error if the context value is `undefined`.
import { useContext } from "react"
/**
* A wrapper around `React.useContext` that throws an error if the context
* value is `undefined`, indicating that the component is not wrapped in the
* context provider.
* @param {React.Context} context
* @return {any} The context value.
*/
export const useSafeContext = (context) => {
@phdesign
phdesign / run-notebook.sh
Last active March 8, 2023 22:05
Run a jupyter notebook in headless mode and update in place
jupyter nbconvert --ExecutePreprocessor.timeout=-1 --to notebook --inplace --allow-errors --execute $1
@phdesign
phdesign / .huskyrc
Created March 19, 2023 00:44
Support for asdf managed npm in Fork application (or any husky run)
. /usr/local/opt/asdf/libexec/asdf.sh
@phdesign
phdesign / .gitconfig
Created March 24, 2024 20:47
Handy git alias commands
[alias]
prune-gone = !git remote prune origin && git branch -v | grep gone | awk '{print $1}' | xargs git branch -D
recent = !git for-each-ref --sort='-authordate:iso8601' --format='%(authordate:relative)%09%(refname:short)' refs/heads | head -15