Skip to content

Instantly share code, notes, and snippets.

@greg-randall
greg-randall / codec-reader.py
Last active October 29, 2024 05:49 — forked from Steve-Tech/codec-reader.py
Codec Reader for HTML Video Tags, gets the correct codecs parameter for AV1, HEVC (H.265), and H.264 videos.
import json
import mimetypes
import subprocess
import sys
# Codec Reader for HTML Video Tags by Steve-Tech
# Usage: python3 codec-reader.py [-d] file_name
# Requires ffmpeg and ffprobe to be installed.
#
# Supported Codecs:
@greg-randall
greg-randall / role-limiter.php
Created June 12, 2024 18:50
WordPress plugin to limit editing of pages and their children to certain user roles.
<?php
/**
* Plugin Name: Role-Based Page Editor Limitations
* Description: This plugin restricts editing capabilities of specific pages to certain user roles. It dynamically creates roles if they don't exist and assigns them editor capabilities. It then checks if a user with a specific role is trying to edit a page that they're not assigned to, and if so, it removes their editing capabilities for that page. Edit the $role_page_map array to specify which roles can edit which pages.
* Version: 1
* Author: Greg R.
*/
/* For example you want to make it so that some peolple at your company can edit /subpage/ and all the children under that page, so you can create a user role that restricts them to jus that section of the site. */
@greg-randall
greg-randall / crop-to-face.py
Created June 5, 2024 19:58
Crops a folder of headshots to the face that it finds in the image.
import os
import cv2
import matplotlib.pyplot as plt
from PIL import Image
# adjust these variables as necessary
dirname = "pix-for-crop"
put_dirname = "cropped"
simple_crop = False
@greg-randall
greg-randall / trim_old.py
Last active September 17, 2024 14:30
Remove items that aren't from 2024 from a wordpress export.
import xml.etree.ElementTree as ET
# Parse the XML file and get the root
tree = ET.parse('wordpress_export.xml')
root = tree.getroot()
# Find the <channel> element
channel = root.find('channel')
total = 0
@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.