Skip to content

Instantly share code, notes, and snippets.

View giocomai's full-sized avatar

Giorgio Comai giocomai

View GitHub Profile
@giocomai
giocomai / install_luminance.sh
Last active February 26, 2019 11:53
Script for installing craigcabrey's luminance - A Philips Hue client for Linux written in Python and GTK+ - on Fedora 24
git clone git@github.com:craigcabrey/luminance.git
cd luminance
pip3 install requests
pip3 install netdisco
sudo dnf install gsettings-desktop-schemas gsettings-desktop-schemas-devel pygobject3-devel gtk3-devel
sudo pip3 install phue
./autogen.sh
./configure
@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)
@giocomai
giocomai / Words disappearing from SOTEU animated.R
Last active September 12, 2018 15:18
Words disappearing from SOTEU animated
# load libraries
library("gganimate")
library("tidyverse")
# introduce data
structure(list(id = c("Barroso\n2010", "Barroso\n2010", "Barroso\n2010",
"Barroso\n2011", "Barroso\n2011", "Barroso\n2011", "Barroso\n2012",
"Barroso\n2012", "Barroso\n2012", "Barroso\n2013", "Barroso\n2013",
@giocomai
giocomai / fertility_age_eurostat.Rmd
Created August 7, 2018 20:01
Replicate NY times birth-age gap with Eurostat data
---
title: "Birth age gap"
author: "Giorgio Comai"
date: "7 August 2018"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
@giocomai
giocomai / udunits in Fedora.R
Created June 14, 2017 15:03
install udunits2 for R in Fedora
# sudo dnf install udunits2 udunits2-devel
install.packages("udunits2", configure.args = c(udunits2 = '--with-udunits2-include=/usr/include/udunits2'))
library("geofacet")
library("ggplot2")
library("tidyverse")
library("scales")
library("readxl")
# dati ripuliti: https://data.world/sapomnia/elezioni-2018/workspace/file?filename=Risultati%20elezioni%20camera%202018%20livello%20comunale.xlsx
# basato su: https://github.com/ondata/elezionipolitiche2018
comune <- readxl::read_excel("Risultati elezioni camera 2018 livello comunale.xlsx")
@giocomai
giocomai / Exploring Putin’s annual news conference.Rmd
Created December 15, 2017 13:38
Exploring Putin’s annual news conference 2017
---
title: "Exploring Putin's annual news conference"
author: "Giorgio Comai"
date: '2017-12-15'
---
```{r setup, include=FALSE, echo=TRUE, message=FALSE}
knitr::opts_chunk$set(echo = FALSE, message = FALSE, warning = FALSE)
@giocomai
giocomai / MEPsOnTwitter_rtweet.R
Last active October 19, 2017 14:36
Extract the full twitter history of all current members of the European Parliament with R (rtweet) #rstats
if (!require("pacman")) install.packages("pacman") # for taking care of package installation/loading
pacman::p_load("tidyverse")
pacman::p_load("ROAuth")
pacman::p_load("rtweet")
# this assumes authentication has been taken care of as explained here: http://rtweet.info/articles/auth.html
# it should still work, but without access tokens the limits for API requests are much slower (it would take *a lot* longer to get all tweets)
# it is expected that this script will need to be run more than once
# interim files are automatically stored and recovered if the script is re-run
@giocomai
giocomai / 2017-09-19 - EuropeanUnion - EuropeanCommission.R
Last active September 27, 2017 19:03
Extract all press releases, speeches and statements issued by the European Commission with R and castarter
## Install castarter (devtools required for installing from github)
# install.packages("devtools")
devtools::install_github(repo = "giocomai/castarter", ref = "development")
setwd("~/R")
## Load castarter
library("castarter")
## Set project and website name
SetCastarter(project = "EuropeanUnion", website = "EuropeanCommission")