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 / 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;
@Muqsit
Muqsit / AdjacencyMatrix.php
Last active April 25, 2023 15:05
A memory-efficient adjacency matrix that can store values in the range 0-15 (4 bits) per cell. Takes roughly 8 * v bytes of memory space (where v = number of vertices). Suitable for Minecraft redstone wires which have a strength of up to 15.
<?php
final class AdjacencyMatrix{
public static function read(string $data) : self{
return new self(array_values(unpack("J*", $data)));
}
public static function of(int $size) : self{
return new self(array_fill(0, ($size >> 4) | $size, 0));
@Muqsit
Muqsit / neural_network.py
Created March 2, 2023 19:17
Simple Neural Network (Python)
import numpy as np
from numpy import exp, array, random, dot
class NeuralNetwork():
def __init__(self):
self.synaptic_weights = 2 * random.random((3, 1)) - 1
def __sigmoid(self, x):
return 1 / (1 + exp(-x))
@Muqsit
Muqsit / simple_neural_network.php
Last active February 27, 2023 09:37
Simple Neural Network implementation in pure PHP (translated from Python). This is a translation of my university classwork on Neural Networks. This can be live-tested on https://3v4l.org (using PHP 8.1.16).
<?php
declare(strict_types=1);
final class Matrix{
/**
* Equivalent of numpy.random.random(size=(size_x, size_y))
*
* @param int $size_x
@Muqsit
Muqsit / RadioButtonVertical_Ant.js
Created August 29, 2022 06:55
RadioButtonVertical_Ant.js
import { Radio } from "antd";
import React from "react";
import * as css from "./RadioButtonVertical.scss";
import 'antd/lib/radio/style/index.css';
export const RadioButtonVertical_Ant = (props) => {
const { field, item, name } = props;
const { value, onChange } = field;
<?php
declare(strict_types=1);
/**
* @name InvMenuListenerTest
* @main muqsit\imtest\InvMenuListenerTest
* @version 0.0.1
* @api 3.0.0
*/
@Muqsit
Muqsit / main.rs
Created January 5, 2022 21:46
Converting head layer from minecraft skin data to a standard image format
use image::*;
use image::imageops::FilterType;
use std::result::Result;
// Takes a byte array of skin data and returns the face layer encoded in a given
// standard image format. The `width` and `height` here are the widths and heights
// of the output image (not the input skin).
fn skin_to_image_data(bytes: &Vec<u8>, width: u32, height: u32, format: ImageFormat) -> Result<Vec<u8>, &'static str>{
let blocks = skin_get_block_length(bytes.len())?;
@Muqsit
Muqsit / orientation_sampler.py
Created October 3, 2021 02:09
Simple outlier removal sampler for the BNO055 sensor (or any distance sensor for that matter)
import math
'''
Divides the sample into two clusters - left and right, where the left cluster
contains all values > mean(sample) and the right cluster contains all other
values.
The cluster with most number of values wins! Returns the winning cluster's mean.
If the cluster's max deviation from mean (i.e., min(cluster) - mean(sample)) is