Skip to content

Instantly share code, notes, and snippets.

@jnolis
Last active February 7, 2020 16:48
Show Gist options
  • Save jnolis/d098a5ebc2e3566ba97bccab904e5313 to your computer and use it in GitHub Desktop.
Save jnolis/d098a5ebc2e3566ba97bccab904e5313 to your computer and use it in GitHub Desktop.
Made your RStudio 80's style only after the sun goes down
setHook("rstudio.sessionInit", function(chooseTheme) {
if (chooseTheme) {
lat <- 47.608013
long <- -122.335167
eighties_time <- FALSE
if(is.element("httr",rownames(installed.packages()))){
response <- httr::GET(paste0("https://api.sunrise-sunset.org/json?formatted=0&lat=", lat, "&lng=", long))
if(response$status_code == 200L){
values <- httr::content(response)
format <- "%Y-%m-%dT%H:%M:%S"
sunrise <- as.POSIXct(values$results$sunrise, format = format, tz = "UTC")
sunset <- as.POSIXct(values$results$sunset, format = format, tz = "UTC")
if(Sys.time() < sunrise || sunset < Sys.time()){
eighties_time <- TRUE
}
}
} else {
warning("Please install the package 'httr' to get that sweet 80s theme at night")
}
if (eighties_time) {
if(!is.element("synthwave85",names(rstudioapi::getThemes()))){
rstudioapi::addTheme("https://raw.githubusercontent.com/jnolis/synthwave85/master/Synthwave85.rstheme", FALSE, TRUE, FALSE)
}
if (rstudioapi::getThemeInfo()$editor != "synthwave85") rstudioapi::applyTheme("synthwave85")
} else {
if (rstudioapi::getThemeInfo()$editor != "textmate (default)") rstudioapi::applyTheme("textmate (default)")
}
}
},
action = "replace"
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment