Skip to content

Instantly share code, notes, and snippets.

@GuillaumePressiat
GuillaumePressiat / decoupe_finess_etalab_geocode.py
Last active Sep 8, 2017
Découper le fichier Etalab Finess géocodé de data.gouv.fr
View decoupe_finess_etalab_geocode.py
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# Le fichier est dispo ici : https://www.data.gouv.fr/fr/datasets/finess-extraction-du-fichier-des-etablissements/
import os
os.chdir('..\\..\\')
print ('----------------- Découper Géocodage et structureET Etalab ---------------')
@GuillaumePressiat
GuillaumePressiat / xml_to_df.R
Created Feb 20, 2018 — forked from nacnudus/xml_to_df.R
Convert xml to a nested data frame
View xml_to_df.R
``` r
library(xml2)
library(dplyr)
library(purrr)
library(stringr)
# From the root node:
# If has_children, then recurse.
# Otherwise, attributes, value and children (nested) to data frame.
@GuillaumePressiat
GuillaumePressiat / love_verse.R
Created Mar 24, 2019
Strength of a Lennon song exposed with R function glue::glue
View love_verse.R
library(stringfix)
library(magrittr)
one <- c('love', 'is', 'real')
(one %c% ' ') %,% (rev(one) %c% ' ')
love_verse <- function(w1, w2, w3){
glue::glue(
"Love is {b}, {b} is love
@GuillaumePressiat
GuillaumePressiat / make_er_file.R
Last active Apr 18, 2019
write .er entity relation Database file with R for erd https://github.com/BurntSushi/erd
View make_er_file.R
library(dplyr, warn.conflicts = FALSE)
con_obj <- odbc::dbConnect(odbc::odbc(), "mydatabase")
liste_tables <- DBI::dbListTables(con_obj) %>% .[grepl('some|filter', .)]
erd_write <- function(tab){
d <- capture.output(glimpse(tbl(con_obj, tab)))
noms <- d %>% stringr::str_extract_all('^\\$ .+\\s*\\<') %>%
@GuillaumePressiat
GuillaumePressiat / fix_exfat_drive.md
Created Jan 10, 2020 — forked from scottopell/fix_exfat_drive.md
Fix corrupted exFAT disk macOS/OSX
View fix_exfat_drive.md

exFAT support on macOS seems to have some bugs because my external drives with exFAT formatting will randomly get corrupted.

Disk Utility is unable to repair this at first, but the fix is this:

  1. Use diskutil list to find the right drive id.
  2. You want the id under the IDENTIFIER column, it should look like disk1s1
  3. Run sudo fsck_exfat -d <id from above>. eg sudo fsck_exfat -d disk1s3
  4. -d is debug so you'll see all your files output as they're processed.
  5. Answer YES if it gives you the prompt Main boot region needs to be updated. Yes/No?
View covidfrance_shiny.R
library(leaflet)
library(sf)
library(rmapshaper)
library(dplyr, warn.conflicts = FALSE)
library(smoothr)
library(shiny)
u <- httr::GET('https://www.data.gouv.fr/api/1/datasets/5e7e104ace2080d9162b61d8/')
url_search <- httr::content(u)$resources
View install_github_windows.R
install_github_with_proxy <- function(package = "GuillaumePressiat/pmeasyr", proxy_port = "<host>:<port>/", ...){
u <- rstudioapi::askForPassword('User for proxy authentification')
p <- rstudioapi::askForPassword('Password for proxy authentification')
Sys.setenv(ALL_PROXY = paste0("http://", u, ":", p, "@", proxy_port))
remotes::install_github(package, ...)
}
View Paris.R
library(sf)
library(spatstat)
library(sp)
library(maptools)
library(raster)
library(cartography)
library(SpatialPosition)
## import dataset
feat <- sf::st_read("https://gist.githubusercontent.com/rCarto/747164575e3f216a123c3092d0ce9162/raw/f12390464f255b5f9760c577ab6bf5456cf61a40/iris75.geojson")
@GuillaumePressiat
GuillaumePressiat / covid_sidep_sursaud_down.R
Last active Oct 14, 2020
Collecter les csv covid SI-DEP et SURSAUD de SPF depuis data.gouv.fr en interrogeant son api, résultat un fichier excel, ici filtré sur la Bretagne
View covid_sidep_sursaud_down.R
library(dplyr, warn.conflicts = FALSE)
liste_url <- list(
indicateurs = list(url_web = "https://www.data.gouv.fr/fr/datasets/indicateurs-de-suivi-de-lepidemie-de-covid-19/",
url_stable = "https://www.data.gouv.fr/fr/datasets/r/4acad602-d8b1-4516-bc71-7d5574d5f33e",
url_api = "https://www.data.gouv.fr/api/1/datasets/5ee9df5003284f565d561278/",
titre = "Indicateurs de suivi de l’épidémie de COVID-19",
# file_pattern = "indicateurs-covid19-dep",
file_pattern = "indicateurs-open-data-dep",
delim = ",",
@GuillaumePressiat
GuillaumePressiat / municipales_lecture_data_.R
Created Feb 18, 2021
Lire et passer fichier data.gouv ministère intérieur commune > 1000 hab. 1er tour
View municipales_lecture_data_.R
library(readr)
library(dplyr)
# 1er tour
# https://www.data.gouv.fr/fr/datasets/elections-municipales-2020-resultats-1er-tour/#_
u <- read_tsv('~/Downloads/2020-05-18-resultats-communes-de-1000-et-plus.txt',
locale = locale(encoding = "latin1"),
col_types = cols(
.default = col_character(),
`Code du département` = col_double(),