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 / Annotation.js
Last active October 24, 2023 22:47
JavaScript Annotations example
import Reader from './Reader';
import Target from './Target';
/**
* This is default annotation property for automatic type casting:
* <code>
* @Annotation({ some: any })
* // => will be casts "as is" {some: any}
*
* @Annotation("any")
@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;
}
@SerafimArts
SerafimArts / Lexer.php
Last active September 5, 2023 16:43
PHP Language lexer
<?php
/**
* Exec "composer require railt/lexer ~1.2"
*/
declare(strict_types=1);
namespace Example;
use Railt\Io\Readable;
use Railt\Lexer\Definition\TokenDefinition;
@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;
@SerafimArts
SerafimArts / Ai.php
Last active March 26, 2023 05:58
AI (Adobe Illustrator) Reader
<?php
namespace app\support\lib;
class Rect
{
protected $left;
protected $top;
protected $width;
protected $height;
<?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)]
@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);
//
<?php
class Example
{
public function __construct(
public ?string $value = null,
) {
}
}
/** @var Example $object */