Skip to content

Instantly share code, notes, and snippets.

View SerafimArts's full-sized avatar
wazzup?

Kirill Nesmeyanov SerafimArts

wazzup?
View GitHub Profile
@SerafimArts
SerafimArts / backslash.php
Last active September 9, 2024 17:28
Why do you need to put a backslash before PHP functions?
<?php
namespace Example;
$a = 23;
\is_null($a);
@SerafimArts
SerafimArts / Headers.php
Last active April 14, 2023 11:20
PHP Memory Map Visualization
<?php
declare(strict_types=1);
namespace Serafim\MemProf\Zend;
use FFI\Contracts\Preprocessor\Exception\DirectiveDefinitionExceptionInterface;
use FFI\Contracts\Preprocessor\Exception\PreprocessorExceptionInterface;
use FFI\Contracts\Preprocessor\PreprocessorInterface;
use FFI\Preprocessor\Preprocessor;
<?php
/**
* @template TArgStart
* @template TArgResume
* @template TArgReturn
* @template TArgSuspend
*
* @param \Fiber<TArgStart, TArgResume, TArgReturn, TArgSuspend> $fiber
* @param TArgStart ...$args
* @return \Generator<array-key, TArgResume, TArgReturn, TArgSuspend>
@SerafimArts
SerafimArts / 1.out.txt
Created October 14, 2022 14:47
bin pack/unpack
benchInt8
+-----------+------+---------+---------+
| benchmark | set | mode | rstdev |
+-----------+------+---------+---------+
| PackBench | raw | 0.972μs | ±22.36% |
| PackBench | pack | 1.336μs | ±25.69% |
+-----------+------+---------+---------+
benchUInt8
+-----------+------+---------+---------+
@SerafimArts
SerafimArts / WriteBench.php
Last active April 22, 2022 11:56
Shared Memory Benchmarks
<?php
namespace Bench;
use PhpBench\Attributes\BeforeMethods;
use PhpBench\Attributes\Iterations;
use PhpBench\Attributes\Revs;
use PhpBench\Attributes\Warmup;
#[Revs(100000), Warmup(2), Iterations(5)]
<?php
class Example
{
public function __construct(
public ?string $value = null,
) {
}
}
/** @var Example $object */
<?php
function file_get_contents(string $pathname): string
{
$result = '';
$fp = fopen($pathname, 'rb');
while (!feof($fp)) {
$chunk = 1024;
Fiber::getCurrent() && ($chunk = (Fiber::suspend() ?: 1024));
@SerafimArts
SerafimArts / example-1.php
Last active April 17, 2022 10:47
phpwtf-1
<?php
$variable = 23;
[$query, $params] = sql(fn() => <<<SQL
SELECT * FROM users WHERE id = ${yield $variable} OR id = ${yield 42}
SQL);
var_dump($query, $params);
//
@SerafimArts
SerafimArts / Merging PR for 2 branches
Created September 19, 2020 05:55 — forked from alopresto/Merging PR for 2 branches
Instructions to merge pull requests for multiple branches (master, support, etc.)
#Steps to merge/close pull requests with two main branches
As NiFi now has a 1.0 (master) and 0.x (support) branch, pull requests (PR) must be applied to both. Here is a step-by-step guide for committers to ensure this occurs for all PRs.
1. Check out the latest master
``` $ git checkout master
$ git pull upstream master
```
2. Check out the PR (example #327). This will be in `detached-HEAD` state. (Note: You may need to edit the `.git/config` file to add the `fetch` lines [below](#fetch))
@SerafimArts
SerafimArts / DecoratorInterface.php
Last active September 22, 2023 09:41
PHP Decorators
<?php
declare(strict_types=1);
interface DecoratorInterface
{
public static function handle(\Reflector $context, self $instance): void;
}