Skip to content

Instantly share code, notes, and snippets.

View jkeefe's full-sized avatar

John Keefe jkeefe

View GitHub Profile
@jkeefe
jkeefe / pi.md
Last active January 17, 2026 21:53
Prepping a Raspberry Pi

Preparing a Pi

My Mac is too old to use the Raspberry Pi Imager.

So intstead I ...

  • go to the downloads page and download the "Raspberry Pi OS" version (as opposed to the "Full" or "Lite" versions — just my preference).
  • use balenaEtcher to image a Mini SD card. The card should be an "A2" version, and I like to use 64GB.
  • use a USB keyboard and HDMI monitor to set up:
  • Wifi network and password (set on first bootup)
@jkeefe
jkeefe / large_files.sh
Last active December 24, 2024 17:02
Removing large files from Github repo commit history
# example: get rid of large `.tif` and `.nc` files in gis/tmp
# from https://www.geeksforgeeks.org/how-to-remove-a-large-file-from-commit-history-in-git/
git filter-branch --force --index-filter \
'git rm --cached --ignore-unmatch gis/tmp/*.tif' \
--prune-empty --tag-name-filter cat -- --all
git filter-branch --force --index-filter \
'git rm --cached --ignore-unmatch gis/tmp/*.nc' \
--prune-empty --tag-name-filter cat -- --all
@jkeefe
jkeefe / round.js
Created August 3, 2023 18:00
Sweet dayjs rounding function
// from https://github.com/iamkun/dayjs/issues/1619#issuecomment-1185714859
const round: PluginFunc = (option, dayjsClass) => {
dayjsClass.prototype.round = function (amount, unit) {
const mod = this.get(unit as UnitType) % amount;
if(mod < amount / 2) {
return this.subtract(mod, unit).startOf(unit);
}
@jkeefe
jkeefe / import_mapshaper.js
Last active November 26, 2024 15:50
Importing mapshaper in ES6
// npm install mapshaper --save
import mapshaper from 'mapshaper'
// Example of runCommands: converting a directory of Shapefiles to GeoJSON
mapshaper.runCommands('-i shapefiles/*.shp -o geojson/ format=geojson');
// ----
// Example of applyCommands: processing a json array
@jkeefe
jkeefe / access.json
Last active May 3, 2024 19:22
Access One Bucket Policy
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:ListAllMyBuckets"
],
"Resource": "arn:aws:s3:::*"
},
@jkeefe
jkeefe / cors.json
Last active October 25, 2023 22:38
Open CORS policy for AWS S3
[
{
"AllowedHeaders": [
"*"
],
"AllowedMethods": [
"GET",
"HEAD"
],
"AllowedOrigins": [
@jkeefe
jkeefe / delay.js
Created January 29, 2023 21:23
Node delay function
function delay(time) {
return new Promise(resolve => setTimeout(resolve, time));
}
// usage:
console.log("Thing one")
await delay(2000)
console.log("Thing two, two seconds later")
@jkeefe
jkeefe / niceRounder.js
Last active October 21, 2025 00:29
Rounds whole numbers to nice figures for publication
// based on: https://stackoverflow.com/a/67136959
const niceRounder = (number) => {
let near = 1
if (number > 100) near = 10
if (number > 1000) near = 100
if (number > 10000) near = 1000
if (number % near === 0) return number;
@jkeefe
jkeefe / nyt_states.json
Created December 27, 2022 21:53
Translation json for NYT state names
[{"name":"Alabama","nyt":"Ala.","postal":"AL"},
{"name":"Alaska","nyt":"Alaska","postal":"AK"},
{"name":"Arizona","nyt":"Ariz.","postal":"AZ"},
{"name":"Arkansas","nyt":"Ark.","postal":"AR"},
{"name":"California","nyt":"Calif.","postal":"CA"},
{"name":"Colorado","nyt":"Colo.","postal":"CO"},
{"name":"Connecticut","nyt":"Conn.","postal":"CT"},
{"name":"Delaware","nyt":"Del.","postal":"DE"},
{"name":"District of Columbia","nyt":"D.C.","postal":"DC"},
{"name":"Florida","nyt":"Fla.","postal":"FL"},
@jkeefe
jkeefe / time_hash.js
Last active April 20, 2023 14:14
Cool hex time hash for cache busting, unique, etc.
const time_hash = Date.now().toString(36);
// reverse it for more wordiness:
const time_hash2 = Date.now().toString(36).split("").reverse().join("")