Skip to content

Instantly share code, notes, and snippets.

@ohbob
ohbob / number_to_words.js
Created October 23, 2025 23:10
number_to_words.js
// ============================================================================
// TYPES & INTERFACES
// ============================================================================
type Gender = "masculine" | "feminine" | "neutral";
interface NumberWords {
ones: string[];
tens: string[];
}
@ohbob
ohbob / logging-grafana-loki.md
Created August 30, 2025 10:31 — forked from thezawzaw/logging-grafana-loki.md
Centralized Logging with Grafana Loki and Promtail

Centralized Logging Setup with Grafana Promtail and Loki

This page describes how to setup Grafana Promtail and Loki for sending the contents of local logs to the centralized Grafana Loki server or Grafana Cloud.

Prerequisties

  • Docker Engine
  • Docker Compose

Setup Grafana Loki

@ohbob
ohbob / log2
Last active May 22, 2025 20:33
log2 - Log forwarder to Loki with automatic log level detection
#!/bin/bash
# --- Defaults ---
JOB_NAME=""
NODE_ENV=""
LOKI_URL="http://localhost:3100"
LOG_LEVEL="debug"
COMMAND_ARGS=()
BUFFER_SIZE=100
FLUSH_INTERVAL=5
@ohbob
ohbob / somafm.py
Created May 11, 2025 22:14
xfce tray somafm, radio + download current song with spotdl
#!/usr/bin/env python3
import gi
gi.require_version("Gtk", "3.0")
gi.require_version("AppIndicator3", "0.1")
from gi.repository import Gtk, GLib, AppIndicator3
import subprocess
import requests
import os
import signal
@ohbob
ohbob / debounce.ts
Created October 22, 2024 17:47
debounce
const debounce = <T extends (...args: any[]) => any>(
fn: T,
delay: number
): ((...args: Parameters<T>) => void) => {
let timeoutId: NodeJS.Timeout;
return (...args) => {
clearTimeout(timeoutId);
timeoutId = setTimeout(() => fn(...args), delay);
};
@ohbob
ohbob / settings.json
Created June 7, 2024 20:37 — forked from MiraiSubject/settings.json
Svelte custom label
{
"workbench.editor.customLabels.patterns": {
"**/src/routes/+page.svelte": "Root Page",
"**/src/routes/+layout.svelte": "Root Layout",
"**/src/routes/+page.ts": "Root Page Data (Universal)",
"**/src/routes/+page.server.ts": "Root Page Data (Server)",
"**/src/routes/+layout.server.ts": "Root Layout Data (Server)",
"**/src/routes/+layout.ts": "Root Layout Data (Universal)",
"**/src/routes/*/**/+page.svelte": "${dirname} - Page",
"**/src/routes/*/**/+layout.svelte": "${dirname} - Layout",
@ohbob
ohbob / docker-compose.yml
Created May 23, 2024 16:08
duplicati docker yml
version: '3.0'
services:
duplicati:
image: 'lscr.io/linuxserver/duplicati:latest'
environment:
- SERVICE_FQDN_DUPLICATI # Assign a FQDN so I can access it remotely
- PUID=0 # Important - sets it to access the host file system as root
- PGID=0 # Important - sets it to access the host file system as root
- TZ=Europe/London # Change this to your server's timezone
- CLI_ARGS=
@ohbob
ohbob / discord.py
Created December 3, 2022 12:16
discord class
#!/usr/bin/python
from urllib.request import Request, urlopen
import json
class Discord:
def __init__(self, webhook: str, botname: str = "April O'Neil",
avatarurl: str = "https://i.pinimg.com/originals/87/67/11/876711e56a0ef942cbb2f15844235f2e.jpg"):
self.webhook = webhook
import requests
from bs4 import BeautifulSoup
def download_file(download_url, filename):
r = requests.get(download_url)
with open(f"MagPi-{filename}.pdf", "wb") as code:
print(f"Downloading => {filename} issue")
code.write(r.content)
@ohbob
ohbob / telegram_webhook.py
Created February 17, 2022 21:37
Send message or image to telegram
token = "#" # MYBOT TOKEN
channel = "#" # MY ID
import requests
def sendtochannelphoto(_token, _channel, image_path, image_caption=""):
data = {"chat_id": _channel, "caption": image_caption}
url = f"https://api.telegram.org/bot{_token}/sendPhoto?" \
f"chat_id={_channel}"