Skip to content

Instantly share code, notes, and snippets.

@pavelanni
pavelanni / text_to_speech.py
Created April 1, 2025 21:57
Text-to-speech generation script
import argparse
import asyncio
import os
from pathlib import Path
from openai import AsyncOpenAI
openai = AsyncOpenAI()
async def text_to_speech(text_file: str, instructions_file: str = 'instructions.txt', voice: str = 'onyx') -> None:
@pavelanni
pavelanni / podman-machine-time-sync.md
Created November 13, 2024 16:03
Synchronize Podman machine's clock with NTP

The problem: when you close your Macbook lid and put it on sleep, the Podman machine's time lags the real time. That brings hard-to-detect problems with certificate verification (look for certificate has expired or is not yet valid in the error messages).

The solution is to podman machine ssh and run timedatectl set-ntp yes. Or run it as a single command from your laptop.

@pavelanni
pavelanni / cleanup-finalizers.sh
Created October 30, 2024 16:53
Remove finalizers from PVCs and Secrets
#!/bin/bash
namespace=$1
if [ -z "$namespace" ]; then
echo "Usage: $0 <namespace>"
exit 1
fi
# Check if kubectl is available
@pavelanni
pavelanni / get_tags_from_aistor.sh
Last active October 21, 2024 21:41
Get image tags from sha256 (works with Harbor; Docker requires slightly different API_URL)
#!/bin/bash
# Function to get tags for a given image
get_tags() {
local FULL_IMAGE="$1"
local POD_NAME="$2"
# Extract components from the full image
REGISTRY=$(echo "$FULL_IMAGE" | cut -d'/' -f1)
PROJECT=$(echo "$FULL_IMAGE" | cut -d'/' -f2)
@pavelanni
pavelanni / hashDir.go
Last active May 31, 2024 16:35
Create a hash of the whole directory; use goroutines to hash files in parallel.
package main
import (
"crypto/sha256"
"encoding/hex"
"fmt"
"io"
"log"
"os"
"path/filepath"
@pavelanni
pavelanni / parseForm.go
Created July 11, 2021 01:39
My naive attempt to fill a struct from form data -- similar to gorilla/schema, but much simpler
func newHandler(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
files := []string{
templateDir + "/bootstrap.go.html",
templateDir + "/header.go.html",
templateDir + "/new.go.html",
templateDir + "/footer.go.html",
}
tmpl, err := template.ParseFiles(files...)
if err != nil {
package main
import "fmt"
func inner(s []int) {
s[len(s)-1] = 999
}
func inner2(s []int) {
s[0] = 9
@pavelanni
pavelanni / gist:4cc93619ed882b8f9a24ac3f06c4cb2a
Created March 16, 2021 17:22
You have many RPMs in one dir; you want to know which repos they belong to (BaseOS, AppStream, etc.)
for r in *rpm ; do pkgname=$(rpm -q --queryformat "%{NAME}" -p ${r}); dnf -q repoquery --qf "%{name} %{reponame}" ${pkgname} ; done
@pavelanni
pavelanni / gist:800a1de2d7c85881b751868208f1d5e3
Created March 12, 2021 15:54
Python: Add items to a dict from a second dict without changing the existing ones
d1 = {'a': 1, 'b': 2, 'c': 3}
d2 = {'d': 4, 'e': 5, 'a': 6}
d1.update({k:v for (k,v) in d2.items() if k not in d1})
d1
# Out: {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5}
#!/usr/bin/env python
import sys
import sqlite3
if len(sys.argv) < 3:
print(f"Usage: {sys.argv[0]} <year_start> <year_end>")
sys.exit(1)
year_start = int(sys.argv[1])
year_end = int(sys.argv[2])