Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ellisvalentiner
ellisvalentiner / google maps geocoder.R
Last active September 21, 2016 02:07
Basic format for Google Maps geocoder API
library(httr)
baseurl = "https://maps.googleapis.com/maps/api/geocode/json"
res <- GET(baseurl, query=list(address = "1600 Amphitheatre Parkway, Mountain View, CA", key = Sys.getenv("GOOGLE_MAPS_KEY")))
content(res)$results[[1]]$address_components[[7]]$short_name
lat = content(res)$results[[1]]$geometry$location$lat
lng = content(res)$results[[1]]$geometry$location$lng
library(httr)
baseurl = "https://api.darksky.net/forecast"
url = sprintf("%1$s/%2$s/%3$s/%4$s", baseurl, Sys.getenv("DARKSKY_API_KEY"), lat, lng)
resp = GET(url)
content(resp)
@ellisvalentiner
ellisvalentiner / geocodeZipcode.jl
Created October 10, 2016 19:33
Function to geocode a zip code using Google's maps API
using Requests
function geocodeZipcode(zipcode)
resp = Requests.get("http://maps.googleapis.com/maps/api/geocode/json?address=$zipcode")
return(Requests.json(resp))
end
export PROJECT_PATH=/path/to/project
docker-machine create --driver virtualbox default
docker-machine start
eval $(docker-machine env)
docker run -it --volume=$PROJECT_PATH --memory=4g --memory-swap=4g --entrypoint=/bin/bash rocker/r-base
library(rvest)
library(dplyr)
library(tidyr)
library(readr)
library(jsonlite)
library(lubridate)
### Begin scrape ###
polls <- xml2::read_html("http://projects.fivethirtyeight.com/2016-election-forecast/national-polls/") %>%
rvest::html_nodes(xpath = "//script[contains(., 'race.model')]") %>%
screen /dev/tty.usbmodem1421 115200
@ellisvalentiner
ellisvalentiner / # qgis - 2016-11-21_09-29-26.txt
Created November 21, 2016 14:40
qgis (homebrew/science/qgis) on macOS 10.11.6 - Homebrew build logs
Homebrew build logs for homebrew/science/qgis on macOS 10.11.6
Build date: 2016-11-21 09:29:26
#!/usr/bin/env bash
# Notes:
# - tsort requires as input a stream of pairs (a, b) where package a depends
# on package b. If package a has k > 1 dependencies, we should have k lines
# associated to it; if package a has no dependencies, then we should have a
# single line (a, a). The pairs are just space delimited, no parentheses.
# the little awk program below formats the data that way for tsort.
# - tsort outputs the order from bottom to top; that's why we need to reverse
# it with tail -r.
@ellisvalentiner
ellisvalentiner / read_dir.R
Created February 6, 2017 20:09
Read all CSV files in a directory and return as a tibble. (Who knows how this might fail)
library(tidyverse)
all_df <- list.files("./data", full.names = TRUE) %>%
map_df(., read_csv)
library(purrr)
library(dplyr)
library(tidyr)
deps <- readLines("~/Desktop/deps.txt")
df <- deps %>%
map(strsplit, split=": ") %>%
flatten %>% map_if(~length(.x) == 1L, ~c(.x, NA)) %>%
do.call(rbind.data.frame, .)
colnames(df) <- c("pkg", "dep")