Skip to content

Instantly share code, notes, and snippets.

Knut Behrends knbknb

Block or report user

Report or block knbknb

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
@knbknb
knbknb / postman-pre-request-mdis.js
Last active Aug 7, 2019 — 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
View postman-pre-request-mdis.js
// 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:
View YDKJS notes.md

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 / CentralBanks-SPARQL.sql
Last active Jun 22, 2019
Wikidata: Search for Company/Banks Headquarters
View CentralBanks-SPARQL.sql
# 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 / clean-tweets.sh
Last active Jun 21, 2019
Clean tweets .json files taken from twitter streaming API.
View clean-tweets.sh
#!/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 / docker-output-as.json.sh
Last active Jan 19, 2019
Local docker containers as JSON
View docker-output-as.json.sh
# 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 20190119
# found here:
# http://timjrobinson.com/how-to-get-docker-ps-data-in-json-format/
# -s silent
@knbknb
knbknb / babeljs-examples-small-but-weird.js
Last active Jan 12, 2019
babeljs transpilation - demo snippets: before: simple, after: complex
View babeljs-examples-small-but-weird.js
// 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 / relotius-mentions-on-twitter-2018.R
Last active Jan 19, 2019
search for 100000 tweets using the rstats hashtag '#relotius'
View relotius-mentions-on-twitter-2018.R
library(rtweet)
## search for 18000 tweets using the rstats hashtag
rt <- search_tweets(
"#relotius", n = 100000, include_rts = FALSE
)
## preview tweets data
rt
## preview users data
@knbknb
knbknb / visjs-grab.js
Last active Jan 19, 2019
Grab existing visjs DOM object on html page, change visjs options. http://visjs.org/ , R htmlwidgets
View visjs-grab.js
// 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 / gephi-2-igraph-2-visjs.R
Created Dec 9, 2018
Create pretty network-diagram of tweets with visjs, after custom filtering. (WORK IN PROGRESS)
View gephi-2-igraph-2-visjs.R
# create pretty network-diagram of tweets,
# captured with Gephi's Twitter plugin,
# exported as JSON
# with more sophisticated filtering
# knbknb 20181209
library(visNetwork)
library(tidyverse)
workdir <- "/home/knut/gephi/"
# infile created with "Export as ..." Feature of Gephi Desktop App
@knbknb
knbknb / gephi-2-visjs.R
Last active Dec 9, 2018
Creates a static HTML/JS page with pretty network-diagram of twitter data (captured by gephi)
View gephi-2-visjs.R
# create pretty network-diagram of tweets,
# captured with Gephi's Twitter plugin,
# exported as JSON
# knbknb 20181218
#
library(visNetwork)
library(readr)
workdir <- "/home/knut/gephi/"
# infile created with "Export as ..." Feature of Gephi Desktop App
You can’t perform that action at this time.