Skip to content

Instantly share code, notes, and snippets.

<?php
namespace Phpcraft;
require "vendor/autoload.php";
$bits_per_block = 5;
$bits = "";
foreach([1, 2, 2, 3, 4, 4, 5, 6, 6, 4, 8, 0, 7, 4, 3, 13, 15, 16, 9, 14, 10, 12, 0, 2, 11, 4] as $value)
{
$bits .= strrev(str_pad(decbin($value), $bits_per_block, "0", STR_PAD_LEFT));
}
@timmyRS
timmyRS / mcast_recv.php
Last active May 23, 2021 20:41
Minecraft LAN world sender & receiver in PHP
<?php
$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP) or die("Failed to create socket.\n");
socket_set_option($socket, IPPROTO_IP, MCAST_JOIN_GROUP, [
"group" => "224.0.2.60",
"interface" => 0
]);
socket_bind($socket, "0.0.0.0", 4445) or die("Failed to bind.\n");
$msg_regex = '/^\[MOTD\]([^\[\]]+)\[\/MOTD\]\[AD\]([0-9]{4,5})\[\/AD\]$/';
while(true)
{
@timmyRS
timmyRS / bigtest.snbt
Created August 7, 2019 05:42
bigtest.nbt converted to SNBT using Minecraft 1.14.4's built-in NBT -> SNBT converter
{
shortTest: 32767s,
longTest: 9223372036854775807L,
byteTest: 127b,
"byteArrayTest (the first 1000 values of (n*n*255+n*7)%100, starting with n=0 (0, 62, 34, 16, 8, ...))": [B; 0B, 62B, 34B, 16B, 8B, 10B, 22B, 44B, 76B, 18B, 70B, 32B, 4B, 86B, 78B, 80B, 92B, 14B, 46B, 88B, 40B, 2B, 74B, 56B, 48B, 50B, 62B, 84B, 16B, 58B, 10B, 72B, 44B, 26B, 18B, 20B, 32B, 54B, 86B, 28B, 80B, 42B, 14B, 96B, 88B, 90B, 2B, 24B, 56B, 98B, 50B, 12B, 84B, 66B, 58B, 60B, 72B, 94B, 26B, 68B, 20B, 82B, 54B, 36B, 28B, 30B, 42B, 64B, 96B, 38B, 90B, 52B, 24B, 6B, 98B, 0B, 12B, 34B, 66B, 8B, 60B, 22B, 94B, 76B, 68B, 70B, 82B, 4B, 36B, 78B, 30B, 92B, 64B, 46B, 38B, 40B, 52B, 74B, 6B, 48B, 0B, 62B, 34B, 16B, 8B, 10B, 22B, 44B, 76B, 18B, 70B, 32B, 4B, 86B, 78B, 80B, 92B, 14B, 46B, 88B, 40B, 2B, 74B, 56B, 48B, 50B, 62B, 84B, 16B, 58B, 10B, 72B, 44B, 26B, 18B, 20B, 32B, 54B, 86B, 28B, 80B, 42B, 14B, 96B, 88B, 90B, 2B, 24B, 56B, 98B, 50B, 12B, 84B, 66B, 58B, 60B, 72B, 94B, 26B, 68B, 20B, 82B, 54B, 36B, 28B, 30B, 42B, 64B, 96B,
@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
@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 / 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 / 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 / False Positive Reporting E-Mails and Forms.md
Last active January 26, 2023 18:34
A list for quickly reporting false positives.
@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 / 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);