Skip to content

Instantly share code, notes, and snippets.

Avatar

François Briatte briatte

View GitHub Profile
@briatte
briatte / label_facets_ggplot2.R
Created Jan 9, 2019 — forked from padpadpadpad/label_facets_ggplot2.R
function to label facets with letters in ggplot2
View label_facets_ggplot2.R
# load package
library(ggplot2)
# write function
label_facets <- function(string){
len <- length(string)
string = paste('(', letters[1:len], ') ', string, sep = '')
return(string)
}
View mathjax.html
<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 / .htaccess
Created Jan 6, 2019
Show RSS feeds on a Web page via pure JavaScript, incl. code to bypass Chrome's CORS policy.
View .htaccess
# enable CORS policy
# https://gist.github.com/maxparm/3105526
<IfModule mod_rewrite.c>
Header add Access-Control-Allow-Origin "*"
Header add Access-Control-Allow-Methods: "GET,POST,OPTIONS,DELETE,PUT"
Header add Access-Control-Allow-Headers: "Content-Type"
RewriteEngine on
RewriteBase /
</IfModule>
View world_maps.Rmd
---
title: "World maps"
output:
html_document:
df_print: paged
---
```{r echo = FALSE, message = FALSE}
library(tidyverse)
library(sf)
@briatte
briatte / frculture.py
Last active Nov 5, 2018
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.
View frculture.py
# !/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]
View scrape-tidy-presidency-project-approval-data.R
library(rvest)
library(lubridate)
library(tidyverse)
Truman <- read_html("http://www.presidency.ucsb.edu/data/popularity.php?pres=33")
Truman %>%
html_table(fill=T) -> Truman
Truman[[11]] -> Truman
@briatte
briatte / segmented_brexit.R
Created Jan 17, 2018 — forked from chrishanretty/segmented_brexit.R
Segmented regression on Brexit Right-Wrong gap
View segmented_brexit.R
library(segmented)
library(tidyverse)
dat <- structure(list(Pollster = structure(c(2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("Poll by gfk",
"Poll by YouGov"), class = "factor"), Fieldwork.end.date = structure(c(17539,
17520, 17511, 17505, 17478, 17463, 17459, 17458, 17450, 17433,
17409, 17400, 17379, 17366, 17358, 17339, 17330, 17324, 17317,
@briatte
briatte / yt.sh
Created Dec 10, 2017
single-line shell commands to download MP4 or MP3 from Youtube
View yt.sh
# 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 Nov 18, 2017 — forked from johngruen/userChrome.css
kill drag space
View userChrome.css
/*
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;
View webloc2url.sh
#!/bin/bash
##
## webloc2url.sh - Replace .webloc (Mac) files with .url (Windows) files.
##
## INITIAL VERSION (c) 2015 by mzm
## https://github.com/flagsoft/webloc2url/blob/master/webloc2url.sh
##
## LICENSE: GPL
TEMP_LIST="webloc2url-list.txt.$$.tmp"
You can’t perform that action at this time.