Skip to content

Instantly share code, notes, and snippets.

🐢

Ben Torvaney Torvaney

🐢
View GitHub Profile
View ggsoccer-reprex.md
library(ggplot2)
library(ggsoccer)

pitch_custom_circle <- list(
  length = 106,
  width = 68,
  penalty_box_length = 16.5,
  penalty_box_width = 40.32,
  six_yard_box_length = 5.5,
View maybe.py
class Just:
def __init__(self, value):
self.value = value
def __repr__(self):
return f'Just({self.value.__repr__()})'
def __eq__(self, other):
if isinstance(other, Just):
return self.value == other.value
View fizzbuzz.py
FIZZBUZZ_SPEC = {
3: 'fizz',
5: 'buzz'
}
def fizzbuzz_item(x, spec=FIZZBUZZ_SPEC):
return ''.join(v for k, v in spec.items() if (x % k) == 0) or str(x)
@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)
}
You can’t perform that action at this time.