Skip to content

Instantly share code, notes, and snippets.

View tomasholderness's full-sized avatar

Tomas Holderness tomasholderness

View GitHub Profile
@tomasholderness
tomasholderness / map.geojson
Created August 21, 2016 09:04 — forked from anonymous/map.geojson
Black Sheep Brewery
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
// Library
var jwkToPem = require('jwk-to-pem');
// Paste your JWK here
var key='{"alg":"RS256","e":"","kid":"","kty":"RSA","n":"","use":"sig"}';
// Parse the key
key = JSON.parse(key);
// Convert to RSA Public Key (.pem)
@tomasholderness
tomasholderness / README.md
Last active May 12, 2019 09:15
Postgres Backup

PostgreSQL Database Archiving & Backup

Postgres includes the command line tools pg_dump and pg_restore to store a copy of a database as a file on disk.

Methods for archiving Postgres databases

  1. Use pg_dump/pg_restore to create binary files in the native postgres dump format
  • this method is efficient, but because the resulting .backup file is binary it can't be edited once it is created which can lead to problems when restoring. Read more: https://www.postgresql.org/docs/current/static/app-pgdump.html
  • this is the preffed method if working locally, and you have no reason to edit the backup file
  • if working with a cloud hosted service such as AWS RDS then see option (2) below. AWS uses specialist permissions and usernames which are typically are not available on a local system and so it is helpful to be able to change these in the backup file prior to restoring.
  1. Use pg_dump to create plain SQL files containing database structure and data as text.
@tomasholderness
tomasholderness / cogs.sh
Created January 30, 2019 16:13
Create COG files
# Add required overalys
gdaladdo input.tif 2 4 8 16
# Create the COG
gdal_translate input.tif cog.tif -co TILED=YES -co COPY_SRC_OVERVIEWS=YES -co COMPRESS=LZW -co BIGTIFF=YES
@tomasholderness
tomasholderness / readcog.py
Last active February 4, 2019 14:36
Lambda function to read values from a COG
import json
import rasterio
def handler(event, context):
"""Lambda function to read pixel values from a COG"""
# open file
src = rasterio.open('s3://bucket/cog.tif')
# note: lat, lon extracted from Lambda event object
@tomasholderness
tomasholderness / readcog_warm.py
Last active February 4, 2019 14:37
Lambda function to read COG, maintaining file object outside the handler
import json
import rasterio
# open file as a global
SRC = rasterio.open('s3://bucket/cog.tif') # <<-- THIS LINE HAS MOVED UP FROM THE FUNCTION BELOW :-)
def handler(event, context):
"""Lambda function to read pixel values from a COG"""