Skip to content

Instantly share code, notes, and snippets.

View banjeremy's full-sized avatar

Jeremy Jones banjeremy

  • pnw
  • 04:21 (UTC -07:00)
View GitHub Profile
@banjeremy
banjeremy / hello-world-threejs.html
Last active April 10, 2023 01:58
Hello World with Three.js
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Hello, Three.js!</title>
<style>
body { margin: 0; }
canvas { width: 100%; height: 100%; }
</style>
</head>
@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 / load-resource.scala
Created January 29, 2017 00:18
scala: load files from resources directory
def loadResource(filename: String) = {
val source = scala.io.Source.fromURL(getClass.getResource(filename))
try source.mkString finally source.close()
}
@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