Skip to content

Instantly share code, notes, and snippets.

View jamescostian's full-sized avatar

James Costian jamescostian

View GitHub Profile
@jamescostian
jamescostian / install_if_not_exists.sh
Created December 15, 2019 23:02
Given a string of programs, try to install them
function install_if_not_exists {
MISSING_DEPENDENCIES=""
for program in $@; do
hash "$program" 2> /dev/null || MISSING_DEPENDENCIES="$program $MISSING_DEPENDENCIES"
done
if [[ -z "$MISSING_DEPENDENCIES" ]]; then
return
fi
if hash nix-env 2> /dev/null; then
nix-env -i $MISSING_DEPENDENCIES
-- Logs begin at Sat 2019-10-05 16:16:58 CDT, end at Sat 2019-10-12 14:05:25 CDT. --
Oct 12 13:59:12 james-desktop systemd[1]: Starting Docker Application Container Engine...
-- Subject: Unit docker.service has begun start-up
-- Defined-By: systemd
-- Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit docker.service has begun starting up.
Oct 12 13:59:12 james-desktop dockerd[5323]: time="2019-10-12T13:59:12.557952849-05:00" level=info msg="libcontainerd: started new containerd process" pid=5346
Oct 12 13:59:12 james-desktop dockerd[5323]: time="2019-10-12T13:59:12.558079670-05:00" level=info msg="parsed scheme: \"unix\"" module=grpc
Oct 12 13:59:12 james-desktop dockerd[5323]: time="2019-10-12T13:59:12.558089996-05:00" level=info msg="scheme \"unix\" not registered, fallback to default scheme" module=grpc
@jamescostian
jamescostian / git-downsize.sh
Created July 22, 2015 01:19
For when you have a gigantic .git directory
git gc --aggressive && git repack -Ad && git prune
@jamescostian
jamescostian / discrepancy.js
Last active August 29, 2015 14:18
Sort of like the difference between x and y, except relative to |x+y|
// Sort of like the difference between x and y, except it's relative to |x+y|.
// So it returns a percentage (so the value is between 0 and 1)
const discrepancy = (x, y) => {
if (y === 0 && x === 0) {
return 0
}
else if (x + y === 0) {
// They're on opposite ends of 0, so they have the largest discrepancy possible
return 1
}
@jamescostian
jamescostian / htmlentities.js
Last active March 29, 2016 14:30
This is like PHP's htmlentities, but for JS
const htmlEntities = (str) => String(str)
.replace(/&/g, '&')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&apos;')
const unhtmlEntities = (str) => String(str)
.replace(/&amp;/g, '&')
.replace(/&lt;/g, '<')