Skip to content

Instantly share code, notes, and snippets.

View geotheory's full-sized avatar

Robin Edwards geotheory

View GitHub Profile
@geotheory
geotheory / source_https.R
Last active August 29, 2015 14:26
Run R code from URL (e.g. Github)
# https://tonybreyal.wordpress.com/2011/11/24/source_https-sourcing-an-r-script-from-github/
source_https <- function(url, ...) {
# load package
require(RCurl)
# parse and evaluate each .R script
sapply(c(url, ...), function(u) {
eval(parse(text = getURL(u, followlocation = TRUE, cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl"))), envir = .GlobalEnv)
})
@geotheory
geotheory / csv2json.py
Created August 17, 2015 14:44
CSV to JSON Python script
import json
import sys
print sys.argv[1]
f = open(sys.argv[1],'r')
arr=[]
headers = []
for header in f.readline().split(','):
@geotheory
geotheory / flashall.sh
Created September 4, 2015 01:11
Running flashall.sh
indigo@indigonet:~/Downloads/toFlash$ sudo ./flashall.sh
[sudo] password for indigo:
Using U-Boot target: edison-blankcdc
Now waiting for dfu device 8087:0a99
Please plug and reboot the board
Flashing IFWI
##################################################] finished!
##################################################] finished!
Flashing U-Boot
##################################################] finished!
@geotheory
geotheory / ubilinux-flashall-osx.diff
Last active October 31, 2016 01:11 — forked from ximus/ubilinux-flashall-osx.diff
get flashall.sh to work on osx
--- flashall.sh
+++ (clipboard)
@@ -220,15 +220,14 @@
flash-command --alt u-boot-env0 -D "${VARIANT_FILE}"
echo "Flashing U-Boot Environment Backup"
- flash-command --alt u-boot-env1 -D "${VARIANT_FILE}" -R
+ flash-command --alt u-boot-env1 -D "${VARIANT_FILE}"
echo "Rebooting to apply partition changes"
- dfu-wait no-prompt
@geotheory
geotheory / report.txt
Last active September 10, 2015 22:13
Edison setup log
[Tail end of editing /etc/network/interfaces..]
Get:100 http://http.debian.net wheezy-backports/main 2015-06-17-0848.19.pdiff [486 B]
Get:101 http://http.debian.net wheezy-backports/main 2015-06-17-0848.19.pdiff [486 B]
Get:102 http://http.debian.net wheezy-backports/main 2015-06-22-1436.25.pdiff [103 B]
Get:103 http://http.debian.net wheezy-backports/main 2015-06-22-1436.25.pdiff [103 B]
Get:104 http://http.debian.net wheezy-backports/main 2015-06-30-1442.21.pdiff [956 B]
Get:105 http://http.debian.net wheezy-backports/main 2015-06-30-1442.21.pdiff [956 B]
Get:106 http://http.debian.net wheezy-backports/main 2015-07-01-2039.58.pdiff [31 B]
Get:107 http://http.debian.net wheezy-backports/main 2015-07-01-2039.58.pdiff [31 B]
@geotheory
geotheory / unknown_pleasures.R
Last active January 31, 2022 12:36
Joy Division album cover with ggplot2
require(raster)
require(ggplot2)
pulsar = function(n){
x = seq(0,100, length=n)
norms = dnorm(x, mean=40, sd=6)*100 + dnorm(x, mean=60, sd=6)*50
noise1 = approx(sample(c(rep(0:8,2),18:19)), n = n, y=NULL)$y
noise2 = approx(sample(0:50), n = n, y=NULL)$y
noise3 = rnorm(n)
abs(norms + norms * noise1 + norms * noise2 * .1 + noise3)
@geotheory
geotheory / dymax.js
Created February 4, 2016 12:23
Dymaxion projection
// Source:
// https://mbostock.github.io/protovis/ex/dymax.js
// https://mbostock.github.io/protovis/ex/dymax.html
/************************************************************************/
/* NOTE: in C, array indexing starts with element zero(0). I choose */
/* to start my array indexing with elemennt one(1) so all arrays */
/* are defined one element longer than they need to be. */
/************************************************************************/
@geotheory
geotheory / grid_lines.R
Last active February 23, 2016 14:14
Creates a spatialLines object for a grid of given x/y values
require(rgeos)
require(rgdal)
grid_lines = function(x, y, crs='+proj=longlat +datum=WGS84'){
x1 = round(seq(min(x),max(x),length.out=50),3)
y1 = round(seq(min(y),max(y),length.out=50),3)
str = character(0)
for(i in x) for(j in 2:length(y1)) str = c(str, paste(i, y1[j], ',', i, y1[j-1]))
for(i in y) for(j in 2:length(x1)) str = c(str, paste(x1[j], i, ',', x1[j-1], i))
grid = readWKT(paste('MULTILINESTRING((', paste(str, collapse='),('), '))'))
@geotheory
geotheory / project_tpe.R
Created February 22, 2016 00:20
Return proj4 CRS object defining a two-point equidistant projection fitting a spatial object
require(raster)
project_tpe = function(d, x=0, y=0){
d = data.frame(t(as.matrix(extent(d))))
dy = mean(d$y)
CRS(paste0("+proj=tpeqd +lat_1=", dy, " +lon_1=", d$x[1],
" +lat_2=", dy, " +lon_2=", d$x[2], " +x_0=", x, " +y_0=", y,
" +ellps=WGS84 +datum=WGS84 +units=m +no_defs"))
}
@geotheory
geotheory / get_areas.R
Created February 23, 2016 15:15
Get total areas of spatialPolygonsDataFrame WGS84 objects
require(geosphere)
get_areas = function(spdf){
polys = lapply(spdf@polygons, function(p) p@Polygons)
sapply(polys, function(p){
coords = lapply(p, function(p) p@coords)
ind_areas = lapply(coords, areaPolygon)
sum(unlist(ind_areas))
})
}