Skip to content

Instantly share code, notes, and snippets.

View jthomasmock's full-sized avatar

Tom Mock jthomasmock

View GitHub Profile
@samcofer
samcofer / 0-rebuild-cache-information-after-os-upgrade.txt
Last active February 14, 2025 20:05
Update local renv and python cache
#Placeholder to change the name of the gist
library(tidyverse)
library(ggtext)
library(grid)
library(crayon)
title <- "The <b><span style='color:#FF0000'>Sigmoid Function</span></b> and its <b><span style='color:#0000FF'>Derivative</span></b>"
df <- data.frame(x = -5:5)
ggplot(df, aes(x)) +
library(gt)
library(gtExtras)
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
gist_to_carbon <- function(
gist_id,
file = "code.png",
bg = "#4A90E2",
bg_alpha = 1,
theme = "shades-of-purple",
font = "Fira+Code",
lang = "auto",
drop_shadow = TRUE,
width = 680,
@mrcaseb
mrcaseb / gt_table_align_decimal_separator.R
Last active November 11, 2022 20:55
A suggestion how to align a column in a gt table to the decimal separator without monospace fonts
library(magrittr)
df <- tibble::tibble(
var_a = c("a", "b", "c", "d"),
var_b = c(1.234, 12.34, 123.4, 1234)
)
num_to_html <- function(num, separator = ".") {
stringr::str_split_fixed(num, stringr::fixed(separator), n = 2) %>%
as.data.frame() %>%
@nntrn
nntrn / espn-api-list.md
Last active April 27, 2025 17:50
List of nfl api endpoints from espn

List of NFL API Endpoints

This page has been updated a lot in the past 3 years. Older revisions you might like more than this one:

library(tweetrmd)
library(htmltools)
library(reactable)
x <- tibble::tibble(
name = c("Tom", "Julia"),
handle = c("@thomas_mock", "@b0rk"),
tweet = c(
"https://twitter.com/thomas_mock/status/1294670115590545408",
"https://twitter.com/b0rk/status/1295029728127135746"
read_csv("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_19-covid-Confirmed.csv") %>%
gather(date, cases, 5:ncol(.)) %>%
mutate(date = as.Date(date, "%m/%d/%y")) %>%
group_by(country = `Country/Region`, date) %>%
summarise(cases = sum(cases)) %>%
filter(country != "Others" & country != "Mainland China") %>%
bind_rows(
tibble(country = "Republic of Korea", date = as.Date("2020-03-11"), cases = 7755)
) %>%
group_by(country) %>%
@guga31bb
guga31bb / box_score.md
Last active May 16, 2021 22:35
Make pretty box scores

Make box scores with EPA and other stuff

Code below. To get the game you want, need to choose season, type (regular, postseason, etc), home team, away team, and the rest will go on itself.

Code from @benbbaldwin

library(nflscrapR)
library(tidyverse)
library(na.tools)
# Load the packages we’re going to be using:
# Alongside the usual stuff like tidyverse and magrittr, we’ll be using rvest for some web-scraping, jsonline to parse some JSON, and extrafont to load some nice custom fonts
needs(tidyverse, magrittr, rvest, jsonlite, extrafont)
# Before we go on, two things to note:
# First, on web scraping:
# You should always check the terms of the site you are extracting data from, to make sure scraping (often referred to as `crawling`) is not prohibited. One way to do this is to visit the website’s `robots.txt` page, and ensure that a) there is nothing explicitly stating that crawlers are not permitted, and b) ideally, the site simply states that all user agents are permitted (indicated by a line saying `User-Agect: *`). Both of those are the case for our use-case today (see https://www.ultimatetennisstatistics.com/robots.txt).
# And second, about those custom fonts: