Skip to content

Instantly share code, notes, and snippets.

View mdneuzerling's full-sized avatar

David Neuzerling mdneuzerling

View GitHub Profile
@mdneuzerling
mdneuzerling / generate-pokemon-data
Last active July 16, 2023 09:35
Generate Pokémon data with evolution family
# data/pokemon.csv from https://gist.github.com/simsketch/1a029a8d7fca1e4c142cbfd043a68f19
# The last 5 to 10 rows needed to be manually fixed to have the correct number of columns
# data/evolutions-raw.csv is manually scraped from https://pokemon.fandom.com/wiki/List_of_Pok%C3%A9mon_by_evolution
library(tidyverse)
# Terminology note: a "base" of a Pokemon "family" is the unevolved form from
# which other Pokemon in the family come from. For example, Squirtle is the
# base of Wartortle and Blastoise, and these three are members of the "Squirtle"
# family (and possibly Mega Blastoise too)
@mdneuzerling
mdneuzerling / australian_licence_plate_type.py
Created June 14, 2019 05:27
Quick bit of code for determining whether an Australian licence plate is standard or personalised
# Takes a pattern like xxxddd (for three letters followed by three numbers)
# and converts it to regex. Other characters are left as is in the regex
# pattern string. This is helpful for states like SA in which every modern
# licence plate begins with an "S".
def match_plate_pattern(plate, pattern):
pattern = pattern.replace('x','[A-Za-z]').replace('d','[0-9]')
return(re.fullmatch(pattern, plate))
# Some of these rules are a bit more general than they need to be.
# These rules aren't complete (I tended to ignore anything before 1970).
@mdneuzerling
mdneuzerling / tidymodels-in-mlflow.R
Created December 19, 2022 21:08
Tidymodels MLflow R
# This file contains the minimal code needed to set up a tidymodels flavour for
# mlflow, along with unit tests. There are three issues that need to be addressed:
#
# * we currently use workflows:::predict.workflow, which will NOT be accepted by
# CRAN. We should ask that the Tidymodels team make this function available in
# the workflows NAMESPACE.
# * we need to ensure that the Python CLI can support the new R flavour. There is
# a commented-out unit test for this.
# * the unit tests call on packages through `library`, and this could be cleaned up.
library(tidyverse)
modifier <- function(x) {
floor((x - 10) / 2)
}
skill_ability <- tribble(
~skill, ~ability_code_upper,
#-------|------------------
"athletics", "STR",
@mdneuzerling
mdneuzerling / diceroll.jl
Created December 21, 2021 06:40
roll dice in Julia
macro roll(dice)
dice_split = split(string(dice), "d")
dice_split[1] = (dice_split[1] == "" ? "1" : dice_split[1])
n_dice, range = parse.(Int64, dice_split)
:(sum(rand(1:$range, $n_dice)))
end
library(tidyverse)
tidy_tuesday <- tidytuesdayR::tt_load(2020, week = 28)
coffee <- tidy_tuesday$coffee_ratings
coffee %>%
filter(!is.na(country_of_origin)) %>%
inner_join(
coffee %>%
group_by(country_of_origin) %>%
@mdneuzerling
mdneuzerling / ptv_get.R
Last active April 19, 2020 02:10
Example HTTP GET request for accessing the PTV API in R
# This function formulates and submits a HTTP GET request to the Public
# Transport Victoria (PTV) API. In particular, it calculates the "signature"
# component of the URL required for authentication. While I've included the
# version number as an argument, I haven't tested this function on versions
# other than 3.
#
# See URL below for information on obtaining a user ID (also called a devid) and
# an API key:
# https://www.ptv.vic.gov.au/footer/data-and-reporting/datasets/ptv-timetable-api/
#
library(tidyverse)
library(bomrang)
weather <- get_historical(
stationid = "090015",
type = "max"
)
weather %>%
filter(!is.na(Max_temperature)) %>% # remove missing values
@mdneuzerling
mdneuzerling / keybase.md
Created June 19, 2016 01:17
Keybase verification

Keybase proof

I hereby claim:

  • I am mdneuzerling on github.
  • I am mdneuzerling (https://keybase.io/mdneuzerling) on keybase.
  • I have a public key whose fingerprint is B09F 70F9 25C8 6754 D5A0 9746 870E C1FF 97FC EB78

To claim this, I am signing this object: