Skip to content

Instantly share code, notes, and snippets.

View phdesign's full-sized avatar

Paul Heasley phdesign

View GitHub Profile
@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
@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 / 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 / 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 / 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 / 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 / python2.bat
Created October 16, 2018 17:37
Python on Windows
rem Place this in C:\Python27\python2.bat
@echo off
set OLDPATH=%PATH%
path C:\Python27;%PATH%
python.exe %*
path %OLDPATH%
@phdesign
phdesign / pwned-passwords.sh
Last active September 29, 2018 13:03
Bash One-Liner to Check Your Password(s) via pwnedpasswords.com’s API Using the k-Anonymity Method
echo "Enter your password:"; read -s pass_str; sha1=$(echo -n $pass_str | tr -d '\n' | openssl sha1); echo "Hash prefix: ${sha1:0:5}"; echo "Hash suffix: ${sha1:5:35}"; result=$(curl https://api.pwnedpasswords.com/range/${sha1:0:5} 2>/dev/null | grep $(echo ${sha1:5:35} | tr '[:lower:]' '[:upper:]')); printf "Your password appeared %d times in the database.\\n" "${result#*:}" 2>/dev/null
@phdesign
phdesign / IPAddressIsInRange.sql
Created June 5, 2018 04:12
Check if a string IP address is in a CIDR range in SQL Server
create function dbo.IPAddressIsInRange(@ip as varchar(15), @range as varchar(18))
returns bit
as
begin
declare @prefix varchar(15),
@cidr varchar(2),
@mask bigint
set @prefix = left(@range, charindex('/', @range) - 1)
set @cidr = right(@range, len(@range) - charindex('/', @range))
@phdesign
phdesign / emoji.ahk
Last active May 24, 2018 03:16
Some text emjoi autocompletes, e.g. :shurg: :table_flip:
; NOTE: This must be saved as UTF-8 BOM
emoji(text){
If (A_EndChar = ":") {
SendInput %text%
} Else {
StringMid, s, A_ThisHotKey, 3 ; A_ThisHotKey contains 2 starting colons
SendRaw %s%%A_EndChar%
}
}