Skip to content

Instantly share code, notes, and snippets.

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

Knut Behrends knbknb

💭
🙅‍♀️💡💤😴🛌🤪🧔
  • Nothing to see here
  • Potsdam, Germany
View GitHub Profile
@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 / 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 / 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 / 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 / gephi-2-igraph-2-visjs.R
Created December 9, 2018 17:23
Create pretty network-diagram of tweets with visjs, after custom filtering. (WORK IN PROGRESS)
# 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 December 9, 2018 16:42
Creates a static HTML/JS page with pretty network-diagram of twitter data (captured by gephi)
# 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
@knbknb
knbknb / node-npm-notes.md
Last active April 21, 2024 20:07
node and npm - Personal notes, 2018

Personal Notes on some Nodejs related courses, npm, and Modern Javascript

"Node.js: Getting Started"; "Advanced Node.js" by Samer Buna;

"NPM Playbook" by Joe Eames;

and other courses and tutorials

Notes

@knbknb
knbknb / pluralsight-es6-the-right-parts.txt
Last active December 14, 2018 14:19
ES6: The Right Parts (personal Notes taken watching a video feat. JS guru Kyle Simpson)
ex0: The arrow function: (x) => 3;
ex1: var vs let
ex2: Default-values, and gather/spread
ex3: Destructuring
ex4: Concise properties and methods, Template Strings, Tag functions
@knbknb
knbknb / node-client-server-todolist-mini-cli-app.md
Last active November 18, 2018 10:11
a TODO-list CLI app implemented using only builtin node modules (EventEmitter, process, readline)

Run the app on the command line with: node client.js. This implicitly loads server.js.

From Samir Buna's "Advanced NodeJS" course on Pluralsight

client.js

const EventEmitter = require('events');
const readline = require('readline');

const rl = readline.createInterface({
@knbknb
knbknb / noder.sh
Last active December 6, 2018 12:57
start node repl with favorite options and modules
#!/bin/bash
# noder.sh : my node repl
# load nodejs repl with lodash preloaded
# - only for nvm users,
# - and lodash must be installed globally
# - optional: rlwrap utility installed with e.g. apt install rlwrap
# (if it is not installed remove rlwrap in NODE_PATH line below)
# knb 20181013
node_version=$(node -p process.versions.node);
extra_path="$HOME/.nvm/versions/node/v$node_version/lib/node_modules/";