Skip to content

Instantly share code, notes, and snippets.

View BenjaminWolfe's full-sized avatar

Benjamin Wolfe BenjaminWolfe

View GitHub Profile
@BenjaminWolfe
BenjaminWolfe / panel-gridlines-color-vector.R
Last active August 27, 2019 14:18
If you specify a vector of gridline colors, ggplot2 cycles through them
library(tidyverse) # dplyr, stringr, ggplot2
library(lubridate)
#' The `sunspot.month` dataset as a tibble:
sunspots_reshaped <-
tibble(
sunspot_month = sunspot.month %>%
start() %>%
c(1) %>%
paste(collapse = "-") %>%
#' Eureka!
#'
#' Running `devtools::check()` on my Windows laptop,
#' I kept getting the following warning:
#'
#' ```
#' 'qpdf' is needed for checks on size reduction of PDFs
#' ```
#'
#' I downloaded the latest version of `qpdf` from SourceForge,
# hacky but fun code to change the RStudio theme every (e.g.) 15 minutes,
# cycling through the themes in the {rsthemes} package.
# https://gist.github.com/BenjaminWolfe/fc00c480f8a7185779669d2895829069
#
# start is 9am on the day rstudio::conf(2021L) kicks off.
# applies the current theme, then starts a timer to change it periodically.
# to rotate less often (or more), adjust theme_period below.
# (fractional minutes may not work.)
# note that breaks are just based on lubridate::round_date logic.
#
library(tidyverse)
library(slackteams)
library(slackr)
library(lubridate)
library(here)
library(glue)
library(conflicted)
library(fs)
conflict_prefer("filter", "dplyr", "stats" )
# my 15yo's homework today during lockdown
# find an equation for the cooling of a cup of coffee
# with the following temperature measurements
library(tidyverse)
decay_tbl <- tribble(
~time, ~temperature,
0, 179.5,
5, 168.7,
collect_iteratively <- function(x, size = 500, timeout = 3600) {
start_time <- Sys.time()
message("pulling ", size, " records at a time...")
message("starting at ", start_time)
message("will time out at ", start_time + timeout, " (", timeout, "s later)")
con <- x$src$con
sql <- dbplyr::db_sql_render(con, x)
res <- DBI::dbSendQuery(con, sql)
@BenjaminWolfe
BenjaminWolfe / group-and-fill.R
Last active August 11, 2020 16:18
grouping, ordering, and filling in Python and R
# code to be compared to group-and-fill.py
# task: fill specific columns down, within each group, ordering by the order.
library(tidyverse)
df <- tribble(
~group, ~order, ~attribute_1, ~attribute_2, ~irrelevant,
"a", 0, 1, 1, "hello",
"a", 2, NA, 3, NA , # this one out of ordr
"a", 1, 6, NA, "world",
"b", 0, 2, 7, "foo" ,
@BenjaminWolfe
BenjaminWolfe / nested_got_data.R
Last active August 31, 2020 17:30
Nested Game of Thrones Data - Snowflake + R
library(tidyverse)
library(repurrrsive) # game of thromes dataset
library(listviewer) # jsonedit for pretty viewing
jsonedit(got_chars, mode = "view")
really_nested <- tibble(id = 1:30, nested_stuff = got_chars)
really_nested %>%
hoist(

Say you want to access GitLab.com for work (using your work email address), and you also want to access it for personal reasons (using your personal email address), and you want to do both on the same laptop.

Generate two SSH keys and save them in your ~/.ssh directory. I'll call them work_key and personal_key. As always with SSH keys in GitHub or GitLab, you'll want to generate a public key for each and add it to the corresponding GitLab account.

Then point to both private keys in your ~/.ssh/config file: