Skip to content

Instantly share code, notes, and snippets.

View vijinho's full-sized avatar

Vijay vijinho

  • England
View GitHub Profile
@vijinho
vijinho / mp3tool.php
Last active November 8, 2021 10:11
Tool to list, view and manipulate .mp3 files using PHP wrapped around command-line tools id3tool and id3v2
#!/usr/bin/php
<?php
// Script example.php
// check CLI commands are available
$commands = getCommands();
if (empty($commands)) exit;
// see https://secure.php.net/manual/en/function.getopt.php
// : - required, :: - optional
@vijinho
vijinho / array_clear.php
Last active January 6, 2025 12:59
Function in PHP to throw out empty values from an array (and optional drop values which have specified keys passed-in)
<?php
/**
* Clear an array of empty values and specified keys
*
* @param array $keys array keys to explicitly remove regardless
* @return array the trimmed down array
*/
function array_clear($array, $keys = [])
{
@vijinho
vijinho / load_save.php
Last active October 12, 2018 20:24
PHP simple load, save functions for file to php array with value and charset type conversion
<?php
/**
* Clear an array of empty values
*
* @param array $keys array keys to explicitly remove regardless
* @return array the trimmed down array
*/
function array_clear($array, $keys = [])
{
@vijinho
vijinho / debug_verbose.php
Last active January 6, 2025 11:04
output text if DEBUG or VERBOSE constant set
<?php
define('DEBUG', 1);
define('VERBOSE', 1);
// Output verbose message if VERBOSE constant is set
function verbose(string $message, mixed $data = ''): bool {
if (VERBOSE && !empty($message)) {
echo trim('[V ' . memoryUsage() . '] ' . $message) . "\n";
if (!empty($data)) {
print_r($data);
@vijinho
vijinho / ytdl.sh
Created December 30, 2018 14:07
wrapper for youtube-dl
caffeinate -i youtube-dl --yes-playlist --download-archive archive.log -r 768k \
--skip-unavailable-fragments --playlist-random --write-info-json \
--write-description --no-check-certificate --prefer-insecure \
--sleep-interval 10 --max-sleep-interval 50 \
--ignore-errors \
$1
@vijinho
vijinho / pdf-compress.php
Last active May 6, 2019 14:18
re-compress PDFs, shrinking if possible improved version of https://gist.github.com/vijinho/724ebfac4739019fd36baa2ab8e2aca2 just run ‘php /path/to/pdf-compress.php’ in current working directory to re-compress all PDFs within
<?php
/**
* pdf-compress.php - re-compress PDFs, shrinking if possible
* WARNING: May run extremely slowly due to very large file sizes generated on pdf2ps
*
* relies on command-line tools, tested on ubuntu.
*
* @license GPLv3 (http://www.gnu.org/licenses/gpl-3.0.html)
*/
<?php
/**
* pdf-compress.php - re-compress PDFs, shrinking if possible
* WARNING: May run extremely slowly due to very large file sizes generated on pdf2ps
*
* relies on command-line tools, tested on ubuntu.
*
* @license GPLv3 (http://www.gnu.org/licenses/gpl-3.0.html)
*/
@vijinho
vijinho / pdf_rename_metadata.php
Last active April 25, 2019 11:31
get metadata from file using exiftool https://www.sno.phy.queensu.ca/~phil/exiftool/#filename and compare to previous metadata file to see savings of filesize
<?php
/**
* pdf_rename_metadata.php - get metadata from files readable with exiftool and rename
* creates 2 cache files, metadata.ser and metadata.old.ser
* where old.ser is the old version of metadata.ser for comparison
*
* https://www.sno.phy.queensu.ca/~phil/exiftool/#filename
* see https://www.sno.phy.queensu.ca/~phil/exiftool/exiftool_pod.html
*
* relies on command-line tools, tested on MacOS.
@vijinho
vijinho / get_exiftool_metadata.php
Last active April 25, 2019 20:35
Get the exif(tool) metadata for a file
<?php
/**
* get-metadata.php - get metadata from files readable with exiftool
* creates 2 cache files, metadata.ser and metadata.old.ser
* where old.ser is the old version of metadata.ser for comparison
*
* https://www.sno.phy.queensu.ca/~phil/exiftool/#filename
* see https://www.sno.phy.queensu.ca/~phil/exiftool/exiftool_pod.html
*
* relies on command-line tools, tested on MacOS.
@vijinho
vijinho / pdf-rename.php
Last active May 3, 2019 00:17
Finds a list of files readable with exiftool (used for PDFs mainly) and present renaming/view options for MacOS
<?php
/**
* get-rename.php - get metadata from files readable with exiftool
* and presents options for renaming
* creates cache files, metadata.ser
*
* https://www.sno.phy.queensu.ca/~phil/exiftool/#filename
* see https://www.sno.phy.queensu.ca/~phil/exiftool/exiftool_pod.html
*
* relies on command-line tools, tested on MacOS.