Skip to content

Instantly share code, notes, and snippets.

@greg-randall
greg-randall / splittums.py
Created February 2, 2024 21:11
Real basic way of splitting WordPress XML/WXR files. Set filename and number of items per split on lines 5 & 6.
import os
import sys
input_file = 'wordpress_export_file.xml'
item_per_output_file = 500
with open(input_file, 'r') as file:
content = file.read()
@greg-randall
greg-randall / gist:64490892ae44ec632041082ad6ea5176
Created January 31, 2024 14:02
WordPress shortcode to export a site, useful if your site is super locked down.
function export_all_posts() {
// Ensure the export function is available
if (!function_exists('export_wp')) {
require_once ABSPATH . 'wp-admin/includes/export.php';
}
// Start output buffering
ob_start();
// Call the export function
Remove bold/strong from all headings:
f: (<h(\d)[^>]*>)\s*<(b|strong)>([^<]*)</\3>\s*(</h\2>)
r: $1$4$5
notes: wont work on headings with links or other tags inside the heading.
@greg-randall
greg-randall / gist:009817414b928051da96738b0bd15273
Last active January 18, 2024 14:06
Takes a class graduation headshot composite, splits the photos apart & OCRs the names. Probably have to tweak name crop spacing for your image.
import cv2
import numpy as np
import pytesseract
# Load the image
image = cv2.imread('2021.jpg')
# Convert the image to gray scale
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
@greg-randall
greg-randall / gen.py
Last active December 20, 2023 15:07
Generate a timeline of screenshots from a video 'vid.mp4' and subtitles 'subs.vtt'. Use yt-dlp or similar to collect your subs and video.
import webvtt
from collections import defaultdict
import cv2
import glob
import os
from pprint import pprint
sub_files = glob.glob('*.srt')
sub_files.append( glob.glob('*.vtt') )
#print(sub_files)
@greg-randall
greg-randall / avg.py
Created December 4, 2023 14:20
Smooth timelapses by averaging frames. Full notes below.
#Averages a number of frames from your timelapse to create a smoother output.
#The number of frames you might want to average depends on the issues you're running into, but
#if you average too many it will make the world look like it's melting, and its slow.
#My timelapses tend to be multiday, and have long shooting intervals(5-20 minutes), so 6 frames
#averaged covers the day/night and night/day transition pretty well. 6-24 might be a reasonable range,
#but I would test ~10 seconds of frames at different averages, maybe try 6, 12, & 24.
#Place in a folder of JPGs that will sort correctly with a natsort,
@greg-randall
greg-randall / mozjpeg.sh
Created November 28, 2023 17:22
Compress jpgs with MozJpeg recursively.
#!/bin/bash
#convert pngs to jpg
#find . -type d -exec bash -c 'cd "{}" && mogrify -format jpg *.png' \;
#find . -type f -name '*.png' -delete
#convert gifs to jpg
#find . -type d -exec bash -c 'cd "{}" && mogrify -format jpg *.gif' \;
#find . -type f -name '*.gif' -delete
@greg-randall
greg-randall / llm_page.py
Last active April 19, 2024 18:37
Generate a headline, keywords, based on some values if you should read the article or not, plus a summary of a given article.
# run like:
# python3 llm_page.py "https://www.cnn.com/2023/12/09/business/cosmcs-mcdonalds-drinks/index.html"
# you can optionally pass in a debug flag as the second argument, like:
# python3 llm_page.py "https://www.cnn.com/2023/12/09/business/cosmcs-mcdonalds-drinks/index.html" True
import json
import requests
from termcolor import cprint
from collections import OrderedDict
from readability import Document
@greg-randall
greg-randall / ssl-checker.sh
Last active November 9, 2023 16:49
Checks a list of sites for SSL expiration and texts you.
#!/bin/bash
#Reads a text file -- domains.txt -- containing one domain per line and checks to see if the ssl cert is expiring in the next 30 days
#Config varaiables,
#days is the number of days you'll get an alert for,
#phone number
#api key from https://textbelt.com/
days=30
phone="##########"
@greg-randall
greg-randall / check_freezing_temps.py
Last active November 1, 2023 19:14
Checks if the temperatures will be freezing in your area over the next 24hrs and texts you if there are freezing temps. I have mine set to run at 7:00am on a cron job.
#########SETUP#########
#textbelt_key: you get one free text per day with the key 'textbelt' or if you think you need more get an api key from https://textbelt.com/
#phone_numbers: a single phone number as a list, just the digits, or if you want to send to multiple people, add addtional numbers in the list
#lat_lon: your latitude and longitude in the format "xxx.xxxx,-xxx.xxxx". https://mapper.acme.com/ is helpful here, though note to change the formatting (ie "N 45.52300 W 122.67600" to "45.52300,-122.67600")
#freezing_notification_temp: default is that you will be notified for temperatures at or below 35, but change that if you want
textbelt_key = "textbelt"
phone_numbers = ["5555555555","5555554444"]
lat_lon = "45.52300,-122.67600"