Skip to content

Instantly share code, notes, and snippets.

View tomasholderness's full-sized avatar

Tomas Holderness tomasholderness

View GitHub Profile
@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"""
@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 / 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 / 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.
// 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 / 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.
[{"_notes":[],"group_terdampak/jml_orang_pengungsi":75,"_bamboo_dataset_id":"","_tags":[],"_xform_id_string":"form_laporan_genangan_v2","group_location/gps":"-6.1822678 106.8287187 0.0 20.0","meta/instanceID":"uuid:5a14b798-1910-41c3-8728-6d6bcfdf2d97","_duration":"","group_terdampak/jml_orang_terdampak":75,"group_terdampak/jml_kk_pengungsi":10,"group_flood/rekomendasi_banjir":"penurapan","_geolocation":[-6.1822678,106.8287187],"group_surveyor/surveyor":"Puji Astuti","_edited":false,"group_location/total_rt":3,"_status":"submitted_via_web","kota":"jakarta_timur","group_location/kelurahan":"cililitan","_uuid":"5a14b798-1910-41c3-8728-6d6bcfdf2d97","group_flood/tinggi_banjir":"10_70","group_surveyor/organisasi":"Kpbk Jakarta timur","_submitted_by":null,"group_location/rw":7,"group_location/rt":"1,5,7","formhub/uuid":"e7ba4b6ac8154449b81e29efb600b505","group_flood/picture":"1459825750578.jpg","_submission_time":"2016-04-05T03:16:59","kecamatan":"kramat_jati","_version":"201603080102","_attachments":[{"mimetype":
@tomasholderness
tomasholderness / chip_countdown.html
Created November 30, 2015 00:46
Updated Countdown for CHIP, with timezone!
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script src="https://code.jquery.com/jquery-2.1.4.js"></script>
<script src="jquery.countdown-2.1.0/jquery.countdown.js"></script>
<script src="http://momentjs.com/downloads/moment.js"></script>
<script src="http://momentjs.com/downloads/moment-timezone.js"></script>
</head>
<body>
@tomasholderness
tomasholderness / 6418f4.patch.sql
Created November 24, 2015 10:55
Patch for cognicity-schema 2.0.x commit 6418f4
ALTER TABLE tweet_reports ADD column tweet_id bigint;
@tomasholderness
tomasholderness / 37628c0.patch.sql
Last active November 24, 2015 10:55
Patch for cognicity-schema 2.0.x commit 37628c0
ALTER TABLE all_reports ADD COLUMN status character varying DEFAULT 'confirmed';
COMMENT ON COLUMN all_reports.status IS '{character varying} Status of the report (defaults to confirmed)';