Skip to content

Instantly share code, notes, and snippets.

@timmyRS
timmyRS / Renamer.php
Last active April 26, 2017 18:06
Rename files in a directory just the way you'd like to.
<?php
// Your configuration starts here.
// Testing. 'true' = Don't actually edit files and only output the name changes.
$testing = false;
// Folders. 'true' = Rename folders and files.
$folders = true;
// Recursive. 'true' = Also rename files in sub-directories.
@timmyRS
timmyRS / prepend.php
Last active January 22, 2023 02:45
The perfect PHP error handler.
<?php
// This changes the error handler to a more helping one.
// You must/can prepend this script - Help: http://stackoverflow.com/a/35298767/4796321
function h_error($severity, $message, $file, $line)
{
if (!(error_reporting() & $severity))
{
return;
}
@timmyRS
timmyRS / shorter.php
Created June 21, 2017 06:13
An inperfect PHP script shorter for code golfing.
<?//noshort
/* This is a little script built for php on linux to short your PHP Scripts,
* it is not, it will never and it is not trying to be perfect,
* but it might still help you with your code golfes!
*******************************************************/
if(empty($argv[1]))
{
echo "Syntax: php shorten.php <file>\n";
@timmyRS
timmyRS / Subtitle Offsetter.php
Created July 29, 2017 20:19
Poorly offsets your .srt files.
<?php
date_default_timezone_set("Etc/Utc");
$offset = -24;
$output = fopen("output.srt", "w");
foreach(file("input.srt") as $line)
{
$line = trim($line);
@timmyRS
timmyRS / 1-Route.md
Last active October 30, 2017 08:15
The 1-Route Protocol: Reach the unreachable.

The 1-Route Protocol

by Tim Speckhals

Purpose

The Purpose of the 1-Route Protocol is to allow unreachable locations to be reached anyways using a proxy server.

Use Cases

@timmyRS
timmyRS / False Positive Reporting E-Mails and Forms.md
Last active January 26, 2023 18:34
A list for quickly reporting false positives.
@timmyRS
timmyRS / fac.php
Last active April 17, 2018 21:59
An efficient PHP script using GMP to calculate factorials.
<?php
if(!isset($argv[1]))
{
die("Syntax: php fac.php <num>\n");
}
$start_time = microtime(true);
$fac = $one = gmp_init("1");
$i = gmp_init("1");
$limit = gmp_init($argv[1]);
do
@timmyRS
timmyRS / make-json-pretty-again.php
Created June 24, 2018 15:27
Make JSON pretty again
<?php
if(empty($argv[1]))
{
die("Syntax: php {$argv[0]} <file>");
}
$json = json_decode(file_get_contents($argv[1]), true);
if($json == NULL)
{
die("ERROR: Invalid JSON.");
}
@timmyRS
timmyRS / mcsha1.php
Last active January 20, 2023 02:27
Generates Minecraft-style SHA1 hashes in PHP.
<?php
/**
* Generates a Minecraft-style SHA1 hash.
* @param string $str
* @return string
*/
function mcsha1($str)
{
$gmp = gmp_import(sha1($str, true));
if(gmp_cmp($gmp, gmp_init("0x8000000000000000000000000000000000000000")) >= 0)
@timmyRS
timmyRS / add_to_path.bat
Last active September 15, 2019 10:58
A batch script to add your folder to %PATH% avoiding the 1024 character limit.
REG ADD "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /F /V PATH /T REG_SZ /D "YOUR_PATH_FOLDER;%PATH%"
:: Setting a temporary dummy variable so setx will broadcast WM_SETTINGCHANGE so the PATH change is reflected without needing a restart.
SETX /m DUMMY ""
REG DELETE "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /F /V DUMMY