Skip to content

Instantly share code, notes, and snippets.

View briatte's full-sized avatar

François Briatte briatte

View GitHub Profile
clear
input str500 x
"-73.974651 40.73868,-73.973391 40.73897,-73.97323 40.73955,-73.97298 40.7415304,-73.97247 40.7423406,-73.97229 40.7428504,-73.97213 40.74338,-73.971871 40.7440804,-73.97141 40.7446706,-73.97103 40.7455605,-73.970301 40.7465204,-73.96929 40.7472"
"-73.970301 40.7465204,-73.96929 40.7472"
end
// keep only the first pair of coordinates
replace x = regexr(x, ",.*", "")
// split by space, converting to numeric
@briatte
briatte / label_facets_ggplot2.R
Created January 9, 2019 01:57 — forked from padpadpadpad/label_facets_ggplot2.R
function to label facets with letters in ggplot2
# load package
library(ggplot2)
# write function
label_facets <- function(string){
len <- length(string)
string = paste('(', letters[1:len], ') ', string, sep = '')
return(string)
}
@briatte
briatte / mathjax.html
Created January 7, 2019 19:28
MathJax <head> content for https://f.briatte.org/r
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-AMS_HTML" async></script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}
});
</script>
@briatte
briatte / yt.sh
Created December 10, 2017 17:51
single-line shell commands to download MP4 or MP3 from Youtube
# MP4
# requirements:
# brew install youtube-dl
# usage: yt-mp4 <youtube-URL>
alias yt-mp4="youtube-dl -f 'best[height=720]'"
# MP3
# requirements:
@briatte
briatte / userChrome.css
Created November 18, 2017 09:47 — forked from johngruen/userChrome.css
kill drag space
/*
Create a userChrome.css file by finding your Firefox profile,
making a directory called chrome and in it, a file called userChrome.css inside that.
Pasting this CSS and restarting Firefox will kill the left drag strip
*/
@namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");
.titlebar-placeholder[type="pre-tabs"] {
width: 2px !important;
@briatte
briatte / 00_survey_data_README.md
Last active January 2, 2019 02:45
A few snippets to quickly get a selection of social science datasets into R.

Here are little chunks of R code to quickly access survey datasets. Some of the linked datasets are provided on an "as-is" basis: typically, you might want to check the official ANES files rather than rely on the extracts linked to below. This also applies to data extracts bundled in packages.

HOWTO

The code occasionally calls the download and foreign packages, respectively to get files from HTTPS sources and to deal with foreign formats. The Gelman and Hill replication also uses plyr and ggplot2, but check the original code for identical functions written in base R.

SEEALSO

---
title: "World maps"
output:
html_document:
df_print: paged
---
```{r echo = FALSE, message = FALSE}
library(tidyverse)
library(sf)
@briatte
briatte / frculture.py
Last active November 5, 2018 18:48
Python 3 code to archive franceculture.com radio shows as "YYYY-MM-DD-FRCULTURE-[Show] - [Title].mp3" files; usage: frculture <URL>. Only one URL at a time for now, and no progress bar, but downloads are usually very quick.
# !/usr/local/bin/python3
# coding: utf8
from bs4 import BeautifulSoup # pip install BeautifulSoup4
import os
import re
import sys
import urllib.request
u = sys.argv[1]
library(dplyr)
library(rvest)
library(network)
library(sna)
library(ggnetwork)
library(wesanderson)
loc = structure(list(country = c("Austria", "Austria", "Austria", "Austria",
"Austria", "Austria", "Austria", "Austria", "Austria", "Austria",
"Austria", "Austria", "Austria", "Austria", "Austria", "Austria",
"Austria", "Austria", "Austria", "Austria", "Austria", "Austria",
"Austria", "Austria", "Austria", "Austria", "Austria", "Austria",
"Austria", "Austria", "Austria", "Austria", "Austria", "Austria",
"Austria", "Austria", "Austria", "Austria", "Austria", "Austria",
"Austria", "Austria", "Austria", "Austria", "Austria", "Austria",
"Austria", "Austria", "Belgium", "Belgium", "Belgium", "Belgium",
"Belgium", "Belgium", "Belgium", "Belgium", "Belgium", "Belgium",