Skip to content

Instantly share code, notes, and snippets.

@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
@greg-randall
greg-randall / form-double-sender.js
Created July 18, 2023 13:24
I needed to send a form's data to two different locations, we couldn't edit the site, but could have them add javascript. The script scrapes out the current form action and adds a field for the page's URL. When the form is submitted, we send the data to the second submit location (set on line #22), then remove the page url field (since we don't …
var form = document.getElementById("form-id"); //get the form for modifications we need to make
//get the form action and then remove the form action so we can control when the form is sent
var action = form.action;
form.action = "";
console.log(`action: ${action}`);
//create a hidden field for getting the page url,
//since in php the HTTP_REFERER/HTTP_ORIGIN in PHP only returns domain
var hiddenInput = document.createElement("input");
@greg-randall
greg-randall / kill_php_123_abc.php
Created May 17, 2023 20:17
Gets a list of processes, if they are php processes, it tries to kill them. Good way to temporarily drop memory usage on a server if you are having issues.
<pre>
<?php
$output=null;
$retval=null;
$return=null;
exec('ps aux', $output, $retval);
foreach ($output as $line){
$line = preg_replace('/\s+/', ' ', $line);
$line = explode(' ',$line);
if($line[10]=="lsphp"){
@greg-randall
greg-randall / gist:2156825a4151e19ef8961a6197694d94
Created December 12, 2022 15:11
Search for a string in filename/foldernames using PHP
<?php
$search_string = ".bak";
$count = 0;
$output = "";
$root = '.';
$iter = new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $root, RecursiveDirectoryIterator::SKIP_DOTS ), RecursiveIteratorIterator::SELF_FIRST, RecursiveIteratorIterator::CATCH_GET_CHILD );
$i=0;
foreach ( $iter as $path => $dir ) {
if( stripos($dir->__toString(),$search_string) !== false){
@greg-randall
greg-randall / process-to-rgb.sh
Last active November 10, 2022 19:26
Skip debayering/demosaicing a raw image, split the image into separate color channels, and then combine back into a lower resolution image but with full color information for every pixel. Essentially trades spatial resolution for higher color resolution.
basename=$(b=${1##*/}; echo ${b%.*})
dcraw -D -W -4 $1
mkdir $basename
convert $basename.pgm -sample 100x50%\! -sample 50%x100\! -contrast-stretch 0x0 -compress zip $basename/r.tiff
convert \( $basename.pgm -background white -gravity northwest -splice 0x1 \) -sample 100x50%\! -sample 50%x100\! -trim -fuzz 5% -contrast-stretch 0x0 -compress zip $basename/g1.tiff
@greg-randall
greg-randall / count_files.php
Created April 15, 2022 12:52
Count the number of files per directory. Useful for hosting services that limit the number of files but not the size. Change $min_count to set the minimum number of files for a folder to be displayed.
<?php
$root = '.';
$min_count = 1000;
$iter = new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $root, RecursiveDirectoryIterator::SKIP_DOTS ), RecursiveIteratorIterator::SELF_FIRST, RecursiveIteratorIterator::CATCH_GET_CHILD );
foreach ( $iter as $path => $dir ) {
if ( $dir->isDir() ) {
$dir_count = count_files( $path );
if ( $dir_count > $min_count ) {
@greg-randall
greg-randall / .htaccess
Last active April 20, 2022 21:02
Generic htaccess to redirect http to https & www to no-www
#This part does the www to no-www redirect:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
#This part does the http to https redirect:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]