Skip to content

Instantly share code, notes, and snippets.

@cavedave
cavedave / slope.html
Last active February 6, 2024 08:57
A slope graph of Irish election results by political party
<!DOCTYPE html>
<!-- paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/ -->
<!--[if lt IE 7 ]> <html lang="en" class="no-js ie6"> <![endif]-->
<!--[if IE 7 ]> <html lang="en" class="no-js ie7"> <![endif]-->
<!--[if IE 8 ]> <html lang="en" class="no-js ie8"> <![endif]-->
<!--[if IE 9 ]> <html lang="en" class="no-js ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <html lang="en" class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
@cavedave
cavedave / dictionary_bat.txt
Last active December 28, 2023 18:03
MAke map of etymology of the word bat in european languages. Code from Most names gotten from here https://www.reddit.com/media?url=https%3A%2F%2Fi.redd.it%2Fapnha37a0fk51.jpg Some gotten from wiktionary https://en.wiktionary.org/wiki/yarasa code a slightly modified version of https://github.com/dd52/mapMakeR/tree/master/etymologyMaps I am sure …
abk, ?, grey
ara, day blind, lightyellow
aze, night bird, orange
bel, leather one, turquoise
bos, blind mouse, lightgreen
bre, blind mouse, lightblue
bul, sticking one, blue
cat, winged rat, yellow
cau, ?, grey
ces, night flyer, lightgreen
@cavedave
cavedave / heapslaw.py
Created October 21, 2023 18:35
heaps law graph to draw
import matplotlib.pyplot as plt
unique = []
check = []
k = 50 #These need to be estimated for particular languages but this is a base estimate
b=0.4 #
for x in range(1, 100000, 100):
unique.append(k*(x**b))
check.append(x)
@cavedave
cavedave / parseCroidhePdf.py
Created August 12, 2023 16:39
Code to parse a pdf of the only Irish-Irish dictionary of the 20th century. Croidhe Cainnte Chiarraighe. Foclóir Gaeilge-Gaeilge (pdf) 1942. PDF is at https://www.forasnagaeilge.ie/wp-content/uploads/2016/06/8fddae92ae307b022d964ebe73d45df6.pdf . I took a few pages using https://smallpdf.com/split-pdf to speed up experiments but that can be done…
import pdfplumber
def is_bold_font(char):
return "bold" in char['fontname'].lower()
def parse_pdf_to_dictionary(pdf_path):
term_definition_dict = {}
term = ""
next_term = ""
definition = ""
@cavedave
cavedave / EuclidTrans.csv
Last active September 27, 2022 22:38
Graph of Euclid translations. That shows when they were translated. Data from wikipedia https://en.wikipedia.org/wiki/Euclid%27s_Elements#Translations
Year Language taxis iso
1505 Latin 1 va
1543 Italian 1 it
1557 Latin 1 va
1558 German 1 de
1562 German 1 de
1562 German 1 de
1564 French 1 fr
1570 English 1 gb
1572 Latin 1 va
objects <-c('Truman','Eisenhower','Kennedy','Johnson','Nixon','Ford','Carter','Reagan','Bush','Clinton','G. W. Bush','Obama','Trump','Biden')
#'FDR', 0.796,
performance <- c(0.319,0.165,0.206,0.172,0.170,0.188,0.219,0.130,0.113,0.105,0.099,0.094,0.15,0.165)
color<-c('#0015BC', '#E9141D', '#0015BC', '#0015BC', '#E9141D', '#E9141D', '#0015BC', '#E9141D', '#E9141D', '#0015BC', '#E9141D', '#0015BC','#E9141D','#0015BC')
df<- data.frame(objects, performance, color)
#lock in order
library(ggplot2)
library("ggthemes")
data <- read.csv("winners.csv",header=TRUE)
#Year AverageSpeed
# 1903 25.679
# 1904 25.265
ggplot(data, aes(x=Year, y=AverageSpeed, fill=type)) +
library(dplyr)
library(lubridate)
library(tidyverse)
gridwatch <-
read_csv(
file = "gridwatch.csv")
#get date int data format
@cavedave
cavedave / IrelandTemp2021.r
Created July 17, 2022 10:23
Ridgeline plot (Joyplot) of temperatures at dublin Airport in 2021. Thicker means there were more days with that temperature. Using max temperature as thats how we think of it due to weather forecasts. As in yesterday was 21C means the hottest yesterday got was 21Cget data from https://www.met.ie/climate/available-data/historical-data for Dublin…
get data from https://www.met.ie/climate/available-data/historical-data
for Dublin airport
```{r}
dub<-read_csv('dly532.csv', skip=25, col_names = TRUE)
head(dub)
```
date looks like 01-jan-1942
separate it out into 3 columns
@cavedave
cavedave / age15to64.r
Last active July 10, 2022 13:40
Sex Ratio in Europe based on code from https://jschoeley.github.io/2018/07/03/bubble-grid_vs_choropleth.html Norway has a missing spot in future combine Nord Trøndelag and Sort Trønderlag to fill this out.
library(eurostat) # eurostat data
library(rnaturalearth) # worldwide map data
library(tidyverse) # tidy data transformation
library(lubridate) # date and time support
library(sf) # simple features GIS
library(RColorBrewer)
euro_pop <-
get_eurostat('demo_r_pjanaggr3', stringsAsFactors = FALSE) %>%