Skip to content

Instantly share code, notes, and snippets.

View vijinho's full-sized avatar

Vijay vijinho

  • England
View GitHub Profile
@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)
*/
@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 / 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 / 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 / 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 / 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 / ytdlmp3-post-process.php
Last active September 6, 2018 13:21
post-processing of filenames into mp3 tags from download output of https://gist.github.com/vijinho/645786c3ab8133d49ca9ef9b50a3944f
#!/usr/bin/php
<?php
// counterpart to https://gist.github.com/vijinho/645786c3ab8133d49ca9ef9b50a3944f
// for post processing filenames
$cmd = 'find . -type f -iname "*.mp3" -depth 1 -print';
$files = cmd_execute($cmd);
sort($files);
$data = $tags = [];
foreach ($files as $j => $path) {
@vijinho
vijinho / rsync-clone-system.sh
Last active January 6, 2025 11:01
rsync with the options I used to clone a root linux filesystem from one disk to another
time $(which rsync) \
--archive \
--checksum \
--super \
--stats \
--acls \
--hard-links \
--xattrs
@vijinho
vijinho / ytdlmp3.sh
Last active November 12, 2019 04:19
yt download to mp3 (use -s to test, remove caffeinate if not macos), post-processing with https://gist.github.com/vijinho/c8e2abd174d1d9ae71541c9007da701a
caffeinate -i youtube-dl --yes-playlist --download-archive archive.log -r 256k \
--skip-unavailable-fragments --playlist-random --write-info-json \
--write-description --no-check-certificate \
--sleep-interval 10 --max-sleep-interval 50 --merge-output-format mp4 \
--audio-format mp3 --audio-quality 0 --extract-audio --embed-thumbnail \
--ignore-errors \
$1
# see https://gist.github.com/vijinho/c8e2abd174d1d9ae71541c9007da701a for post-processing
@vijinho
vijinho / small_images.php
Created September 2, 2018 04:25
find small jpg images
<?php
// find small jpeg images
$cmd = 'find . -type f -iname "*.jp*" -print';
$files = cmd_execute($cmd);
$counts = [];
$by_size = [];
foreach ($files as $k => $path) {
$data = getimagesize($path);