Skip to content

Instantly share code, notes, and snippets.

@greg-randall
greg-randall / gist:b6dbcb64c90b78c3e17efba19ff9ad61
Created February 15, 2022 18:58
Save output from get/post for testing.
<?php
$data = "\n---------------------------------------------------------------------\nRaw Input:\n" . file_get_contents("php://input");
$data .= "\n\nGet:\n". print_r($_GET,true);
$data .= "\nPost:\n". print_r($_POST,true);
file_put_contents( "log-output-test.txt", $data , FILE_APPEND | LOCK_EX );
@greg-randall
greg-randall / site_map.sh
Last active March 9, 2022 14:40
Generate a list of all the urls on a website. Ignores common files like jpg, pdf, js, css, etc.
#example: ./site_map.sh asdf.com
SITE=$1
URLS="$1_urls.txt"
echo -e "Starting Sitemap Generation===============================================\n"
echo "" > site_url_list_raw.txt
@greg-randall
greg-randall / site_scooper.sh
Last active May 23, 2023 20:12
Site Scooper. Give the script a URL and it'll build a list of pages on the site and then download and render the pages using chromium. Built off my Site Map gist. You'll probably need to install chromium, but otherwise the tools are pretty standard.
#example: ./site_scooper.sh asdf.com
#if it doesn't work, check your url, and see if it redirects from asdf.com to www.asdf.com, and retry with www.asdf.com
SITE=$1
URLS="$1_urls.txt"
echo -e "Starting Sitemap Generation===============================================\n"
echo "" > site_url_list_raw.txt
@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]
@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 / 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 / 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 / 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 / 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 / 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