Skip to content

Instantly share code, notes, and snippets.

View hrwgc's full-sized avatar

Chris Herwig hrwgc

  • Google
  • San Francisco
View GitHub Profile
@hrwgc
hrwgc / README.md
Last active September 4, 2023 11:15
VIIRS Nighttime Lights 2012 processing
@hrwgc
hrwgc / nasa_iotd.py
Last active December 12, 2015 02:38
Create SQLite archive of NASA image of the day blog #Python #BeautifulSoup #SQLite
import scraperwiki
import urllib2, urllib
import re, os
import sqlite3
import uuid
from bs4 import *
import lxml
import unicodedata
from time import sleep
@hrwgc
hrwgc / noaa_viirs_fire.py
Last active December 12, 2015 07:28
Scraper for NOAA VIIRS Combustion Source CSVs
import urllib2, urllib
import re, os
import sqlite3
import uuid
import contextlib
from bs4 import *
import csv
import unicodedata
@hrwgc
hrwgc / postgresql_quantiles.md
Last active May 31, 2018 13:36
Calculate quantile distributions for PostgreSQL column
SELECT
ntile,
CAST(avg(length) AS INTEGER) AS avgAmount,
CAST(max(length) AS INTEGER)  AS maxAmount,
CAST(min(length) AS INTEGER)  AS minAmount 
FROM (SELECT length, ntile(6) OVER (ORDER BY length) AS ntile FROM countries) x
GROUP BY ntile
ORDER BY ntile;
@hrwgc
hrwgc / smithsonian_folkways.geojson
Created June 1, 2013 16:58
smithsonian folkways record collection
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@hrwgc
hrwgc / nearest_neighbor.sql
Last active December 19, 2015 06:19
postgis select across polygon layers based on nearest adjacent polygon from other layer.
create table
closest_point as
select distinct on (a.featureid) a.featureid as image_id,
(select b.eventid from fl_events as b order by st_distance(a.wkb_geometry,b.wkb_geometry) limit 1) as event_id,
a.wkb_geometry from images as a,
fl_events as b;
update images set eventid = closest_point.event_id from closest_point where images.featureid = closest_point.image_id;
@hrwgc
hrwgc / clipboard.py
Last active December 20, 2015 01:38
#!/usr/bin/env python
import os
def CopyToClipboard(text):
cmd = "echo '%s' | tr -d \"\\\n\" | pbcopy" % text
os.system(cmd)
@hrwgc
hrwgc / clean_git.sh
Created October 22, 2013 14:49
remove all non master branches from git repo
function clean_git_branches(){
git checkout master;
BRANCHES=`git branch | grep -Ev '^\s{0,}\*{0,}\s{0,}master$'`
git branch -D ${BRANCHES[@]}
}
Landsat 4-5 Wavelength Landsat 7 Wavelength Landsat 8 Wavelength (micrometers)
Band 1 - Coastal aerosol 0.43 - 0.45
Band 1 0.45-0.52 Band 1 0.45-0.52 Band 2 - Blue 0.45 - 0.51
Band 2 0.52-0.60 Band 2 0.52-0.60 Band 3 - Green 0.53 - 0.59
Band 3 0.63-0.69 Band 3 0.63-0.69 Band 4 - Red 0.64 - 0.67
Band 4 0.76-0.90 Band 4 0.77-0.90 Band 5 - Near Infrared (NIR) 0.85 - 0.88
Band 9 - Cirrus 1.36 - 1.38
Band 5 1.55-1.75 Band 5 1.55-1.75 Band 6 - SWIR 1 1.57 - 1.65
Band 7 2.08-2.35 Band 7 2.09-2.35 Band 7 - SWIR 2 2.11 - 2.29
@hrwgc
hrwgc / validate.sh
Created November 13, 2013 19:57
bash wget - check if file exists at url before downloading
#!/bin/bash
# simple function to check http response code before downloading a remote file
# example usage:
# if `validate_url $url >/dev/null`; then dosomething; else echo "does not exist"; fi
function validate_url(){
if [[ `wget -S --spider $1 2>&1 | grep 'HTTP/1.1 200 OK'` ]]; then echo "true"; fi
}