Skip to content

Instantly share code, notes, and snippets.

View maelle's full-sized avatar

Maëlle Salmon maelle

View GitHub Profile
library(tidyverse)
# in case we have network or site issues
sfj <- safely(jsonlite::fromJSON)
# URLs 1-3600
hit_lists <- sprintf("https://hitlijst.vrt.be/api/lists/%s.json", 1:3600)
# gotta get'em all!
map(hit_lists, ~{
@jeanmanguy
jeanmanguy / best9oftweets.R
Last active January 1, 2018 18:21
create a collage with the best 9 tweets from the tweet activity data
# code adapted from http://www.masalmon.eu/2017/12/30/best9of2017/
library(purrr)
library(webshot) #webshot::install_phantomjs()
library(magick)
library(dplyr)
library(glue)
# load all the CSV files in the data folder downloaded from https://analytics.twitter.com/user/<username>/tweets
my_tweets <- file.path("data", list.files("data", pattern = "^tweet_activity_metrics_")) %>% map_df(readr::read_csv)
@privefl
privefl / Unicode To Hexa HTML
Created December 2, 2017 09:27
Convert unicode in HTML to hexa.
unicode2hex <- function(html_file) {
new_text <- gsub(pattern = "&lt;U\\+([0-9]{4})&gt;", replacement = "&#x\\1",
x = readLines(html_file, encoding = "UTF-8"))
writeLines(new_text, con = html_file, useBytes = TRUE)
}
@jeroen
jeroen / canny.R
Last active April 1, 2021 14:20
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()
library(gh)
library(tidyverse)
library("magick")
library(glue)
dir.create("data")
repos <- gh::gh("/orgs/:org/repos", org = "tidyverse", .limit = Inf) %>% map_chr("name")
urls <- repos %>%
library(waffle)
library(hrbrthemes)
library(stringi)
library(tidyverse)
dots <- c(28, 27, 24, 20, 18, 17, 16, 16, 15)
labs <- c(
"Support health-related cause",
"Comment on others' health experiences",
"Post about health experiences",
@noamross
noamross / find_local_tweeps.R
Created August 14, 2017 23:43
A visit to Durham
library(rtweet) #rtweet API creds should already be set up
library(stringi)
library(dplyr)
friends = get_friends(user="noamross")
followers = get_followers("noamross")
tweeps_id = distinct(bind_rows(friends, followers))
tweeps_info = lookup_users(tweeps_id$user_id)
# A regex for a visit to Durham
# Got too many private repos in a GitHub Organization?
# This will list all of the private repos you have access to and rank them by
# days since last push and total number of commits.
# Add PAT to .Renviron - mine is obscured
# cat("GITHUB_PAT=yourowngithubpatgoeshere\n",
# file=file.path(normalizePath("~/"), ".Renviron"),
# append=TRUE)
@ahmadawais
ahmadawais / upload-a-file.MD
Created June 18, 2017 11:07 — forked from websupporter/upload-a-file.MD
Upload a file using the WordPress REST API

Upload files

Using the REST API to upload a file to WordPress is quite simple. All you need is to send the file in a POST-Request to the wp/v2/media route.

There are two ways of sending a file. The first method simply sends the file in the body of the request. The following PHP script shows the basic principle:

@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]]