Skip to content

Instantly share code, notes, and snippets.

@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"
@greg-randall
greg-randall / run.sh
Created October 20, 2023 17:31
Diffs sites looking for changes to see if someone has posted a new job.
#!/bin/bash
# create a file 'config.sh' where you set two variables one is your phone number the other is an api key from https://textbelt.com/
#phone=##########
#apikey=#######################################
#the tool read through a file called "sites-to-diff.txt" which is a list of sites with one url per line.
source config.sh #get phone number & api key
@greg-randall
greg-randall / gist:8581eec1bb492d1fe107fbd17d49da8b
Created September 6, 2023 18:51
Quick curl to get alt text for an image using https://alttext.ai/. Create an account to get an API key.
curl https://alttext.ai/api/v1/images \
-s \
-X POST \
--header "X-Api-Key:API-KEY" \
-H 'Content-Type: application/json' \
-d "$( printf "{ \"image\": { \"raw\": \"$(base64 test.jpg)\" } }" )" \
| jq \
| grep -i alt_text \
| perl -pe 's/^[^"]*"[^"]*"[^"]*"([^"]*)".+/$1/i'
@greg-randall
greg-randall / wave-screenshotter.js
Created August 24, 2023 15:47
Generate a screenshot and csv of A11y errors from a list of URLs.
//pass a text file with one url per line:
//node wave-screenshotter.js urls.txt
const fs = require( 'fs' );
//get the arguments from the terminal
const myArgs = process.argv.slice( 2 );
@greg-randall
greg-randall / generate_audiobook.sh
Last active May 9, 2024 20:06
Audiobook Generator. Takes a text file, splits it up into chunks, runs it through the Edge-TTS, combines the files into a single wav file, and then reencodes into an Opus files for minimum size/maximum quality.
#!/bin/bash
# takes a text file and makes an audiobook of it ex:
# ./generate_audiobook.sh input_book.txt
# a few notes,
# first, you'll need to install edge-tts (pip3 install edge-tts), sox (sudo apt-get install sox), and