Skip to content

Instantly share code, notes, and snippets.

View Muqsit's full-sized avatar
👑
A beacon of hope.

Muqsit Muqsit

👑
A beacon of hope.
View GitHub Profile
@Muqsit
Muqsit / run.php
Created April 7, 2025 05:10
PHP: Execute a python script with stdin data using proc_open() and print stdout
<?php
declare(strict_types=1);
function run_python(string $path, string $payload) : ?string{
$process = proc_open(["/usr/bin/python3", $path], [
0 => ["pipe", "r"],
1 => ["pipe", "w"],
2 => ["pipe", "w"],
], $pipes);
@Muqsit
Muqsit / nbt-tag-equals-vs-equality-operator.php
Created January 30, 2025 04:47
NBT CompoundTag::equals vs. Equality operator (PHP)
<?php
declare(strict_types=1);
use pocketmine\nbt\BigEndianNbtSerializer;
$n_runs = 100;
// wget https://gist.githubusercontent.com/Muqsit/08391495f934f5c47be0f837ac2907ab/raw/6d36652ca8b557bbaf96115a846ed25a1e45e7c6/inventory.json
$inventory = file_get_contents("/home/cosmicpe/dev/plugin_data/Scripter/inventory.json");
@Muqsit
Muqsit / apply_destructor_hooks.php
Created January 1, 2025 18:32
PHP: Apply destructor hooks to all class in a .phar file to debug memory leaks
<?php
declare(strict_types=1);
function apply_destructor_hook(string $contents) : ?string{
$destructor_body = PHP_EOL;
$destructor_body .= "echo 'Destroyed ', \$this::class,";
$destructor_body .= "' (', \spl_object_id(\$this), ')...',";
$destructor_body .= "\PHP_EOL,";
$destructor_body .= "(new \Exception)->getTraceAsString(),";
This file has been truncated, but you can view the full file.
<?php
declare(strict_types=1);
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Facing;
use pocketmine\math\Vector3;
use pocketmine\math\VoxelRayTrace;
use pocketmine\player\Player;
use pocketmine\scheduler\CancelTaskException;
@Muqsit
Muqsit / build-pathfinding-mesh.php
Created April 23, 2024 00:53
Pathfinding Block Position Mesh for Arbitrary-Sized Mobs
<?php
declare(strict_types=1);
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Facing;
use pocketmine\math\Vector3;
use pocketmine\player\Player;
use pocketmine\scheduler\CancelTaskException;
use pocketmine\scheduler\ClosureTask;
<?php
declare(strict_types=1);
/**
* @name KitEditorPlugin
* @main muqsit\kiteditorplugin\KitEditorPlugin
* @api 5.0.0
* @version 0.0.1
*/
@Muqsit
Muqsit / GeneratorMethodNotYieldingRule.php
Last active April 5, 2024 00:55
PHPStan rule to find unused instantiated generators
<?php
declare(strict_types=1);
namespace pocketmine\phpstan\rules;
use Generator;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\ArrayItem;
use PhpParser\Node\Expr\Assign;
@Muqsit
Muqsit / nbt-json.php
Last active November 11, 2023 11:53
NBT CompoundTag to JSON in PocketMine-MP using a stack for iterative node traversal
<?php
declare(strict_types=1);
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\player\Player;
use pocketmine\Server;
$server = Server::getInstance();
assert(isset($sender) && $sender instanceof Player);
@Muqsit
Muqsit / test.php
Created September 9, 2023 07:58
Terraforming regions in PocketMine-MP worlds using Scripter plugin
<?php
declare(strict_types=1);
use cosmicpe\CosmicPE;
use pocketmine\block\Block;
use pocketmine\block\BlockTypeIds;
use pocketmine\block\Liquid;
use pocketmine\block\VanillaBlocks;
use pocketmine\event\EventPriority;