Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
I don't know everything, I just know what I know

ToshY

💭
I don't know everything, I just know what I know
  • #0823
View GitHub Profile
@ToshY
ToshY / randomString.php
Last active May 6, 2019
Create a random alphanumeric string
View randomString.php
<?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 / createCaptcha.php
Last active Sep 5, 2020
Create an alphanumeric captcha with different text -and linecolours
View createCaptcha.php
<?php
/* Create an alphanumeric captcha the easy way - by ToshY | 05-05-2019 */
function imageCaptcha($chars = 6, $lines, $bg_colour = array('R'=>204,'G'=>153,'B'=>255), $line_colours = array(array('R'=>153,'G'=>51,'B'=>102)), $txt_colours = array(array('R'=>0,'G'=>0,'B'=>0),array('R'=>255,'G'=>255,'B'=>255)), $fonts = array('arial.ttf')){
// dimensions / fontsize based on amount of characters
$MW = round($chars * ( 100 / 3) ); $MH = round($MW / 3); $fs = round( ( 30 * (1 - exp( -0.005 * $MW ) ) ) , 2);
// init image with user dimensions
$img = imagecreatetruecolor( $MW, $MH );
@ToshY
ToshY / batchregex.ps1
Last active Jun 26, 2019
Batch rename files with regex replace
View batchregex.ps1
<#
.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 Aug 31, 2019
Clean ASS files by removing unused styles
View cleanASS.ps1
# 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 / addNewFonts.ps1
Last active May 9, 2020
Adds new fonts from specified directory
View addNewFonts.ps1
# "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 / get_metadata.py
Last active May 7, 2020
FFprobe file metadata (Python 3.x)
View get_metadata.py
# 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 / change_metadata.py
Last active May 18, 2020
Exiftool for changing metadata (Python 3.x)
View change_metadata.py
# 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 / string_incrementer.py
Last active Sep 5, 2020
Python simple string incrementer
View string_incrementer.py
# -*- coding: utf-8 -*-
"""
Created on Fri May 8 00:07:46 2020
@author: ToishY
My favorite online string increment tool "was" dead (http://www.mynikko.com/tools/tool_incrementstr.html), so I made this snippet back then.
Haven't tested it fully but seems to work.
Note:
@ToshY
ToshY / BunnyVOD.php
Last active Apr 8, 2022
BunnyCDN VOD HLS Token Authentication V2 with directory tokens
View BunnyVOD.php
<?php
/*
VOD HLS streaming for BunnyCDN with Token authentication V2
NOTES:
> Credits to Dejan from BunnyCDN Support for the function for token authentication V2
> I've created this snippet to show how to use HLS streaming with the directory tokens.
This is a workaround which works by appending the token query string for every request to the TS segments (see JS below)
@ToshY
ToshY / m3u8tomp4.md
Last active May 24, 2020
FFmpeg m3u8 to mp4
View m3u8tomp4.md
ffmpeg -i in.m3u8 -acodec copy -bsf:a aac_adtstoasc -vcodec copy out.mp4