Skip to content

Instantly share code, notes, and snippets.

View jnolis's full-sized avatar
💖

Jacqueline Nolis jnolis

💖
View GitHub Profile
@jnolis
jnolis / ds9_chart.R
Created January 25, 2021 15:56
Creating a Star Trek: Deep Space Nine Netflix analytics plot in R
# Creating a Star Trek: Deep Space Nine Netflix analytics plot in R
#
# FONT SETUP INSTRUCTIONS
# Before running this you'll need to go to this website,
# download the Context Ultra Condensed font, then install it to your system.
# https://www.st-minutiae.com/resources/fonts/index.html
#
# You'll need to register the font by running extrafont::font_import().
# I found that I had to manually import the ttf file--it wasn't picked up by reading the default
# directory. Instead I did running
library(shiny)
library(jsonlite)
# we'll store received data in a local json file
write_json(list(), "data.json")
post_handler <- function(req, response) {
# we'll catch everything that's POST for this demo but you'll want to make
# sure you don't step on shiny's built-in POST handlers
# (I'm pretty sure this handler is called after shiny's handlers but :shrug:)
library(shiny)
library(jsonlite)
# we'll store received data in a local json file
write_json(list(), "data.json")
post_handler <- function(req, response) {
# we'll catch everything that's POST for this demo but you'll want to make
# sure you don't step on shiny's built-in POST handlers
# (I'm pretty sure this handler is called after shiny's handlers but :shrug:)
@jnolis
jnolis / get_sunrise_sunset.R
Created March 17, 2021 16:12
Get the sunrise and sunset times for one location on one day
get_sunrise_sunset <- function(lat,long, date, tz){
# tz is required to know when daylight savings happens
response <- httr::GET(glue::glue("https://api.sunrise-sunset.org/json?lat={lat}&lng={long}&date={date}&formatted=0"))
results <- httr::content(response)$results
results[["day_length"]] <- NULL
results <- lapply(results, function(x) as.POSIXct(x,format="%Y-%m-%dT%T",tz="UTC"))
results <- lapply(results, function(x) lubridate::with_tz(x, tzone = tz))
results
}
@jnolis
jnolis / wrxcars.csv
Last active May 28, 2021 05:00
wrxcars
name mpg cyl disp hp drat wt qsec vs am gear carb
2021 WRX 23 4 122 268 NA 3.341 14 1 1 6 0
2021 WRX STI 19 4 150 305 NA 3.451 14.2 1 1 6 0
2018 WRX 23 4 122 268 NA 3.269 14 1 0 NA 0
2017 WRX Premium 23 4 122 268 NA 3.34 14 1 0 NA 0
2015 WRX 24 4 122 268 NA 3.267 14 1 1 6 0
2013 WRX Hatchback 21 4 150 265 NA 3.208 13.9 1 1 5 0
2009 WRX Premium 21 4 150 265 NA 3.142 13.9 1 1 5 0
library(tidyverse)
library(jsonlite)
x <- tribble(
~name, ~city, ~age,
"Heather", "Renton", 31,
"Jacqueline", "Issaquah", 34
)
# BAD WAY
@jnolis
jnolis / example_furrr
Created June 30, 2021 04:11
group_split + furrr::map_dfr()
library(furrr)
library(dplyr)
future::plan(future::multisession()) # This is for windows, might want something else for Linux
data <- data.frame(letter = sample(letters,num_samples, replace = TRUE),
value = runif(num_samples))
data %>%
group_by(letter) %>%
{
"name": "embed-recipe-site",
"image_uri": "saturncloud/saturn-r:2021.11.10-2",
"description": "A simple website with R and Shiny for embedding recipe links",
"environment_variables": {},
"working_directory": "/home/jovyan/git-repos/embed-recipes-site",
"extra_packages": {
"use_mamba": true,
"conda": "",
"apt": "libv8-dev",
@jnolis
jnolis / advent_of_code_2021_day_7.R
Created December 7, 2021 05:53
Advent of Code 2021 Day 7
library(tidyverse)
data <-
read_lines("07/input.txt") %>%
str_split(",") %>%
.[[1]] %>%
as.integer()
# part 1
# the optimal location to meet is exactly the median (think L1 space if you're mathy)
{
"name": "nvidia-reporting-test",
"image_uri": "saturncloud/saturn-r:2021.11.10-2",
"description": "",
"environment_variables": {},
"working_directory": "/home/jovyan/git-repos/nvidia-reporting",
"extra_packages": {
"apt": "unixodbc unixodbc-dev",
"conda": "",
"pip": "",