Skip to content

Instantly share code, notes, and snippets.

View phagenlocher's full-sized avatar

Philipp Hagenlocher phagenlocher

View GitHub Profile
@phagenlocher
phagenlocher / scrocr.sh
Created January 13, 2026 20:06
Simple text extraction from the screen
#!/bin/bash
scrot -s -f "-" | tesseract - - 2>/dev/null | xclip -selection clipboard -i
@phagenlocher
phagenlocher / auto_migrate.py
Last active August 16, 2025 13:57
Sketch: Automatically migrate old data with alternatives from pydantic's BaseModels
from __future__ import annotations
from abc import ABC, abstractmethod
from typing import Self, override
from collections.abc import Callable
import pydantic
class FooV1(pydantic.BaseModel):
a: int
b: str
@phagenlocher
phagenlocher / scrotmp.sh
Last active February 18, 2025 16:39
Scrot but saves files in a temporary directory and automatically copies the screenshot to the clipboard
#!/bin/bash
DIR="/tmp/screenshots"
mkdir -p "$DIR"
TIMESTAMP=$(date +%Y-%m-%dT%H-%M-%S)
FILE=$(mktemp -u -p "$DIR" -t "$TIMESTAMP-XXXXX.png")
scrot -e 'xclip -selection clipboard -t image/png -i $f' "$@" "$FILE" && echo "$FILE"
@phagenlocher
phagenlocher / main.py
Last active October 24, 2024 06:02
Vector Embedding eDSL
from vectorize import (
categorize_class,
categorize_bool,
categorize_num,
make_vectorize,
)
@categorize_class(["FIN", "MISC"], weight=10)
def module_cat(d):
#!/usr/bin/env python3
import code
import ctypes
import inspect
import logging
def hook(
banner_msg: str | None = None,
@phagenlocher
phagenlocher / lazy.py
Last active March 6, 2024 13:59
Lazy Evaluation in Python (https://youtu.be/KniIeHiEzdo)
class Lazy:
def __init__(self, fun, *args, **kwargs):
self.fun = fun
self.args = args
self.kwargs = kwargs
self.executed = False
self.value = None
# Binary Operators
def __binary__(self, binfun, other):
@phagenlocher
phagenlocher / Lazy.java
Last active September 7, 2020 15:00
Lazy Evaluation in Java (https://youtu.be/KniIeHiEzdo)
package main;
public interface Lazy<R> {
public R force();
}
-- Compile with -threaded
import System.IO
import Control.Concurrent
import Control.Concurrent.STM
-- (<Sum>, <Number of finished transactions>)
type Result = TVar (Int, Int)
-- Adds x to result and increments the number of finished transactions
-- Compile with -threaded
import System.IO
import Control.Concurrent
getGreeting :: IO String
getGreeting = do
-- Get id and convert to string
tid <- myThreadId
let greeting = "Hello from " ++ show tid
-- Compile with the -XScopedTypeVariables flag.
-- e.g. ghc -Wall -XScopedTypeVariables Main.hs
import Control.Exception
data MyError = Error deriving Show
instance Exception MyError
failing :: IO ()