Skip to content

Instantly share code, notes, and snippets.

View andrewbattista's full-sized avatar
🎯
Focusing

Andrew Battista andrewbattista

🎯
Focusing
View GitHub Profile
@andrewbattista
andrewbattista / pull-invenio-records.md
Last active September 17, 2020 17:09
Pull all records from invenio and pretty print them

Pull all records from invenio

Use this bash script and command to pull down all records from invenio and save them as discrete files within uniquely named directories

Create a file named invenio_recs.sh with these contents:

#!/bin/bash

#create directory for records
@andrewbattista
andrewbattista / exec-cat-js.md
Created September 8, 2020 11:09
Concatenate many JSON files into single JSON file with JS

If you have a directory path with many JSON files in it and you want them all on a single document for batch edits use JS

find . -name '*.json' -exec cat '{}' + | jq -s '.' > /Users/staff/Desktop/newjsonsinglefile.json

To reduce the process time for exceedingly large examples, you may be able to simply use

find . -name '*.json' -exec jq -s '{}' + > /Users/staff/Desktop/newjsonsinglefile.json
@andrewbattista
andrewbattista / grep-get-coordinates.md
Created July 13, 2020 20:56
Recursive extraction of coordinates from .JPG files

Use grep to strip out elements from photo metadata

If you have a bunch of .jpg photos in a directory that were taken with a camera with coordinates associated, this workflow will allow you to recursively get the coordinates.

First, install exiftool Then, from the directory where all of the .JPGs are

exiftool /Users/andrewbattista/desktop/*.JPG |grep 'File Name\|GPS Latitude\|GPS Longitude'
@andrewbattista
andrewbattista / recursive-conversion-gdal.md
Last active July 2, 2020 12:27
Recursive conversion between formats with GDAL

Recursive conversion with GDAL

This shell script assumes that you have already installed GDAL and are converting between .KMZ files and Shapefiles with the names preserved. The specific ogr2ogr commands can be changed as needed. This also assumes many .KMZ files in a single directory. Kudos to Marii Nyrop.

Begin by creating a file named batch-separate-folders.sh with the following and place it in your directory with the KMZs:

for KMZ in *.kmz; do
  IDENTIFIER="$(basename ${KMZ} .kmz)"
@andrewbattista
andrewbattista / zip-files.md
Last active May 4, 2020 14:15
Zip all files in a directory and rename

Zips all files within a containing directory

This zips all files in a directory and renames the zip archive according to the name of the existing directory.

for i in */; do zip -r "${i%/}.zip" "$i"; done