Skip to content

Instantly share code, notes, and snippets.

View ToshY's full-sized avatar
🤔
I don't know everything. I just know what I know.

ToshY

🤔
I don't know everything. I just know what I know.
View GitHub Profile
@ToshY
ToshY / randomString.php
Last active May 6, 2019 10:32
Create a random alphanumeric string
<?php
function gRS($length, $opt = '111') {
$r = '';
//numbers only
$r .= ( ( (int) $opt[0] === 1) ? '012345678923456789' : '');
//numbers with small letters
$r .= ( ( (int) $opt[1] === 1) ? 'abcdefghijklmnopqrstuvwxyz' : '');
//numbers with small and capital letters
$r .= ( ( (int) $opt[2] === 1) ? 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' : '');
@ToshY
ToshY / batchregex.ps1
Last active June 26, 2019 20:54
Batch rename files with regex replace
<#
.SYNOPSIS
Batch rename files with regex replace
.DESCRIPTION
BATCHREGEX makes it easy to batch rename your files using regex. Supply the directory of the files you need to rename; supply the regex expression you want applyp;
supply the new file names (including capturing groups as `$1, `$2, etc.; please note the backtick). Some experience with regex would be nice before using this.
Please note that the default mode for $safe_mode = 1, which means that it will show what happens when you'd rename the files but it will NOT execute the command.
When setting $safe_mode = 0, your regex will be executed so there's no turning back...
.EXAMPLE
In the following examples, pretend we have the following files "MyAwesomeVideo - 01 (somerubbish).mp4",..., "MyAwesomeVideo - 50 (somerubbish).mp4"
@ToshY
ToshY / cleanASS.ps1
Created August 31, 2019 10:10
Clean ASS files by removing unused styles
# The directory of the ASS files that need to be cleaned
$dir = "C:\Users\Kintoki\Desktop\ASS_files"
$files = Get-ChildItem "$dir" | Where-Object {$_.Extension -eq ".ass"}
#Start batch loop
for ($i=0; $i -lt $files.Count; $i++) {
$subs = $files[$i].FullName
$ASS = Get-Content -LiteralPath $subs
Write-Host ('>> File: ' + $files[$i].BaseName)
#Remove non-used styles
@ToshY
ToshY / get_metadata.py
Last active May 7, 2020 19:50
FFprobe file metadata (Python 3.x)
# Use FFprobe to get file metadata, e.g. streams, tags, etc., in JSON format
import json
import subprocess as sp
def get_file_metadata(input_file):
return json.loads(sp.check_output(["ffprobe","-v","quiet","-print_format","json","-show_streams","-show_format",input_file]).decode('utf-8'))
file_metadata = get_file_metadata(r"D:\hello_world.mp4")
@ToshY
ToshY / addNewFonts.ps1
Last active May 9, 2020 13:46
Adds new fonts from specified directory
# "Automatically" adds font but for some reason it still needs user interaction when the file already exists
function addNewFonts{
Param(
[Parameter(Mandatory=$true)]
[string]$dir
)
if($dir[-1] -ne [IO.Path]::DirectorySeparatorChar){$dir = $dir + [IO.Path]::DirectorySeparatorChar}
$fonts = (New-Object -ComObject Shell.Application).Namespace(0x14)
Get-ChildItem -Path ($dir + '*') -Include @('*.ttf','*.otf') | % { $fonts.CopyHere($_.fullname, 16) }
@ToshY
ToshY / change_metadata.py
Last active May 18, 2020 13:15
Exiftool for changing metadata (Python 3.x)
# Change metadata like Title, Comment, Description, by using Exiftool
# Tested with ExifTool 11.98 on Win10 and Ubuntu 18.04
import subprocess as sp
def change_file_metadata(input_file, meta_dict={'-Title':'','-Comment':''}):
return sp.check_output(["exiftool", "-api", "largefilesupport=1", "-overwrite_original"] + [ '{}={}'.format(k,v) for k, v in meta_dict.items() ] + [input_file])
change_file_metadata(r"D:\hello_world.mp4",{'-Title':'Hello Darkness','-Comment':'My Old Friend'})
# b' 1 image files updated\r\n'
@ToshY
ToshY / m3u8tomp4.md
Last active May 24, 2020 23:42
FFmpeg m3u8 to mp4
ffmpeg -i in.m3u8 -acodec copy -bsf:a aac_adtstoasc -vcodec copy out.mp4
@ToshY
ToshY / random_string.ps1
Created August 5, 2020 19:08
Random string with PS
[CmdletBinding()]
<#
.SYNOPSIS
Create a random string of alphanumeric characters
.DESCRIPTION
This function creates a random string of alphanumeric characters.
Alphanumeric characters are put into an array, joined, randomly picked and shuffled once more.
.PARAMETER length
The length of the random string to be returned.
@ToshY
ToshY / SimpleMailJetSender.php
Created September 5, 2020 17:50
Simple MailJet API v3 email sender in PHP
<?php
class MailJetAPI{
/*
* Simpel MailJet mailer with the v3 API
*/
private const BASE_URL = 'https://api.mailjet.com/v3.1/send';
private $key;
private $secret;
@ToshY
ToshY / OneWayEncryption.php
Last active September 5, 2020 17:52
Simple one-way encryption in PHP
<?php
class OneWayEncryption{
/*
* One way encryption; hash + salt
*/
private const COST = '14';
private function uniqueSalt() {