Skip to content

Instantly share code, notes, and snippets.

View knbknb's full-sized avatar
💭
🙅‍♀️💡💤😴🛌🤪🧔

Knut Behrends knbknb

💭
🙅‍♀️💡💤😴🛌🤪🧔
View GitHub Profile
@knbknb
knbknb / visjs-grab.js
Last active January 19, 2019 22:12
Grab existing visjs DOM object on html page, change visjs options. http://visjs.org/ , R htmlwidgets
// Grab existing visjs DOM object on html page, change options
// knb 2018-12-08
// http://visjs.org/ Visualisation Library
// get similar id e.g. by inspecting HTML page source code that was generated by R htmlwidgets package
var = "htmlwidget-4210fec5d0f413c28b94";
var el = document.getElementById("graph" + widget);
var network = el.chart;
@knbknb
knbknb / relotius-mentions-on-twitter-2018.R
Last active April 14, 2022 15:56
search for 100000 tweets using the rstats hashtag '#relotius'
## The Claas Relotius Scandal just happened to be a popular/interesting topic
## in the German news when I develeoped this code.
## (Relotius was/is a cheating journalist who made up his own stories
## to gain prizes and fame)
## Lots of people have tweeted about the story in 2018.
library(rtweet)
## search for 18000 tweets using the rstats hashtag
rt <- search_tweets(
"#relotius", n = 100000, include_rts = FALSE
@knbknb
knbknb / babeljs-examples-small-but-weird.js
Last active January 12, 2019 14:30
babeljs transpilation - demo snippets: before: simple, after: complex
// this simple snippet will moderately complex after transpiling
// https://babeljs.io/repl#?babili=false&browsers=safari%20%3E%209&build=&builtIns=false&spec=false&loose=false&code_lz=G4QwTgBA2iA0BQEnKQIwgXggFgEyxQgHoiIBiCAEwFMAzEAVwBsAXCUJh6gZwEIIAFAEtaEagFsADiwCeEAPaQGAOxq0hy6pQXKIAJQASAZQCUiQkgDGCCwDp74AObd4AXUwRa8-QJMQAPv7QEK4A3BDwQA&debug=false&forceAllTransforms=false&shippedProposals=false&circleciRepo=&evaluate=false&fileSize=false&timeTravel=false&sourceType=module&lineWrap=true&presets=env&prettier=false&targets=&version=6.26.0&envVersion=1.6.2
var [a,
b = 42, // default values! (if empty or undefined on RHS)
c,
...args
] = foo() || [ ];
//
function foo(){
@knbknb
knbknb / docker-output-as.json.sh
Last active April 14, 2022 15:59
Local docker containers as JSON
# How to get docker ps data in JSON format
# With curl version 7.40 and newer you can get data from the local unix socket,
# and docker always runs the remote api on docker.sock.
# -----
# knbknb 2019, 2022
# list of all running Docker containers, return names only
curl -s --unix-socket /var/run/docker.sock http://localhost/images/json | jq .[].Names
# list of all Docker images, return names (RepoTags) only
@knbknb
knbknb / clean-tweets.sh
Last active June 21, 2019 10:12
Clean tweets .json files taken from twitter streaming API.
#!/bin/sh
# knb 2019-06 -- untested
#
# Clean tweets .json files taken from twitter streaming API.
# (can probably also remove non-tweet-objects). One JSON object per line is important.
#
# Some tweets might have been corrupted by errors made by the application,
# or by the operating system
# But tweets must be well-formed
# in order to read them in quickly by R or some other postprocessing app.
@knbknb
knbknb / CentralBanks-SPARQL.sql
Last active June 22, 2019 12:47
Wikidata: Search for Company/Banks Headquarters
# see https://stackoverflow.com/questions/56539793/wikidata-sparql-get-company-entities-and-the-location-of-their-headquarters
SELECT ?item ?itemLabel ?web ?isin ?hqLabel ?hqloc ?hqCountry ?hqCountryLabel ?inception
WHERE { #values ?item {wd:Q74687}
# for debugging
?item p:P31/ps:P31/wdt:P279* wd:Q783794.
OPTIONAL{?item wdt:P856 ?web.}
# get website
OPTIONAL{?item wdt:P946 ?isin.}
# get ISIN
OPTIONAL{?item wdt:P571 ?inception.} # get inception date
@knbknb
knbknb / YDKJS notes.md
Last active December 10, 2019 09:25
YDKJS : You don't know Javascript (book by Kyle Simpson) ed1

Book 1

Into programming

Going back to general programming basics. Even after 25 years, I can still learn some new things, or get a precise definition of some terms.

  • variables - not typed
  • literal values - typed
  • operators
  • statements are made of: expressions, any reference to a variable or value, or a set of variables and values combined with operators
@knbknb
knbknb / postman-pre-request-mdis.js
Last active August 7, 2019 21:40 — forked from bcnzer/postman-pre-request.js
Postman pre-request script to automatically get a bearer token from our custom software 'mDIS' and save it for reuse
// set these variables on the folder level
// also select Postman No-Authentication option, and then set your own HTTP Autorization Header
var url = pm.variables.get('baseUrl') + "/api/v1/auth/login";
var username = pm.variables.get('username');
var password = pm.variables.get('password');
const echoPostRequest = {
url: url,
method: 'POST',
header: 'Content-Type:application/json',
body:
@knbknb
knbknb / github_my_gists.sh
Last active May 23, 2022 08:37
GET date, url, filename, description of all my github gists, ordered by crdate DESC
#!/bin/sh
# knb 2019,2022
# get date, url, filename, description of all my github gists, ordered by crdate DESC
#GITHUB_PAT=5b01b116a34967ff0afce4d45205f907d45501c9
GITHUB_PAT=
if [ -z "$1" ]
then
user=knbknb
else
user=$1
@knbknb
knbknb / fetch-api.js
Last active April 14, 2022 15:34
some small node / javascript snippets with very basic tasks
// 2022 - does no longer work
// node: assume node-fetch is installed.
// alias node='export NODE_PATH=$NODE_PATH:$NVM_BIN/../lib/node_modules && node --use-strict'
// const fetch = require("node-fetch"); // load -g module
(async () => {const data = await fetch("http://api.figshare.com/v1/categories", {
"credentials": "include",
"headers": {
"User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:79.0) Gecko/20100101 Firefox/79.0",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",