Skip to content

Instantly share code, notes, and snippets.

Wouter van Atteveldt vanatteveldt

Block or report user

Report or block vanatteveldt

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
# should also try this one?
from transformers import BertTokenizer, BertModel
import logging
import time
#import matplotlib.pyplot as plt
import numpy as np
View i3.config
# This file has been auto-generated by i3-config-wizard(1).
# It will not be overwritten, so edit it as you like.
# Should you change your keyboard layout somewhen, delete
# this file and re-run i3-config-wizard(1).
# i3 config file (v4)
# Please see for a complete reference!
View energy_nl_cbs.r
# get data from
d = cbs_get_data("80030NED") %>% cbs_add_date_column() %>% cbs_add_label_columns() %>%
filter(CentraleDecentraleProductie_label=="Totaal centrale/decentrale productie") %>%
select(date=Perioden_Date, source=Energiedragers_label, elec=ElektriciteitMWh_2)
# filter and translate energy sources
sources = c(coal="Steenkool", oil="Stookolie", gas="Aardgas", biomass="Biomassa", nuclear="Kernenergie", solar="Zonnestroom", wind="Windenergie", water="Waterkracht")
import re
import csv
import sys
from elasticsearch import Elasticsearch
from elasticsearch.helpers import scan
from collections import Counter
es = Elasticsearch("localhost:9201")
index = "amcat_vu"
View sulfuric acid
View sotu.R
x = read_csv("")
x = x %>% select(president, date, text)
t = readtext("/tmp/trump.txt") %>% mutate(doc_id=NULL, president = "Donald J. Trump", date=as.Date("2019-01-01"))
c = bind_rows(x, t)
View nytimes.r
# I will try to post a longer handout, but here is the needed code for accessing nytimes.
# See also:
# 1. Install the package from github:
# 2. Get an API key from nytimes
# - create an account at
View rvest.r
for (page in 1:10) {
url = str_c("", page)
urls = read_html(url) %>% rvest::html_nodes(".mh-item a") %>% html_attr("href")
View rvest_mini_demo.R
# See also:
# install.packages("rvest")
url = ""
s = read_html(url)
headers = s %>% html_nodes("h2")
hist = headers[headers %>% html_text == "Education"]
text = hist %>% html_nodes(xpath="following-sibling::p") %>% html_text
View peerfeedback.r
# helder function that gets a query, does pagination, but doesn't process
get_raw = function (endpoint, args = NULL, method = "GET") {
endpoint = paste(endpoint, collapse = "/")
if (!grepl("^https?://", endpoint))
endpoint = paste0(rcanvas:::canvas_url(), endpoint)
resp <- rcanvas:::canvas_query(endpoint, args, "GET")
rcanvas:::paginate(resp) %>% purrr::map(httr::content, "text") %>%
You can’t perform that action at this time.