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 / 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 / 1_how_to_fix.md
Last active December 29, 2015 11:19
postgres / postgis randomly stops working on osx mavericks - fix

Following advice of Psql: could not connect...:

Running the following command resets PostgreSQL's transaction log, which resolves the problem.

 pg_resetxlog -f /usr/local/Cellar/postgresql/9.3.1/data

you should replace /usr/local/Cellar/postgresql/9.3.1/data with your own pg_datadir (eg., pg_ctl -D $DATADIR start)

@hrwgc
hrwgc / mapbox_learn.md
Last active September 5, 2016 15:24
Resources for those just starting with Mapbox, TileMill, and Quantum GIS
@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 / translate.sh
Created December 12, 2012 20:34
Command line translator application using Bing's free Translator service.
#!/bin/bash
if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then
echo 'Usage: translate.sh ["Original Text"] ["Source Language"] ["Target Language"]'
echo 'Example: translate.sh "Hello World" "en" "fr"'
declare -a LANG_NAMES=('Arabic' 'Czech' 'Danish' 'German' 'English' 'Estonian' 'Finnish' 'French' 'Dutch' 'Greek' 'Hebrew' 'Haitian Creole' 'Hungarian' 'Indonesian' 'Italian' 'Japanese' 'Korean' 'Lithuanian' 'Latvian' 'Norwegian' 'Polish' 'Portuguese' 'Romanian' 'Spanish' 'Russian' 'Slovak' 'Slovene' 'Swedish' 'Thai' 'Turkish' 'Ukrainian' 'Vietnamese' 'Simplified Chinese' 'Traditional Chinese');
declare -a LANG_CODES=('ar' 'cs' 'da' 'de' 'en' 'et' 'fi' 'fr' 'nl' 'el' 'he' 'ht' 'hu' 'id' 'it' 'ja' 'ko' 'lt' 'lv' 'no' 'pl' 'pt' 'ro' 'es' 'ru' 'sk' 'sl' 'sv' 'th' 'tr' 'uk' 'vi' 'zh-CHS' 'zh-CHT');
for IX in $(seq 0 $((${#LANG_CODES[@]} - 1))); do
echo ${LANG_CODES[$IX]}: ${LANG_NAMES[$IX]};
done
@hrwgc
hrwgc / README.md
Last active May 3, 2020 01:12
download all of your gists from gist.github.com

gist list

A command line script to retrieve json for all of your gists.

usage:

github.sh [username] [password] [total number of gists] [oath or user:password]
@hrwgc
hrwgc / evernote_parse.py
Last active January 1, 2022 10:13
Evernote note export wrangling to sqlite -> markdown jekyll data
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sqlite3
import sys
import re
import uuid
from bs4 import *
import lxml
import unicodedata