Skip to content

Instantly share code, notes, and snippets.

View giocomai's full-sized avatar

Giorgio Comai giocomai

View GitHub Profile
@giocomai
giocomai / explore_zavtra.ru_ru_2024.R
Created April 17, 2024 12:19
Explore zavtra.ru dataset
# https://discuss-data.net/dataset/dae0b5b8-157f-471a-bb3c-ea24e0b2a7f7/
# remotes::install_github("giocomai/castarter")
library("castarter")
corpus_name <- "zavtra.ru_ru_2024"
corpus_file <- paste0(corpus_name, ".csv.gz", collapse = "")
## Step 1: Download the corpus ####
# download `zavtra.ru_ru_2024.csv.gz` from the main repository,
@giocomai
giocomai / oscar_winners_length.R
Created November 15, 2022 09:02
Are movies that win the Oscars really longer than in the past? Nah... (slow at first run, but data are cached locally)
# https://en.wikipedia.org/wiki/List_of_Academy_Award-winning_films
library("dplyr", warn.conflicts = FALSE)
library("tidywikidatar")
library("ggplot2")
# https://github.com/ivelasq/severance
library(severance)
tw_set_language(language = "en")
@giocomai
giocomai / get_meps_9th.R
Last active April 21, 2021 08:34
Get MEPs of the 9th legislature
library("dplyr", warn.conflicts = FALSE) # data wrangling
library("tidywikidatar")
tw_enable_cache()
tw_set_cache_folder(path = fs::path(fs::path_home_r(),
"R",
"tw_data"))
tw_create_cache_folder(ask = FALSE)
@giocomai
giocomai / population grid to kml example.R
Last active November 16, 2020 09:41
population grid to kml example
#remotes::install_github("giocomai/latlon2map")
library("latlon2map")
ll_set_folder(path = "~/R")
library("ggplot2")
library("dplyr")
library("sf")
# recupera griglia di esempio come oggetto sf
if (file.exists("base_grid.rds")==FALSE) {
@giocomai
giocomai / docker-compose_libreoffice.yml
Created June 7, 2020 14:06
Libreoffice Collabora with Traefik / Docker compose (only part with Libreoffice, with `network1` as external network)
libreoffice:
image: libreoffice/online:master
environment:
- "domain=nextcloud\\.example\\.com"
- "SLEEPFORDEBUGGER=0"
- "username=user"
- "password=actualgoodpassword"
- "extra_params=--o:ssl.enable=false --o:ssl.termination=true"
networks:
network1:
@giocomai
giocomai / sibiu_1934_map.Rmd
Created January 22, 2020 20:31
Create sync leaflet maps from a Geotiff, see https://www.giorgiocomai.eu/testzone/sibiu1934/
---
title: "Sibiu 1934 historic map"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library("tidyverse")
library("leaflet")
library("leaflet.opacity")
@giocomai
giocomai / cartograms_italy_leftovers.Rmd
Last active June 9, 2019 11:38
Unsuccesful or partly successful attempts removed from a post on cartograms and EU elections in Italy
```{r eval = FALSE}
partito_facet_tm <- carto_partiti_combo %>%
tm_shape() +
tm_polygons(col = "perc",
palette = "YlGnBu") +
@giocomai
giocomai / Nations_in_transit_animated.R
Last active March 24, 2019 08:44
Nations in transit animated line chart
if (!require("pacman")) install.packages("pacman")
pacman::p_load("tidyverse")
pacman::p_load("gganimate")
pacman::p_load("gifski")
nit <- tibble::tribble(
~Country, ~`2001`, ~`2002`, ~`2003`, ~`2004`, ~`2005`, ~`2006`, ~`2007`, ~`2008`, ~`2009`, ~`2010`, ~`2011`, ~`2012`, ~`2013`, ~`2014`, ~`2015`, ~`2016`, ~`2017`, ~`2018`,
"Albania", 4.42, 4.25, 4.17, 4.13, 4.04, 3.79, 3.82, 3.82, 3.82, 3.93, 4.04, 4.14, 4.25, 4.18, 4.14, 4.14, 4.14, 4.11,
"Bosnia Herzegovina", 5.17, 4.83, 4.54, 4.29, 4.18, 4.07, 4.04, 4.11, 4.18, 4.25, 4.32, 4.36, 4.39, 4.43, 4.46, 4.5, 4.54, 4.64,
"Bulgaria", 3.42, 3.33, 3.38, 3.25, 3.18, 2.93, 2.89, 2.86, 3.04, 3.04, 3.07, 3.14, 3.18, 3.25, 3.29, 3.25, 3.36, 3.39,
@giocomai
giocomai / extract_armenia_census_2011.R
Created December 22, 2018 23:16
Extracts Armenia 2011 census data for all settlements from pdf file issued by Armenia's statistical office
library("tabulizer")
library("tidyverse")
dir.create("data", showWarnings = FALSE)
dir.create(file.path("data", "original_files"), showWarnings = FALSE)
census_2011_pdf_url <- "https://www.armstat.am/file/article/1._bajin_1_182-311.pdf"
census_2011_pdf_file <- file.path("data", "original_files", "census_2011.pdf")
if (file.exists(census_2011_pdf_file)==FALSE) {
@giocomai
giocomai / datacommons_json_to_csv.R
Last active October 1, 2018 08:26
Convert to csv json from FactChecks and Data Commons.org
if (!require("pacman")) install.packages("pacman")
pacman::p_load("jsonlite")
pacman::p_load("tidyverse")
#https://www.datacommons.org/docs/download.html
text <- readLines(con = "fact_checks_20180502.txt")
text <- stringr::str_remove_all(string = text, pattern = stringr::fixed('<script type=\"application/ld+json\">'))
text <- stringr::str_remove_all(string = text, pattern = stringr::fixed("</script>"))
txtList <- purrr::map(.x = text, .f = fromJSON, simplifyDataFrame = TRUE, flatten = TRUE)