Skip to content

Instantly share code, notes, and snippets.

View eksiscloud's full-sized avatar

Jakke Lehtonen eksiscloud

View GitHub Profile
@eksiscloud
eksiscloud / varnish_manual_purge.sh
Created June 23, 2025 13:49
Makes manually purge in Varnish using xkeys, can used with several hosts
#!/bin/bash
# chmod +x purge.sh
# DEFAULT
DEFAULT_DOMAIN="1.example.tld"
# MANUAL
function usage() {
echo "Use:"
@eksiscloud
eksiscloud / wordpress_auto_purge.php
Last active June 23, 2025 13:45
Sends a request to Varnish for bans after a WordPress post is edited and re-published
// Use snippets plugin or functions.php
// Adds xkey tags: frontpage, sidebar (right), article-ID, category and tag
// Remember to change url
add_action('save_post', function ($post_id) {
// Don't do anything is this isn't an article or is autosaving
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return;
if (get_post_type($post_id) !== 'post') return;
$tags = [];
@eksiscloud
eksiscloud / wordpress_add_xkey_header.php
Last active June 23, 2025 13:43
Adds X-Cache-Keys header to Wordpress posts, uses few xkey-tags
// Add Xkey-based X-Cache-Tags headers
add_action('send_headers', function () {
if (is_admin() || is_user_logged_in()) {
return;
}
$tags = [];
// Frontpage
if (is_front_page()) {
@eksiscloud
eksiscloud / generate-snapshot.py
Created June 22, 2025 19:48
Creates copy of wanted sites for emergencies
#!/bin/bash
# Nicknames, urls and snapshot directories
case "$1" in
example)
DOMAIN="www.example.com"
TARGET_DIR="/var/www/emergency/example"
;;
try)
DOMAIN="try.example.tld"
@eksiscloud
eksiscloud / generate_audio_article.py
Created June 21, 2025 20:50
AI creates MP3 where it reads WordPress article
#!/usr/bin/env python3
import os
import re
import sys
import json
import httpx
import tempfile
import configparser
from langdetect import detect
@eksiscloud
eksiscloud / cache-warmer.py
Created June 18, 2025 05:32
Cache Warmer using Matomo API
#!/usr/bin/env python3
import requests
import subprocess
import tempfile
import datetime
import sys
import time
MATOMO_API_URL = "https://matomo/index.php"
TOKEN = "<long-api-key" # give right token
@eksiscloud
eksiscloud / error_reporter.py
Created June 11, 2025 12:22
Flask-script to send notification to Discourse when error 502/503 happens
## Comments are in Finnish, sorry
#--- Rate-limiter muistiin ---
from datetime import datetime, timedelta
from zoneinfo import ZoneInfo
ALLOWED_ERROR_CODES = [502, 503, 504]
last_reported = {} # esim. {503: datetime_object}
RATE_LIMIT_HOURS = 4
@eksiscloud
eksiscloud / setup_varnish_tmpfs.sh
Created June 7, 2025 15:25
Varnish is more faster when working directory is in tmpfs. And 7.6 started nagging if not.
#!/bin/bash
# Varnish working directory location in tmpfs
TMPFS_DIR="/dev/shm/varnish"
echo "Creating directory: $TMPFS_DIR"
mkdir -p "$TMPFS_DIR"
chown -R varnish:varnish "$TMPFS_DIR"
# Path to override.conf
@eksiscloud
eksiscloud / x-cache.vcl
Created May 7, 2025 21:04
Varnish hit/miss/pass counter
sub vcl_recv {
unset req.http.x-cache;
}
sub vcl_hit {
set req.http.x-cache = "hit";
if (obj.ttl <= 0s && obj.grace > 0s) {
set req.http.x-cache = "hit graced";
}
}
@eksiscloud
eksiscloud / mastodon-update.sh
Last active March 22, 2025 06:30 — forked from Mixaill/mastodon-update.sh
Semi-automatic Mastodon updater for nightly build
#!/usr/bin/env bash
#
# Mastodon update script
# v3 (2024.02.18)
# forked
#
# Changelog
# * v1 - initial version
# * v2 - added mastodon-bird-ui