Skip to content

Instantly share code, notes, and snippets.

View mhkeller's full-sized avatar

Michael Keller mhkeller

View GitHub Profile
P012030
P012031
P012032
P012033
P012034
P012035
P012036
P012037
P012038
http://harvester.census.gov/sac/dissem/accessoptions.html?submit=Go+To+Database
@mhkeller
mhkeller / Replace NAs with 0s
Created October 16, 2012 03:12
Replace NAs with 0s
df[is.na(df)] <- 0
@mhkeller
mhkeller / gist:3907278
Created October 17, 2012 18:37
Count points intersecting with polygons in PostGIS
UPDATE poly_table SET count_col = (SELECT count(*) FROM points_table WHERE ST_Intersects(points_table.the_geom, poly_table.the_geom))
@mhkeller
mhkeller / gist:3950280
Created October 25, 2012 03:37
google maps geocoding function
var geoCode = function(address){
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var lat = results[0].geometry.location.lat();
var lng = results[0].geometry.location.lng();
var latLng = new L.LatLng(lat, lng);
map.panTo(latLng);
// Set the zoom to whatever you want.
// the higher the number the greater the zoom.
map.setZoom(8);
@mhkeller
mhkeller / gist:3965805
Created October 27, 2012 19:33
R T-shirt ideas
I hear that your strings are factors
FALSE
csv soundsystem bookclub
read.csv()
csv soundsystem publishing house
write.csv()
@mhkeller
mhkeller / gist:3975177
Created October 29, 2012 17:48
sum columns with apply
apply(df[,c("col1","col2")], 1, sum)
@mhkeller
mhkeller / gist:3994581
Created November 1, 2012 16:03
Polygon labels in CartoDB / Tilemill Carto
via @andrewxhill
#your_table_name::text_style {
text-face-name:"DejaVu Sans Book";
text-name:"[name]";
text-fill:#FFF;
text-halo-fill:rgba(0,0,0,0.5);
text-halo-radius:1;
text-size:11;
text-allow-overlap: false;
@mhkeller
mhkeller / assignColors.R
Created November 2, 2012 19:12 — forked from abelsonlive/assignColors.R
assignColors.R
# this function takes an input numeric vector and
# partitions it into a set number of breaks
# it then assigns a color to each break via RColorBrewer
assignColors <- function(var,
n = 9, # number of colors / breaks
style = "jenks", # can be changed to other methods in "classIntervals"
pal = "RdYlBu", # Palettes from RColorBrewer
na_color ='#787878', # Color to give NA's
na_omit = FALSE, # Logical, argument above will be irrelevant if TRUE
@mhkeller
mhkeller / gist:4060805
Created November 12, 2012 17:46 — forked from jatorre/gist:3892665
How to do many updates in a single query WAY faster
UPDATE counties_results o SET pres_dem_pct = n.pres_dem_pct, pres_gop_pct = n.pres_gop_pct,
pres_oth_pct = n.pres_oth_pct, pres_pctrpt = n.pres_pctrpt
FROM ( VALUES
(48.51, 39.69, 11.8, 100, 'AK', '02000'),
(51.65, 41.67, 6.68, 100 , 'AL' , '01001' ),
(52.14, 42.4, 5.46, 100 , 'AL' , '01003' ),
(51.94, 42.24, 5.82, 100 , 'AL' , '01005' ),
(60.28, 34.95, 4.76, 100 , 'AL' , '01007' ),
(53.19, 42.04, 4.77, 100 , 'AL' , '01009' ),
(45.07, 50.85, 4.08, 100 , 'AL' , '01011' ),