Skip to content

Instantly share code, notes, and snippets.

View banjeremy's full-sized avatar

Jeremy Jones banjeremy

  • pnw
  • 00:40 (UTC -07:00)
View GitHub Profile
@banjeremy
banjeremy / 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
}
@banjeremy
banjeremy / 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;
@banjeremy
banjeremy / 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
}
@banjeremy
banjeremy / .prettierrc.js
Created February 25, 2020 18:06
.prettierrc.js
module.exports = {
semi: true,
trailingComma: 'all',
singleQuote: true,
printWidth: 120,
tabWidth: 2,
};
@banjeremy
banjeremy / 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
#!/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_% %
@banjeremy
banjeremy / 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
from urllib.request import urlretrieve
from os.path import isfile, isdir
from tqdm import tqdm
import sys
class DLProgress(tqdm):
last_block = 0
def hook(self, block_num=1, block_size=1, total_size=None):
self.total = total_size
@banjeremy
banjeremy / Adaptive.sublime-theme
Created December 31, 2017 20:41
slight modification of Default Adaptive theme for Sublime Text 3
[
// Title Bar
{
"class": "title_bar",
"attributes": ["file_medium_dark"],
"bg": ["background", 0, 0, 0, 0.25]
},
// Side Bar
{
"class": "sidebar_container",
@banjeremy
banjeremy / js-quickstart.md
Last active September 28, 2017 15:06
JavaScript Quick Start Resources