Skip to content

Instantly share code, notes, and snippets.

View vijinho's full-sized avatar

Vijay vijinho

  • England
View GitHub Profile
@vijinho
vijinho / pdf-linearize.php
Last active August 17, 2023 16:00
use qpdf to linearize a bunch of pdf files
<?php
/**
* pdf-linearize.php - linearize PDFs
* 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 / calibre-rename-jdupes.php
Created May 5, 2019 22:53
Find/remove duplicate files in subfolders and move/rename files exported from calibre ebook application folder in OPF files.
<?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.
@vijinho
vijinho / pdf-rename-auto.php
Created May 6, 2019 14:21
automatically rename PDF files found as: year - title - author(s)
<?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.
@vijinho
vijinho / files-by-type.php
Created May 7, 2019 14:34
list files by type
#!/usr/bin/php
<?php
/**
* files-by-type.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
*
@vijinho
vijinho / disk-set-sleep-time.sh
Last active January 6, 2025 11:14
Clear standby mode and set the disk sleep-time in Linux
#!/bin/bash
# Function to check if a device file exists and is an HDD
is_valid_device() {
if ! test -b "$DEVICE"; then
echo "Error: '$DEVICE' is not a valid block device."
return 1
fi
if ! grep -q "$DEVICE" /proc/partitions; then
@vijinho
vijinho / directory-tree-clone.sh
Last active January 6, 2025 11:23
Clone a directory tree structure without the files
#!/bin/bash
# Function to show help
usage() {
echo "Usage: $0 [-h] -s <source> -d <destination>"
echo " -h, --help Show this help message and exit."
echo " -s, --source Specify the source directory or file."
echo " -d, --destination Specify the destination directory."
return 1
}
@vijinho
vijinho / transliterate_files.php
Created December 25, 2019 02:48
Display transliterated files and folders to non-accented ASCII characters script - rename feature tested successfully with a filesystem of over 65,000 files - USE AT OWN RISK!
#!/usr/bin/php
<?php
// show and optionally rename files and dirs to transliterated unaccented ascii from current working folder
// 2019-12-24 Vijay Mahrra [email protected]
// code is public domain
define('DEBUG', true); // use pre-generated file list
define('VERBOSE', true);
define('RENAME', false); // allow renaming
define('RENAME_FILES', false);
@vijinho
vijinho / adb-backup.sh
Last active January 6, 2025 11:32
Backup all Android apps and data using adb, excluding system apps
#!/bin/bash
# Function to handle errors and log them
handle_error() {
echo "Error: $1" >> backup.log
exit 1
}
# Check if adb is available
command -v adb >/dev/null 2>&1 || {
@vijinho
vijinho / macos-set-hostname.sh
Last active January 6, 2025 10:25
script to set the hostname in macOS using scutil for HostName, LocalHostname, ComputerName to the same value
#!/bin/bash
# Function to display usage information
usage() {
echo "Usage: $0 <new-hostname>"
exit 1
}
# Check if the user has provided a hostname argument
if [ $# -eq 0 ]; then
@vijinho
vijinho / markdown_escape.php
Last active February 13, 2025 16:12
Return a given string with the text markdown escaped, in PHP
<?php
/**
* Escape markdown text
*
* @param string $text The markdown text to escape
*
* @return string Escaped text
*/
function markdown_escape($text) {
// Define a regex pattern for all special characters in markdown