Last active
March 28, 2020 17:08
-
-
Save kriskowal/8bff7993712c328d945710800da8c42c to your computer and use it in GitHub Desktop.
shell memo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Very slow build step. | |
sleep 5 | |
jq .+1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
time bash -c 'echo 1 | MEMO=inc-memo memo.sh inc.sh' # Slow | |
time bash -c 'echo 1 | MEMO=inc-memo memo.sh inc.sh' # Fast |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Memoizes a pure command, using git notes. | |
# $MEMO is the name of the git note. | |
INPUT=$(git hash-object -w --stdin) | |
OUTPUT=$(git notes --ref="$MEMO" show "$INPUT" 2>/dev/null) || | |
OUTPUT=$(git cat-file blob "$INPUT" | "$@" | git hash-object -w --stdin) && | |
git notes --ref="$MEMO" add -f -m "$OUTPUT" "$INPUT" 2>/dev/null | |
git cat-file blob "$OUTPUT" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The ideas just keep coming: