Skip to content

Instantly share code, notes, and snippets.

View salishdev's full-sized avatar

Jeremy Jones salishdev

View GitHub Profile
@salishdev
salishdev / gh-pages.sh
Created February 13, 2018 21:26
create orphan gh-pages branch
git checkout --orphan gh-pages
git subtree push --prefix dist origin gh-pages
#!/usr/bin/env bash
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=merged.pdf **.pdf
# jpg to pdf
ls *.JPG | xargs -I% convert % -quality 100 %.pdf
# compress them
ls *.pdf | xargs -I% gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=compressed_% %
@salishdev
salishdev / fu.sh
Created June 22, 2018 15:41
reckless process murdering script
#!/usr/bin/env bash
if [ $# -eq 0 ]
then
echo "usage: fu <grep pattern>"
exit 1
fi
pattern=$1
@salishdev
salishdev / .prettierrc.js
Created February 25, 2020 18:06
.prettierrc.js
module.exports = {
semi: true,
trailingComma: 'all',
singleQuote: true,
printWidth: 120,
tabWidth: 2,
};
@salishdev
salishdev / whatsonport.zsh
Created April 9, 2021 14:18
get pid for a process running on a port
whatsonport () {
if [ $# -eq 1 ]
then
lsof -i :$1 | awk '{ print $2; }' | head -n 2 | grep --color=auto --exclude-dir={.bzr,CVS,.git,.hg,.svn,.idea,.tox} -v PID
else
echo "Usage: whatsonport [port]"
fi
}
@salishdev
salishdev / useLocalStorage.ts
Created June 22, 2021 22:37
useLocalStorage
import { useCallback, useState } from 'react';
// like `useState`, but also persists to local storage
export default function useLocalStorage<T>(key: string, initialValue: T): [T, (initialValue: T) => void] {
const [state, setState] = useState<T>(() => {
try {
const value = localStorage.getItem(key);
return value ? JSON.parse(value) : initialValue;
} catch (e) {
return initialValue;
@salishdev
salishdev / whatsonport.sh
Created October 12, 2021 22:20
Find what process is using a port
whatsonport () {
if [ $# -eq 1 ]
then
lsof -i :$1 | awk '{ print $2; }' | head -n 2 | grep --color=auto --exclude-dir={.bzr,CVS,.git,.hg,.svn,.idea,.tox} -v PID
else
echo "Usage: whatsonport [port]"
fi
}