Skip to content

Instantly share code, notes, and snippets.

@greg-randall
greg-randall / page_pull.py
Created April 15, 2024 17:32
Try several methods of getting a webpage, starting with just a basic page download, then using lynx, then using Pyppeteer which runs Chrome.
import requests
import asyncio
from termcolor import cprint
from pyppeteer import launch
from pyppeteer_stealth import stealth
import subprocess
def page_content_vaild(page_content):
excluded_strings = ["Page Not Found", "Human Verification", "About Lynx"]
@greg-randall
greg-randall / gist:a1b02ee046f50d47fa6f2e543ac04085
Created April 6, 2024 12:03
Convert a folder one m4b at a time to opus. Edit line 4 for more or less any file format that contains audio.
#!/bin/bash
# Loop over all m4b files in the current directory
for input in *.m4b
do
# Print a message indicating the file being processed
echo "Processing file $input..."
# Use ffmpeg to convert the m4b file to a wav file
ffmpeg -i "$input" "${input%.*}.wav"
@greg-randall
greg-randall / do_gutenberg.php
Created February 26, 2024 20:35
Works like "do_shortcode" but for Gutenberg blocks.
function do_gutenberg( $content ) {
$output_rendered = "";
$parsed_blocks = parse_blocks( $content );
if ( $parsed_blocks ) {
foreach ( $parsed_blocks as $block ) {
$output_rendered .= apply_filters( 'the_content', render_block( $block ) );
}
}
return ( $output_rendered );
}
@greg-randall
greg-randall / lat-lon-mon.py
Created February 25, 2024 01:00
Human Readable Moon Phase from Latitude & Longitude
from datetime import datetime
from skyfield.api import load
from skyfield.framelib import ecliptic_frame
from tzfpy import get_tz
import pytz
def human_moon(lat, lon):
ts = load.timescale()
# Get the current time in the specified timezone
@greg-randall
greg-randall / index.php
Created February 15, 2024 22:16
Database table to CSV dumper. Add info at the top to connect to your database/table etc.
<?php
// Dumps a database table out to the screen or out a csv file.
// add ?download=true to the url to download the file
// Database credentials, table, filename, and timezone
$db_host = "";
$db_user = "";
$db_pass = "";
$db_name = "";
@greg-randall
greg-randall / gtn-brgr-upgrdr.php
Last active February 6, 2024 20:22
Use to swap from bootstrap WordPress pages to Gutenberg. MAKE BACKUPS BEFORE YOU USE!!!! More Below...
<?php
/**
* Plugin Name: Gutenburger Upgrader
* Author: Greg R.
* Version: 0.0.1
*/
/*
This plugin tries to clean html up so that it can be directly converted into gutenberg as blocks.
@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)