Skip to content

Instantly share code, notes, and snippets.

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

Knut Behrends knbknb

💭
🙅‍♀️💡💤😴🛌🤪🧔
View GitHub Profile
@knbknb
knbknb / exlore-dataset-bobdc-helmhotzkg.sparqlbook
Last active May 2, 2024 06:37
helmholtz-knowledge-graph (use in VSCode with Sparqlbook Extension)
[
{
"kind": 1,
"language": "markdown",
"value": "# Queries to explore a dataset: Helmholtz-KnowledgeGraph\n\n> Source: [bobdc.com](https://www.bobdc.com/blog/exploringadataset/) - Bob DuCharme's blog\n\nI recently worked on a project where we had a huge amount of RDF and no clue what was in there apart from what we saw by looking at random triples.\nI developed a few SPARQL queries to give us a better idea of the dataset’s content and structure and these queries are generic enough that I thought that they could be useful to other people.\n\nI’ve written about other exploratory queries before.\nIn Exploring a SPARQL Endpoint I wrote about queries that look for the use of common vocabularies that might be used at a particular endpoint, and how getting a few clues led me to additional related queries.\nThat blog post also mentioned the “Exploring the Data” section of my book Learning SPARQL, which has other general useful queries.\n\nYou can see those listed in the book’s table of contents; they of
@knbknb
knbknb / exiftool-hacks.sh
Last active May 2, 2024 06:39
exiftool-hacks (used to set metadata in a PDF file here)
#!/usr/bin/env bash
OUTFILE=myfile.pdf
# write metadata to the PDF file, update in place
exiftool -overwrite_original -Title="" \
-Author="" \
-Subject="Newsletter, v$(date '+%Y-%m-%d')" \
-Producer="" \
-Creator="" \
@knbknb
knbknb / ffmpeg-hacks.sh
Last active May 2, 2024 06:41
ffmpeg hacks (various bash commands to extract audio from a video, etc.)
# You can use `ffmpeg`, a powerful tool that can be used to convert multimedia data
# from one format to another. If `ffmpeg` is not installed on your system,
# you can install it using the package manager of your Linux distribution.
ffmpeg -i input.mov -vcodec copy -acodec copy output.mp4
#In this command:
#
#- `-i input.mov` specifies the input file.
#- `-vcodec copy` and `-acodec copy` tell `ffmpeg` to copy the video and audio streams as-is, without re-encoding them.
#- `output.mp4` is the output file.
@knbknb
knbknb / create-er-diagram.md
Last active May 2, 2024 06:42
Create ER diagram from CSV files describing a relational DB schema using "sql2dbml" tool

Create ER Diagram from CSV files forming the database schema using "sql2dbml" tool

Load database into Sqlite

# install from pypy
sqlite-utils insert trees.db  myfile.csv

Show full schema for this database or for specified tables

@knbknb
knbknb / json-Reponse-to-Visualizer-Tab.js
Last active February 15, 2024 12:28
Postman JS snippets and Utilities
// Display the response in the Visualizer, if it is json
// and if it has a "model" property
// and a "".choices[0].message.content" Property
// (Typical output from OpenAI API and Perplexity APIs)
pm.test(`response is json`, function () {
const response = pm.response.json();
pm.expect(response.model).to.eql(pm.variables.get("model"));
pm.expect( Object.keys(response).length).to.above(0);
content = response.choices[0].message.content
pm.visualizer.set(`
@knbknb
knbknb / python-snippets.md
Last active October 14, 2023 20:43
Python Notebook snippets

Wrap text in cell outputs

To wrap text in cell outputs in a Jupyter notebook, you can use the pandas library to display the text in a DataFrame with word wrapping enabled. Here's an example:

import pandas as pd

text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."

df = pd.DataFrame({'text': [text]})
@knbknb
knbknb / jq_snippets_basics.sh
Last active May 2, 2024 09:21
jq basics (oneliners)
#% jq, unixtools, knb
# manual: https://jqlang.github.io/jq/manual/
# wiki jq:
# https://github.com/jqlang/jq/wiki/jq-Language-Description#lexical-symbol-bindings-function-definitions-and-data-symbol-bindings
# man jq
# jq exit codes in $?: (default: 0 on success null on error.)
# jq -e : jq exit codes $?: (default: 0 on success 1 on error.
@knbknb
knbknb / prompts-for-LLMs.md
Last active August 17, 2023 20:16
Prompts for ChatGPT and LLMs

meeting/hn-thread summarizer, ultrashort

You will be provided with meeting notes. Participants discussed topic "Open Challenges in LLM Research"

Provide a table | Participant/User name | Argument (keyword-style) |

User names can be found in lines containing a substring matching the regex "^\s*[\d+]\w+" . if no username is obvious, write (unknown). if links are given in a paragraph, include it in the Argument column.

@knbknb
knbknb / gcloud-snippets.sh
Last active August 10, 2023 19:01
gcloud snippets
#!/usr/bin/env bash
# Description: snippets for gcloud
# install gcloud sdk
# login
# first look
gcloud auth list
gcloud config list
@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