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 / pwsh-json.sh
Last active August 3, 2025 16:36
json|pwsh: PowerShell JSON Bash Snippets
# display a JSON object as a table using PowerShell.
# the JSON is generated by a perl script
perl api-gfz.pl -r \
| pwsh -Command "$json = Get-Content -Raw -Stream; ConvertFrom-Json $json | Format-Table -AutoSize "
# with a Where-Object filter in between:
perl api-gfz.pl -r \
| pwsh -Command "$json = Get-Content -Raw -Stream; ConvertFrom-Json $json | Where-Object { \$_.status -eq 'paused' } | Format-Table -AutoSize "
# Assumes that the JSON structure is an array of objects
@knbknb
knbknb / R-scrape-wikipedia.R
Last active August 3, 2025 16:36
R: Wikipedia Scraping & URL Tester
library(tidyverse)
library(lubridate)
library(rvest)
# Even better to use the Internet Archive since web pages change over time
url <- "https://web.archive.org/web/20220908211042/https://en.wikipedia.org/wiki/..."
wiki_raw <- read_html(url)
wiki_raw
@knbknb
knbknb / construct-show-objects-in-default-namespace.rq
Last active August 3, 2025 16:36
SPARQL: Show Common Graph Objects & Types
# CONSTRUCT query to surface the graph schema (ontology) as a sub-graph.
CONSTRUCT {
?domain ?property ?range
}
WHERE {
?property rdfs:domain ?domain ;
rdfs:range ?range .
FILTER(?domain NOT IN(rdfs:Class, rdf:Property))
@knbknb
knbknb / truthtables.R
Last active August 3, 2025 16:36
R: Print Basic Truth Table with Custom Predicates
library(tidyverse)
tt <- tibble(
x = c(TRUE, TRUE, FALSE, FALSE),
y = c(TRUE, FALSE, TRUE, FALSE)
)
`->` <- function(x, y) {
as.logical(dplyr::case_when(
x == TRUE & y == TRUE ~ TRUE,
x == TRUE & y == FALSE ~ FALSE,
@knbknb
knbknb / countrygraph-objects.json
Created May 25, 2023 21:16
sparql: Query Results (countrygraph objects)
[
{
"subject": "http://example.com/demo/Country",
"predicate": "http://example.com/demo/area_in_sq_km",
"object": "http://www.w3.org/2001/XMLSchema#double"
},
{
"subject": "http://example.com/demo/Country",
"predicate": "http://example.com/demo/capital",
"object": "http://www.w3.org/2001/XMLSchema#string"
@knbknb
knbknb / SPARQL-Semweb-notes.md
Last active August 3, 2025 16:36
semweb: SPARQL/RDF/SemWeb Notes & Queries

RDF Nodes cannot exist without at least one edge, to another node or to themselves.

IRI: Internationalized Resource Identifier, generalized URI used for proper things URLs are not officially recognised as a type of RDF node

Literal: string, number, date, etc. used for values

@knbknb
knbknb / dig-queries-gfz-2023.md
Last active August 3, 2025 16:36
bash: dig Command Cheatsheet (GFZ 2023)
<!-- markdownlint-disable MD041 -->
<!-- markdownlint-disable MD022 -->
<!-- markdownlint-disable MD026 -->
dig gfz-potsdam.de A        # A records only (name -> IP)
dig gfz-potsdam.de A +short # Short output
dig gfz-potsdam.de MX       # MX records (mail server)
dig gfz-potsdam.de TXT      # TXT records (text)
dig gfz-potsdam.de NS       # NS records (name server)
dig gfz-potsdam.de SOA # SOA records (start of authority)
@knbknb
knbknb / cookiejar-async.js
Last active August 3, 2025 16:36
js: Postman Snippets & Cookiejar Examples
// Postman snippet to check if cookie jar contains a Yii2 Session cookie.
// For this to work any domain with a cookie of that value must be whitelisted inside postman.
// The error message text will point this out in case it fails.
let URL = require('url'); // postman-built-in
const cookieJar = pm.cookies.jar();
const cookieName = "PHPSESSID";
const baseUrl = pm.environment.get("baseUrl");
const parsedUrl = URL.parse(baseUrl)
@knbknb
knbknb / newman-as-node-module-write-to-disk.js
Last active August 3, 2025 16:36
js: Newman CLI Scripts for Postman
const fs = require('fs');
const process = require('process');
const newman = require('newman'); // require newman in your project
// call this as node newman-as-node-module-write-to-disk.js
// simpler: How can machine_name and port_number can be passed dynamically to the Postman tests when using Newman?
// newman run my-collection.json --global-var "machineName=mymachine1234" --global-var "machinePort=8080"
// In your request builder, just use them as normal variables https://{{machineName}}:{‌{machinePort}}.
// call newman.run to pass `options` object and wait for callback
@knbknb
knbknb / ultimate-ut-cheat-sheet.md
Last active August 21, 2024 07:20 — forked from yoavniran/ultimate-ut-cheat-sheet.md
The Ultimate Unit Testing Cheat-sheet For Mocha, Chai, Sinon, and Jest