Skip to content

Instantly share code, notes, and snippets.

View eczajk1's full-sized avatar

Eric Czajkowski eczajk1

  • Maryland
View GitHub Profile
@eczajk1
eczajk1 / dump-eml-attachments.js
Last active December 11, 2019 20:16
Dump e-mail attachments from a folder of e-mail (.eml) files
const fs = require('fs')
const Promise = require('bluebird');
const moment = require('moment');
const { simpleParser } = require('mailparser');
const run = async (params) => {
const { inputFolder, outputFolder } = params;
// make a list of e-mails (.eml files)
const files = fs.readdirSync(inputFolder);
@eczajk1
eczajk1 / form-ids-and-names.sh
Created May 31, 2019 00:44
Gets a list of Fulcrum Form names and IDs
curl --request GET 'https://api.fulcrumapp.com/api/v2/forms.json' \
--header 'Accept: application/json' \
--header 'X-ApiToken: yer_token' | jq '.forms[] | {name, id}'
@eczajk1
eczajk1 / record-history.sh
Last active April 28, 2019 00:25
bash script to download and create JSON files for each version of a Fulcrum record's history
#!/usr/bin/env bash
# USAGE: bash record-history.sh -r <record_id> -t <api_token> -d <some_folder>
fulcrum_id=''
token=''
folder='./'
while getopts 'r:t:d:' flag; do
case "${flag}" in
@eczajk1
eczajk1 / fgdb-to-pg
Created March 11, 2019 14:47
Convert (EPSG:4269) to 4326 (WGS84), FileGDB to PostGIS, query out some data
ogr2ogr -t_srs EPSG:4326 \
-f "PostgreSQL" \
PG:"host=localhost user=postgres dbname=mydb password=mypassword" \
"myfgdb.gdb" "myfeatureclass" \
-where "somefield" <> 'some_value'

Railroad Crossings

Original dataset (comma separated values, CSV) was downloaded from https://safetydata.fra.dot.gov/officeofsafety/publicsite/downloaddbf.aspx

The following ogr2ogr script converts the CSV file to GeoJSON, keeping several attributes that we wished to use for styling:

ogr2ogr -f "geojson" \
  crossings-5.geojson \
 CI_Crossings.csv -oo X_POSSIBLE_NAMES=Longitude -oo Y_POSSIBLE_NAMES=Latitude \
@eczajk1
eczajk1 / unix-to-date-time.txt
Created October 5, 2018 15:25
Convert unix timestamp to Date/Time in Excel
=(((((B4/1000)/60)/60))/24)+DATE(1970,1,1)
@eczajk1
eczajk1 / gpkg-to-pg.sh
Created September 25, 2018 19:26
load GeoPackage into PostgreSQL
ogr2ogr -f PostgreSQL PG:"dbname='mydb' host='localhost' port='5432' user='postgres' password='ilovedonuts'" \
~/Desktop/mygpkg.gpkg gpkg_layer_name -nln pg_schema_name.pg_layer_name
@eczajk1
eczajk1 / resize-photos.sh
Created June 13, 2018 17:43
Use ImageMagick to resize a folder of JPG files
for file in $(ls *.jpg); do magick ${file} -resize 640x640 ./out/${file}; done
@eczajk1
eczajk1 / resize-photos.js
Created April 5, 2017 14:27
Resize photos in a folder, saving the new files in a subfolder. Requires ImageMagick 7
var exec = require('child_process').exec;
var fs = require('fs');
fs
.readdirSync(__dirname)
.filter(function (file) {
return file.indexOf('.') > -1 && file != 'index.js';
})
.forEach(function(file) {
exec('magick ' + file + ' -resize 640x640 ./out/' + file)