Skip to content

Instantly share code, notes, and snippets.

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

Knut Behrends knbknb

💭
🙅‍♀️💡💤😴🛌🤪🧔
View GitHub Profile
@knbknb
knbknb / pwsh-json.sh
Last active August 10, 2023 13:48
json | powershell
# 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 / qmd_template_at_a_glance.qmd
Last active June 26, 2023 14:01 — forked from erikerhardt/erik_qmd_template_simple.qmd
A qmd quarto frontmatter and template document, simple
---
title: Title
subtitle: Subtitle
author: # originally: Erik Erhardt
date: last-modified # today, now, last-modified
date-format: long # full, long, medium, short, iso, https://quarto.org/docs/reference/dates.html
format:
html:
theme: litera
highlight-style: atom-one
@knbknb
knbknb / R-scrape-wikipedia.R
Last active June 7, 2023 19:04
R: scrape something from wikipedia
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 June 4, 2023 11:44
SPARQL: show common graph objects and types in a default namespace
# 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 June 3, 2023 12:45
R: print a basic truth table, with some custom logical predicates in mutate() call
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 Scrstvchpad (from Output Panel)
[
{
"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 April 3, 2024 07:54
SPARQL/RDF/SemWeb: notes

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 November 30, 2023 18:49
Cheatsheet for simle common dig commands (bash)
<!-- 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 May 18, 2023 09:03
JS: Postman snippets
// 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 May 18, 2023 09:02
JS: 3 Newman Scripts (Postman CLI tool)
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