Skip to content

Instantly share code, notes, and snippets.

View jthomasmock's full-sized avatar

Tom Mock jthomasmock

View GitHub Profile
@jthomasmock
jthomasmock / get_compatible_ext.R
Created October 31, 2024 00:50
Query OpenVSX API for versions of extensions compatible with specific minimum version of Code OSS
library(httr2)
library(semver)
library(glue)
get_compatible_ext <- function(namespace, name, code_version){
url <- glue::glue("https://open-vsx.org/api/{namespace}/{name}/latest")
raw_ext_json <- httr2::request(url) %>%
req_headers(accept = "application/json") %>% req_perform() %>% resp_body_json()
``` r
library(dplyr)
# vector operation
chunk_vec <- function(chunk_size){
ceiling(seq_along(row_number())/chunk_size)
}
# operate on dataframe
chunk_df <- function(.data, chunk_size) {
@jthomasmock
jthomasmock / guess_keyword.R
Created September 13, 2023 01:36
Guess the Keyword of the day with R!
library(tidyverse)
library(jsonlite)
library(shiny)
# get_json_data(date)
# score_letters(letters)
# read_keywords() on mac
# split_char(word) into words
# limit_words(words, str_length) to specific length and lower case
# top_words(word, words_in, top_n = 50) - combo of split_char, limit_words
@jthomasmock
jthomasmock / copilot_keyword.R
Created September 13, 2023 01:35
Solving the Keyword game with R, with a little help from RStudio and Copilot!
library(tidyverse)
library(stringr)
library(jsonlite)
# create a function to solve the Keyword game
# this game uses a 6 letter horizontal word at the
# intersection of 6 other words, where a missing letter from each of the vertical words
# accounts for one letter of the mystery 6 letter length horizontal word
# how to play
@jthomasmock
jthomasmock / keyword-solver.R
Created August 17, 2023 15:15
Provide reasonable solutions to solve the Keyword game from WaPo.
library(tidyverse)
library(jsonlite)
library(shiny)
# get_json_data(date)
# score_letters(letters)
# read_keywords() on mac
# split_char(word) into words
# limit_words(words, str_length) to specific length and lower case
# top_words(word, words_in, top_n = 50) - combo of split_char, limit_words
@jthomasmock
jthomasmock / quarto-temp.sh
Created August 2, 2023 16:04
Take a ipynb from Colab and render
# Colab follows Google Drive style syntax
# so https://colab.research.google.com/drive/1R_G1BEdOSN6RcmNDZSG0vJtxk4rOodN7
# means file id = 1R_G1BEdOSN6RcmNDZSG0vJtxk4rOodN7
# so to download that file, we could use:
#> This would download the file and -O (output) as temp-quarto.ipynb
wget -O temp-quarto.ipynb 'https://docs.google.com/uc?export=download&id=1R_G1BEdOSN6RcmNDZSG0vJtxk4rOodN7'
# we can then pass that to quarto render
quarto render temp-quarto.ipynb --to html
gt_render_reprex <- function(gt_object, imgur = FALSE) {
# create temp file
img_out <- tempfile(fileext = ".png")
# save image to temp
save_obj <- gt::gtsave(gt_object, img_out) %>%
utils::capture.output(type = "message") %>%
invisible()
```{r write-tags}
#| echo: false
library(rvest)
library(xml2)
raw_html <- read_html(here::here("_site/index.html"))
length_tags <- raw_html |>
html_nodes("#quarto-margin-sidebar > div > div") |>
@jthomasmock
jthomasmock / example.qmd
Created November 16, 2022 21:57
Rotating images
---
format: html
---
```{r}
library(ggplot2)
library(grid)
```
```{r}
library(dplyr)
raw_metrics <- espnscrapeR::get_espn_wr_metrics()
raw_metrics |> glimpse()
raw_metrics |>
group_by(gsis_id) |>
summarise(across(c(overall:rtm_targets, yds), mean),
across(ends_with("nm"), unique)) |>