Skip to content

Instantly share code, notes, and snippets.

View zross's full-sized avatar

Zev Ross zross

View GitHub Profile
@zross
zross / spatial_example.R
Last active March 19, 2018 14:54
Spatial analysis with R
# An example of spatial analysis with R that involves grabbing data
# from a PostGIS database, joining to tabular data, projecting
# simplifying and creating an interactive map.
# This data is publicly available but requires some processing
# if you want the county boundaries you can find them here:
# cftp://ftp2.census.gov/geo/tiger/TIGER2016/COUNTY/
# The tabular data requires some processing but the raw data
@zross
zross / businesses.json
Last active January 4, 2018 08:11
Leaflet.js Tips, Step 4 (filter geojson markers)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@zross
zross / nested_for_loops.R
Created December 15, 2017 21:31
Testing nested for loops with foreach
# The idea I'm trying to test is if I can nest a parallel
# for loop inside another parallel for loop.
# The following does open up 4 cores with the first loop
# and opens an additional 3 cores with the second. I see
# seven running at one time, the four are turned off then
# 3 are turned off.
# I'm not sure if this is truly 7 parallel cores or if it's
# 4 then 3 sequentially.
@zross
zross / index.html
Last active October 26, 2017 17:46
HTML: Google maps with CartoDB (v3) layer, includes cartoCSS (CA counties)
<!DOCTYPE html>
<html>
<head>
<title>HTML5</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=650, user-scalable=yes">
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
@zross
zross / markdown_style.css
Created September 21, 2017 16:58
markdown_style.css
body{
color:red;
}
@zross
zross / index.html
Created September 19, 2014 17:42
D3, Leaflet animation
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7/leaflet.css" />
<script src="http://d3js.org/d3.v3.min.js" type="text/javascript"></script>
<script src="http://cdn.leafletjs.com/leaflet-0.7/leaflet.js"></script>
<script src='https://api.tiles.mapbox.com/mapbox.js/v1.6.4/mapbox.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox.js/v1.6.4/mapbox.css' rel='stylesheet' />
@zross
zross / index.html
Last active July 13, 2017 04:45
Leaflet.js Tips, Step 1 (boilerplate)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7/leaflet.css" />
<script src="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.js"></script>
<script src='https://api.tiles.mapbox.com/mapbox.js/v1.6.4/mapbox.js'></script>
<style type="text/css">
#map {
width: 600px;
@zross
zross / index.html
Created April 1, 2015 15:05
Simple Leaflet with CartoDB tiles
<!DOCTYPE html>
<html>
<head>
<title>Leaflet GeoJSON Example</title>
<meta charset="utf-8">
<meta content="width=device-width, initial-scale=1.0" name="viewport">
<link href="http://cdn.leafletjs.com/leaflet-0.7/leaflet.css" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script src="http://cdn.leafletjs.com/leaflet-0.7/leaflet.js"></script>
<style>
@zross
zross / sf_dplyr.R
Created April 20, 2017 20:50
quick example of sf with dplyr producing spatial output
library(dplyr)
nc = st_read(system.file("shape/nc.shp", package="sf"))
nc$blah <- sample(c(1,2,3), size = nrow(nc), replace = TRUE)
nc %>% group_by(blah) %>% summarize(avg_bir74 = mean(BIR74))
@zross
zross / index.html
Last active April 17, 2017 05:16
HTML: D3 scatter, data from cartodb
<!DOCTYPE html>
<html>
<head>
<title>HTML5</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=650, user-scalable=yes">
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://libs.cartocdn.com/cartodb.js/v2/cartodb.js">
</script>
<style>