Skip to content

Instantly share code, notes, and snippets.

View maelle's full-sized avatar
🌞

Maëlle Salmon maelle

🌞
View GitHub Profile
@expersso
expersso / pig_latin.R
Created June 2, 2017 15:14
Pig latin translator
library(stringr)
library(purrr)
vowels <- c("a", "e", "i", "o", "u")
is_vowel <- function(l) l %in% c(vowels, toupper(vowels))
is_capitalized <- . %>% substr(1, 1) %>% str_detect("[[:upper:]]")
split_at <- function(x, i) split(x, cumsum(seq_along(x) %in% i))
pigify_word <- function(word) {
ltrs <- strsplit(word, "")[[1]]
@geofis
geofis / wordcloud.R
Created March 12, 2017 16:40
Wordcloud of RBloggers Twitter account
#REF: https://cran.r-project.org/web/packages/wordcloud2/vignettes/wordcloud.html
#INSPIRED BY: http://www.masalmon.eu/2017/02/28/rbloggerstweets/
#PACKAGES
library(rtweet)
library(dplyr)
library(tidytext)
library(rcorpora)
library(wordcloud2)
library(rvest)
library(tidyverse)
library(ggbeeswarm)
library(hrbrmisc)
library(ggalt)
library(gridExtra)
sprintf("http://cran.rstudio.org/src/base/R-%d", 0:3) %>%
map(read_html) %>%
map(html_table) %>%
@jeroen
jeroen / monkeylearn_http2.sh
Last active November 24, 2016 17:27
Monkeylearn HTTP2 POST connection failures
# To install curl with HTTP2 on MacOS:
brew reinstall curl --with-nghttp2
brew link --force curl
curl --version # must be 7.51.0
# Example that fails with HTTP2
curl -v https://api.monkeylearn.com/v2/classifiers/test/classify/ \
-d '{"text_list":["my dog is an avid rice eater","i want to buy an iphone"]}'
# Error:
@pboesu
pboesu / mtcars-cat.R
Last active November 18, 2016 10:47 — forked from dill/mtcars-cat.R
categorical emojis -- like this Mark?
library(emoGG)
library(ggplot2)
#use subsetting to display different emojis for different factor levels
ggplot(mtcars, aes(wt, mpg))+
geom_emoji(data = mtcars[mtcars$am==1, ], emoji = "1f697") +
geom_emoji(data = mtcars[mtcars$am==0, ], emoji = "1f68c")
@jonathansick
jonathansick / query.graphql
Last active January 20, 2024 07:58
GitHub GraphQL repo commit history query
{
repository(name: "sickvim", owner: "jonathansick") {
ref(qualifiedName: "master") {
target {
... on Commit {
id
history(first: 5) {
pageInfo {
hasNextPage
}
@leeper
leeper / make_patch.R
Last active September 11, 2016 17:22
Compare two data.frames and generate the code to patch the differences
# function to identify what changed where
which_changed <- function(x, y = x) {
# argument validation
stopifnot(inherits(x, "data.frame"))
stopifnot(inherits(y, "data.frame"))
stopifnot(identical(dim(x), dim(y)))
y <- y[, names(x)]
# compare objects
@gmbecker
gmbecker / broken.Rmd
Last active September 26, 2018 04:25
DebuggingInRmd
We set up knitr so it doesn't catch errors, then set
`options(error=recover)` to set up R's debug-on-error machinery.
We have to do one additional thing, before the options call though:
trace the recover function with`sink(NULL)` to turn off the output
capturing so the R console is useful when the debugging framework
dumps us back into it. This has to happen before the options call
because that call grabs the `recover` object and stores it somewhere
so setting a trace on recover after the call won't affect the cached
version that gets called upon an error.
@stephlocke
stephlocke / .Rprofile
Last active July 20, 2018 07:04
HIBPwned .Rprofile examplel
.First<-function(){
cat(paste0("My data has been breached ",
length(HIBPwned::account_breaches("stephanie.g.locke@gmail.com")$name),
" times (that we know of)"))
}