Skip to content

Instantly share code, notes, and snippets.

View briatte's full-sized avatar

François Briatte briatte

View GitHub Profile
@briatte
briatte / canny.R
Created August 28, 2017 15:39 — forked from jeroen/canny.R
Magick canny edge detector
library(magrittr)
library(magick)
image_read("logo:") %>%
image_convert('png', colorspace = 'gray') %>%
image_edge(radius = 1) %>%
image_negate() %>%
image_transparent('white', 10000) %>%
image_background("white") %>%
image_browse()
@briatte
briatte / terrorism-in-ukg-1970-2015.R
Created August 23, 2017 14:16 — forked from svmiller/terrorism-in-ukg-1970-2015.R
Model terrorism patterns in the United Kingdom
# You won't need all of these packages. I just copied it from another,related analysis:
# https://github.com/svmiller/etjc
library(car)
library(arm)
library(countrycode)
library(data.table)
library(tidyverse)
library(sqldf)
# library(pdftools)
@briatte
briatte / update.sh
Created August 23, 2017 14:14
generic code to update a git document
#!/bin/bash
cd $(echo $0 | sed 's#/[^/]*$##')
git pull > /tmp/file.tmp 2>&1
./run.sh >> /tmp/load_portes_etroites.tmp 2>&1
if git status | grep "data/" > /dev/null; then
cat /tmp/load_portes_etroites.tmp
@briatte
briatte / opml_dates.r
Created August 15, 2017 13:18
find dead feeds in OPML export (supports Atom and RSS2, will fail to parse on occasions)
library(dplyr)
library(httr)
library(readr)
library(rvest)
d <- read_xml("~/Downloads/digg_reader_subscriptions.xml") %>%
xml_nodes("outline")
d <- data_frame(
title = xml_attr(d, "text"),
url = xml_attr(d, "xmlUrl")
@briatte
briatte / vpt.R
Created August 2, 2017 08:26 — forked from chrishanretty/vpt.R
Replicating Angelova et al., "Veto player theory and reform making in Western Europe"
library(MASS)
library(rio)
library(tidyverse)
multhet <- function(y, ## = formula(1~1),
v, ## = formula(~1),
data) {
## check length of inputs
if (class(y) != "formula") {
@briatte
briatte / NEET-in-Europe.R
Created July 19, 2017 16:40 — forked from ikashnitsky/NEET-in-Europe.R
Young people neither in employment nor in education and training in Europe, 2000-2016
################################################################################
#
# ikashnitsky.github.io 2017-07-18
# Accessing Eurostat data using the `eurostat` R package
# Young people neither in employment nor in education and training in Europe
# Ilya Kashnitsky, ilya.kashnitsky@gmail.com
#
################################################################################
# Erase all objects in memory
@briatte
briatte / congres-afsp-plots.r
Created July 17, 2017 11:23
L'AFSP, un congrès international(isé) ? – https://politbistro.hypotheses.org/5319
library(ggplot2)
library(readr)
d <- read_tsv("data/affiliations.tsv") %>%
filter(j != "2015_STRC20IPSA") %>%
mutate(
y = str_sub(j, 1, 4),
e = str_extract(affiliation, "\\((.*?)\\)") %>%
str_replace_all("\\(|\\)", "")
) %>%
@briatte
briatte / colorcoded-map-population-structures.R
Created July 3, 2017 15:07 — forked from ikashnitsky/colorcoded-map-population-structures.R
Code to reproduce the RGB map of the population structure of NUTS-3 regions of Europe -- https://ikashnitsky.github.io/2017/colorcoded-map/
################################################################################
#
# ikashnitsky.github.io 2017-06-30
# Produce an RGB coded map of pop structures at NUTS-3 level
# Ilya Kashnitsky, ilya.kashnitsky@gmail.com
#
################################################################################
# Erase all objects in memory
rm(list = ls(all = TRUE))
library(dplyr)
# library(igraph)
library(readr)
library(stringr)
library(tidyr)
library(networkD3)
f <- "parcours_selected.tsv"
e <- read_tsv(f, col_types = "ccccccccccccccc") %>%
filter(siteId %in% 3, type == "action") %>%
@briatte
briatte / minority_report.R
Created June 20, 2017 21:16 — forked from chrishanretty/minority_report.R
Get stats on minority government from ParlGov
library(tidyverse)
### Make sure to download files from www.parlgov.org!
elec <- read.csv("view_election.csv")
cab <- read.csv("view_cabinet.csv")
party <- read.csv("view_party.csv")
### Date
cab$start_date <- as.Date(cab$start_date)