Skip to content

Instantly share code, notes, and snippets.

View barryrowlingson's full-sized avatar

Barry Rowlingson barryrowlingson

View GitHub Profile
@barryrowlingson
barryrowlingson / abuff.R
Created May 28, 2014 12:37
buffer feature to a fixed percentage area increase
abuff <- function(f, percent, precision, maxsteps = 20){
require(rgeos)
A0 = gArea(f)
targetA = A0 + A0 * (percent/100)
e = bbox(f)
w0 = 0
w2 = diff(e[1,])/10 # initial w
## initial expansion until we pass the solution:
@barryrowlingson
barryrowlingson / dexys.R
Created May 19, 2014 16:32
Hiding mechanics from R plotting for dexy
# You want to show users the code to make a plot.
# BUT you dont want to show them the png() function call you used to make the plot
# for your documentation.
#
# dexy doesn't. You have to open/close the graphics device in your code:
### @export "graph"
png("plot.png")
plot(c(1,2,3), pch=19, col="purple")
dev.off()
# Author: Joona Lehtomäki <[email protected]>
# Updated: 13.11.2011
# Version: 0.0.1
if (!require("rgdal")) {
install.packages("rgdal")
}
if (!require("raster")) {
install.packages("raster")
@barryrowlingson
barryrowlingson / response times by language.sql
Created October 31, 2012 14:11 — forked from guilespi/response times by language.sql
StackOverflow response times by stats packages (and java)
select TagName,
avg(cast(ResponseTime as bigint)) as Average,
stdev(cast(ResponseTime as bigint)) as StandardDev
from
(SELECT
Questions.CreationDate,
Questions.Title,
Tags.TagName,
Answers.CreationDate as ResponseDate,
datediff(minute, Questions.CreationDate,
@barryrowlingson
barryrowlingson / gist:3207893
Created July 30, 2012 15:39
Can you fit a rectangle in a polygon?
require(rgeos)
require(sp)
makeRect <- function(origin, l1, l2, angle){
sa = sin(angle)
ca = cos(angle)
x=origin[1] + c(0,l1*ca,l1*ca-l2*sa,-l2*sa,0)
y=origin[2] + c(0,l1*sa,l1*sa+l2*ca,l2*ca,0)
return(SpatialPolygons(list(Polygons(list(Polygon(cbind(x,y))),"Rectangle"))))
return(cbind(origin[1]+x,origin[2]+y))
@barryrowlingson
barryrowlingson / tach.R
Created June 30, 2012 21:37
Simple mechanism for attaching functions in a single .R file
###
### tach (c) Barry Rowlingson, 2012, pronounced like "tash"
###
### tach("file.R") will source that file into an environment and
### put it on the search path, thus including any function
### definitions without polluting your GlobalEnv
###
### retach() will scan your search path for any tach'ed files and
### if they have been modified since they were loaded they'll be
### re-tached.