Skip to content

Instantly share code, notes, and snippets.

View 5-bits-per-block.php
<?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));
}
View the-index.md
Points Held Bonus Total Efficiency
1 +0 1 +0%
2 +0 2 +0%
3 +0 3 +0%
4 +0 4 +0%
5 +2 7 +40%
6 +2 8 +33.333333333333%
7 +2 9 +28.571428571429%
8 +2 10 +25%
@timmyRS
timmyRS / mcast_recv.php
Last active May 23, 2021
Minecraft LAN world sender & receiver in PHP
View mcast_recv.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 Aug 7, 2019
bigtest.nbt converted to SNBT using Minecraft 1.14.4's built-in NBT -> SNBT converter
View bigtest.snbt
{
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 Sep 15, 2019
A batch script to add your folder to %PATH% avoiding the 1024 character limit.
View add_to_path.bat
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 Nov 24, 2022
Generates Minecraft-style SHA1 hashes in PHP.
View mcsha1.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)
View make-json-pretty-again.php
<?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 Apr 17, 2018
An efficient PHP script using GMP to calculate factorials.
View fac.php
<?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 Mar 14, 2018
A list for quickly reporting false positives.
View False Positive Reporting E-Mails and Forms.md
@timmyRS
timmyRS / 1-Route.md
Last active Oct 30, 2017
The 1-Route Protocol: Reach the unreachable.
View 1-Route.md

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