Skip to content

Instantly share code, notes, and snippets.

@ryanscharf
ryanscharf / pain.R
Created June 3, 2023 01:11
union contiguous geometries example
library(tigris)
library(tidyverse)
library(sf)
# get the states
test_states <- tigris::states() %>%
filter(
STUSPS %in% c(
'FL',
'GA',
@ryanscharf
ryanscharf / plot_us.R
Created May 12, 2022 16:01
plot us w/AK& HI
#' Plot US
#'
#' @param spdf sf data frame
#' @param fill_val quoted fill value name
#' @param title plot title
#' @param palette color palette
#' @param ... idk how these work still
#'
#' @return
#' @export
## @y dataframe of coordinates
## @x vector of buffer sizes for cone diameters
coneify <- function(y, x, ref){
points <- y %>% st_as_sf(coords = c('lng', 'lat'), crs = ref)
buffs <- st_buffer(points, points$x)
cone <- st_sf(st_sfc())
for (i in 2:nrow(buffs)) {
tmp <- buffs[(i - 1):i,]
@ryanscharf
ryanscharf / ParseChangePlates.R
Created February 13, 2021 17:49
Parsing change plate stock/availability from a few different providers
library(tidyverse)
library(rvest)
library(jsonlite)
library(janitor)
library(lubridate)
library(httr)
library(htmlTable)
library(mailR)
username = '',
password = ''
wdir <- file.path(tempdir(),"Path_for_downloading_folder")
bbox_ls <- clipping_bbox(-82.758605,27.631232,-82.732227,27.654636)
sres <- lsSearch(startDate = as.Date("01-01-2020", "%d-%m-%Y"),
endDate = as.Date("31-01-2020", "%d-%m-%Y"),
#pathrow = list(c(200, 31), c(200, 30)),
@ryanscharf
ryanscharf / getBeanies.R
Last active March 31, 2020 13:34
getBeanies
library(rvest)
library(tidyverse)
library(curl)
bbdb <- 'http://world.ty.com/catalog/catPagePrint.cfm'
bbnames <-
read_html(curl(bbdb, handle = curl::new_handle("useragent" = "Mozilla/5.0"))) %>%
html_node('table') %>%
html_table()
bbnames <- bbnames[3:nrow(bbnames), 2]
@ryanscharf
ryanscharf / FireCooper.Rmd
Last active November 9, 2021 05:59
Fire Cooper?
---
title: "Fire Coop: A Peek at the Prevalance of Regime Change Discussions on r/tampabaylightning"
output:
html_document:
df_print: paged
code_folding: "hide"
---
First, we'll start by installing Mike Kearney's rreddit package. It's kinda still in development, I guess, but it gets the job done. Some functions from it were either not found or broken, but that may be because I was too lazy to update my version of R from 3.5.0. If you have problems, just throw "mkearney %broken function%" into the ol' Google and you'll be good to go. Below, I have included fixed/usable functions that should fulfill everything needed by the rreddit package.
@ryanscharf
ryanscharf / NHC operational model intensity forecast animation
Last active September 6, 2019 14:56
NHC operational model intensity forecast animation
library(tidyverse)
library(lubridate)
library(gganimate)
library(ggrepel)
library(ggthemes)
NHCintensityModels <- c('FSSE', 'HCCA','GFEX','RVCN','ICON','IVCN','NVGM','NVGI','AVNO','AVNI','GFSO','GFSI','EMX','EMXI','EMX2','EGRR','EGRI','EGR2','CMC','CMCI','HWRF','HWFI','CTCX','CTCI','HMON','HMNI','CLP5','SHF5','DSF5','TCLP','SHIP','DSHP','LGEM')
P <-
daATCF %>% mutate(datee = ymd(paste0(Year, Month, Day))) %>% filter(
Hour == '00' &
@ryanscharf
ryanscharf / wordpress-wjt-httr.R
Created July 20, 2019 21:56 — forked from kalendar/wordpress-wjt-httr.R
Publishing to the Wordpress REST API from R with JSON Web Tokens and httr
library(httr)
# Get the JWT
get_jwt <- POST("https://example.com/throwaway/wp-json/jwt-auth/v1/token",
query = list(username = "your_username", password = "your_password"))
token <- content(get_jwt)$token
# Confirm auth is working
test <- POST("https://example.com/throwaway/wp-json/jwt-auth/v1/token/validate",
add_headers('Authorization' = paste("Bearer", token, sep = " ")), encode = "json")