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
View bertest.py
# https://towardsdatascience.com/identifying-hate-speech-with-bert-and-cnn-b7aa2cddd60d
# should also try this one? https://github.com/bentrevett/pytorch-sentiment-analysis/blob/master/6%20-%20Transformers%20for%20Sentiment%20Analysis.ipynb
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 http://i3wm.org/docs/userguide.html for a complete reference!
View energy_nl_cbs.r
# get data from https://opendata.cbs.nl/statline/#/CBS/nl/dataset/80030NED/table?fromstatweb
library(cbsodataR)
library(tidyverse)
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")
View counts.py
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
0eNq1W9ty4ygQ/ZUtPZsUIMQlb/sN+7g1lZJl7KFWljySlUxqKv++2JZsT9xAMzv7kvii093QV7rxj2LdTvYwuO5YPP8oXNN3Y/H8949idLuubk+fHd8Ptngutu3kNsWq6Or96W3rvvn3ZJza7TS4htSN//ZjVbhuY78Xz+zjy6qw3dEdnb0QPL95f+mm/doO/oErpaatB7d1/sNVcehHj+i7E19PhbByVbyf/rOPj9UDDX6lUXc7246kdgPZuvZoB8IBavpKbFVs3GCby5dyVfjX7gASct2uAFiXn1k3X+3eNXVLDm3t9/KRuZiZ8whzz3W0h3qoz98BbMWV7cFDyLEnu6Gfug3Aj8/8yk/8AKoVmiqDiQqAqPyJ6CMpeSUFgBVaogqWiANE9ZXo1/fN0Ic0xZZF0k8k7zT1btu2fyNv9Xi0/u/J4A7TyYqboOrMZ4vZeru3ZDzWzT+Q5T8tK/Ov0mtjNNcgOewM4m6VAR9/ZM7Q6pJXL4Do8ITNqCi6RKLBWMJEAs2qKPMKC4e5S1Q4nKOhTrs0w3sQvRA1CCPTaKIcJApKalI7t5CCMkC22QtwC++tflePs8mTjeu/u42FbJ5n2zxigznSAeC9wNo/BdFY+4d5o80fZp5KFoRd9QbBFS6yEzabpQhrHxfMuU4KXMYENkk4jcBLmoLPlY4C0QyJhnnfTPS1bl8t8SZvh63PhgAhg45X5c14x2ntk+L50UeKckmLymdFiI7IjXsY4SpciIK3W+LA8G6r3Cij0pVZeTNe1412OEK5RoHkvPK9fx1eHorNJ2YMZ1pdtHOqnA6u+Wd6eJLP30NiGfRaFag6KKIKigxMoO4EQ6JB5QmOdDQJokt8ra8WOklTFjf/qNtdbcm2HvakDJ9XeLgIvhDYDdZ2ZHT7QwsmSlHleqREqBXpVPDOZjsVGGqExp1wYBlSGaCKgCuKcOBqEf1zqgMdeN76mx8HPfjyJFgEVwwVxNUSwys4hlc866hkFnIiQK7MIsdYih4+xbCoFm+
View sotu.R
x = read_csv("https://raw.githubusercontent.com/BuzzFeedNews/2018-01-trump-state-of-the-union/master/data/sou.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: https://github.com/mkearney/nytimes
# 1. Install the package from github:
install.packages("devtools")
devtools::install_github("mkearney/nytimes")
# 2. Get an API key from nytimes
# - create an account at https://developer.nytimes.com/accounts/create
View rvest.r
library(rvest)
for (page in 1:10) {
url = str_c("https://www.abgeordnetenwatch.de/bundestag/abstimmungen?page=", page)
message(url)
urls = read_html(url) %>% rvest::html_nodes(".mh-item a") %>% html_attr("href")
print(urls)
}
View rvest_mini_demo.R
# See also: https://blog.rstudio.com/2014/11/24/rvest-easy-web-scraping-with-r/
# install.packages("rvest")
library(rvest)
url = "https://en.wikipedia.org/wiki/Hong_Kong"
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
text[1]
View peerfeedback.r
library(rcanvas)
library(tidyverse)
# 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.