Skip to content

Instantly share code, notes, and snippets.

Ben Torvaney Torvaney

Block or report user

Report or block Torvaney

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@Torvaney
Torvaney / simple-rng.R
Last active Jul 2, 2019
Create uniform distribution from non-uniform distribution
View simple-rng.R
library(tidyverse)
answers <-
read_csv("https://git.io/fjoZ2") %>%
mutate(rounded = round(pick_a_random_number_from_1_10)) %>%
filter(!is.na(rounded))
modulo_rng <- function(n, data) {
data %>%
@Torvaney
Torvaney / concentration.py
Last active Apr 4, 2019
Why did I do this?
View concentration.py
'''
How many turns does it take to complete a game of Concentration?
https://en.wikipedia.org/wiki/Concentration_(game)
With perfect memory and strategy, for a game of n pairs, this converges to
(approximately) 1.61n moves.
https://www.jstor.org/stable/10.4169/amer.math.monthly.120.09.787
What about with imperfect memory?
'''
@Torvaney
Torvaney / calendar.R
Last active Mar 12, 2019
Make a circular calendar in ggplot2
View calendar.R
library(tidyverse)
year <- 2019
start_date <- lubridate::date(str_glue("{year}-01-01")) # there must be a better way??
month_colours <- c(
"January" = "#a5cdff",
"February" = "#c9e1ff",
"March" = "#b2edb6",
@Torvaney
Torvaney / zagreba-metodo.py
Created Nov 8, 2018
Download images of la angla zagreba metodo textbook
View zagreba-metodo.py
import os
import urllib.request
import bs4
import progressbar
import requests
URL = 'http://esperantofre.com/zagreb/zagreba.htm'
IMG_DIR = os.path.join(os.path.dirname(__file__), 'zagreba-metodo')
View birthday_problem.R
library(tidyverse)
# https://math.stackexchange.com/questions/35791/birthday-problem-expected-number-of-collisions
exp_collisions <- function(n, d) {
n * (1 - (1 - (1 / d)) ^ (n - 1))
}
tibble(n = 1:80) %>%
mutate(collisions = exp_collisions(n, 365)) %>%
ggplot(aes(x = n, y = collisions)) +
View workdays.R
library(tidyverse)
library(rvest)
url <- "https://en.wikipedia.org/wiki/List_of_minimum_annual_leave_by_country"
clean_colnames <-
. %>%
str_to_lower() %>%
str_remove_all("\\[.*\\]") %>%
str_remove_all("\\(.*\\)") %>%
View bertrands-paradox
suppressPackageStartupMessages({
library(tidyverse)
library(sf)
})
# c.f. http://web.mit.edu/tee/www/bertrand/problem.html
chord_length <- function(theta) {
2 * sin(theta / 2)
}
@Torvaney
Torvaney / classifier-agreement-bounds.R
Created Jul 20, 2018
Bounds on classifier error given disagreement rate
View classifier-agreement-bounds.R
lower_bound <- function(d) {
(1 - sqrt(1 - 2*d)) / 2
}
upper_bound <- function(d) {
(1 + sqrt(1 - 2*d)) / 2
}
tibble(d = seq(0, 0.5, 0.001),
lower = lower_bound(d),
View to_clipboard.R
to_clipboard <- function(data) {
clip <- pipe("pbcopy", "w")
write.table(data, file = clip, row.names = FALSE)
close(clip)
}
View dixoncoles-benchmarks.R
benchmark <-
games %>%
mutate(
outcome = case_when(
hgoals > agoals ~ "home_win",
agoals > hgoals ~ "away_win",
hgoals == agoals ~ "draw"
)
) %>%
count(outcome) %>%
You can’t perform that action at this time.