Skip to content

Instantly share code, notes, and snippets.

View jkeefe's full-sized avatar

John Keefe jkeefe

View GitHub Profile
@jkeefe
jkeefe / first_frame.sh
Created November 2, 2021 18:58
Extract first frame from a video as an image
ffmpeg -i infile.mp4 -vf "select=eq(n\,0)" -q:v 3 outfile.jpg
# from https://stackoverflow.com/questions/4425413/how-to-extract-the-1st-frame-and-restore-as-an-image-with-ffmpeg/4425466
@jkeefe
jkeefe / sub.css
Created October 29, 2021 14:09
Prevent sub/superscripts from affecting line height in CSS
// from https://css-tricks.com/snippets/css/prevent-superscripts-and-subscripts-from-affecting-line-height/
sup, sub {
vertical-align: baseline;
position: relative;
top: -0.4em;
}
sub {
top: 0.4em;
}
@jkeefe
jkeefe / dots.js
Last active October 29, 2021 01:34
d3 lines - with intermediary points
// assumes multiple lines on a graph
// like: {id: 'category one', values: [ [0,0], [1,1] [2,2] ... ]}
// define circles as markers for the line to use
lines.append('defs')
.append('marker')
.attr('id', d => `v-dot-${d.id}`)
.attr('viewBox', [0, 0, 10, 10])
.attr('refX', 5)
@jkeefe
jkeefe / Makefile
Created October 8, 2021 20:34
Make SVG maps with more than one layer
hpgraphic:
npx mapshaper -i ./src/data/latest-mercator.geojson ./src/data/states/us-state-innerlines.geojson combine-files \
--rename-layers counties,lines \
--style target=lines stroke='#a0a0a0' stroke-width=0.5 \
-proj albersusa \
-o target=counties,lines format=svg ./src/data/for_hp.svg
@jkeefe
jkeefe / sheet2json.js
Created October 7, 2021 01:05
Google Sheets to JSON Script
/* Source: https://gist.github.com/daichan4649/8877801 */
/* and this blog post: https://www.labnol.org/code/20005-publish-json-google-spreadsheets */
// Note: To use...
// - from your sheet, go to Tools > Script Editor
// - delete the code that's there
// - paste in this code
// - change the sheetId to match that of your sheet. You'll find it in the url between /d/ and /edit
// - click "run" and authorize the app
// - click "Deploy"
@jkeefe
jkeefe / legend.css
Last active September 27, 2021 22:50
Responsive Map Legend
/// legend css ///
.v-legend-hed {
font-weight: bold;
font-size: 16px;
margin-bottom: 12px;
width: 100%;
text-align: center;
margin-top: 20px;
}
@jkeefe
jkeefe / get_history.sh
Created September 9, 2021 01:55
Load all of the previous versions of a file in git from earlier commits
#!/bin/sh
# copied from https://github.com/truist/settings/blob/master/bin/git_export_all_file_versions
# more details here: https://stackoverflow.com/questions/12850030/git-getting-all-previous-version-of-a-specific-file-folder
# based on script provided by Dmitry Shevkoplyas at http://stackoverflow.com/questions/12850030/git-getting-all-previous-version-of-a-specific-file-folder
set -e
if ! git rev-parse --show-toplevel >/dev/null 2>&1 ; then
echo "Error: you must run this from within a git working directory" >&2
@jkeefe
jkeefe / Makefile
Created August 31, 2021 20:36
Making state water files. Your paths will vary.
# usage: make water STATE=06
water:
# note that I've previously downloaded all county water files from ftp2.census.gov/geo/tiger/TIGER2020/AREAWATER
# to /Volumes/jkeefe-data/2020_Census/AREAWATER on my computer
mkdir -p ./tmp/water
rm ./tmp/water/*.*
cd /Volumes/jkeefe-data/2020_Census/AREAWATER; unzip -o "tl_2020_$(STATE)*.zip" -d /Users/keefe/cnnvis-census2020-dot-maps/tmp/water
npx mapshaper -i './tmp/water/*.shp' combine-files \
-simplify 40% \
@jkeefe
jkeefe / gdal_solve.md
Created July 21, 2021 21:50
Solve "ModuleNotFoundError: No module named 'gdal' in qgis

I was having trouble installing QGIS plugins because I kept hitting ModuleNotFoundError: No module named 'gdal'

Here's how I solved it

  • QGIS -> Preferences -> System
  • See "Current environment variables" window
  • Note the path that is called PYTHONHOME (mine was /Applications/QGIS-LTR.app/Contents/MacOS )
  • Open terminal
  • Look for gdal using find /Applications/QGIS-LTR.app/Contents -type f -name "gdal.*"
  • Note location. Mine was: `/Applications/QGIS-LTR.app/Contents/Resources/python/site-packages/GDAL-3.2.1-py3.8-macosx-10.13.0-x86_64.egg/osgeo/gdal.py
@jkeefe
jkeefe / pym_custom_height.js
Last active February 16, 2022 21:30
Send a custom height to pym
// update height, sending an extra 20 pixels to be safe
const mainElementHeight = (document.getElementsByTagName('body')[0].offsetHeight + 20).toString();
pymChild.sendMessage('height', mainElementHeight);
//// may need to add this:
// instantiate pym object
window.pymChild = new Child();
// or, for cnn rig, inside your draw function:
pymChild.sendMessage('height', initialHeight);