Skip to content

Instantly share code, notes, and snippets.

View sebastianrothbucher's full-sized avatar

Sebastian Rothbucher sebastianrothbucher

View GitHub Profile
@sebastianrothbucher
sebastianrothbucher / cell.py
Last active January 18, 2025 18:33
Jupyter HTML and several displays - just store for once
import pandas as pd
from IPython.core.display import HTML
# display several
display("one")
display(pd.DataFrame({"a": [1, 2]}))
print("two-a")
display(HTML('<em style="color: hotpink">two-b</em><a href="https://bla">Link gets rendered in PDF</a>'))
display("two-c")
@sebastianrothbucher
sebastianrothbucher / pg-insert-missing.sql
Last active January 18, 2025 18:07
Postgres - insert missing and ignore dups -
CREATE TABLE public.test (
id int4 NOT NULL,
"text" text NULL,
CONSTRAINT test_pkey PRIMARY KEY (id)
);
insert into test (id, text) values (1, 'hey'), (2, 'ho') on conflict do nothing;
insert into test (id, text) values (2, 'hoo'), (3, 'whatever') on conflict do nothing;
-- result: 1/hey, 2/ho, 3/whatever inserted - perfect: minimum # statements, exactly what's wanted: just fill in missing
@sebastianrothbucher
sebastianrothbucher / combine.tex
Last active January 18, 2025 15:38
All PDF manipulations - nice and open src (pypdf would be an alternative - see below)
\documentclass{article}
\usepackage{pdfpages}
\usepackage{background}
\backgroundsetup{scale = 1, angle = 0, opacity = 1,
contents = {\includegraphics[width = \paperwidth,
height = \paperheight, keepaspectratio]
{testbriefkopf.pdf}}}
% for different, we can have two steps: first background, then merge
\begin{document}
\includepdf[pages=-]{dinbrief2.pdf}
@sebastianrothbucher
sebastianrothbucher / flow.json
Created August 3, 2024 18:01
Simulating a sine curve and sudden drop via Node-Red
[
{
"id": "91450f41b1eae9c6",
"type": "inject",
"z": "426169ba36026cef",
"name": "on",
"props": [
{
"p": "payload"
},
@sebastianrothbucher
sebastianrothbucher / gql-test.ts
Last active July 21, 2024 10:18
Base Apollo server (including subscriptions - can leave out ws part) - round trip
import {ApolloServer} from '@apollo/server';
import { ApolloServerPluginDrainHttpServer } from '@apollo/server/plugin/drainHttpServer';
import {expressMiddleware} from '@apollo/server/express4';
import {makeExecutableSchema} from '@graphql-tools/schema';
import express from 'express';
import cors from 'cors';
import morgan from 'morgan';
import fs from 'fs';
import {createServer} from 'http';
import { WebSocketServer } from 'ws';
@sebastianrothbucher
sebastianrothbucher / automator-shell.sh
Last active January 19, 2025 16:28
img2txt - clipboard image to clipboard text (per se: on Mac)
#!/bin/zsh
/opt/homebrew/bin/python3 -c 'import pytesseract; from PIL import Image, ImageGrab; im = ImageGrab.grabclipboard(); pytesseract.pytesseract.tesseract_cmd = "/opt/homebrew/bin/tesseract"; print(pytesseract.image_to_string(im))' | pbcopy # python3.12 for specific python
# done
@sebastianrothbucher
sebastianrothbucher / shell-helper.inc
Created May 31, 2024 14:38
STS assume role and export creds - use via . shell-helper.inc in bash
function assumeRoleAndExport {
local STS_RES=$(aws sts assume-role --role-arn $1 --role-session-name "whatever-session-$(uuidgen)")
export AWS_ACCESS_KEY_ID=$(echo $STS_RES | jq -r .Credentials.AccessKeyId)
export AWS_SECRET_ACCESS_KEY=$(echo $STS_RES | jq -r .Credentials.SecretAccessKey)
export AWS_SESSION_TOKEN=$(echo $STS_RES | jq -r .Credentials.SessionToken)
}
@sebastianrothbucher
sebastianrothbucher / node-red-flows.json
Last active May 30, 2024 18:51
IoTcore simple policy and node-red flow
[
{
"id": "426169ba36026cef",
"type": "tab",
"label": "Flow 1",
"disabled": false,
"info": "",
"env": []
},
{
@sebastianrothbucher
sebastianrothbucher / index.html
Created March 31, 2024 18:59
pdf.js cont scroll
<div style="position: sticky; top: 0; background: white; ">Page <span id="page"></span> Timing: <span id="timing"></span></div>
<div id="canvases"></div>