Skip to content

Instantly share code, notes, and snippets.

View vudaltsov's full-sized avatar
🐘

Valentin Udaltsov vudaltsov

🐘
View GitHub Profile
@vudaltsov
vudaltsov / php_point_interview_1.php
Last active February 24, 2024 18:54
Задачи и решения с собеседования https://youtu.be/ZPGjJDIZm4Y, https://youtu.be/Wa9hUi8NeTs
<?php
/**
* Дано: последовательность натуральных чисел (потенциально бесконечная).
*
* Требуется:
* 1. Написать функцию, которая принимает на вход эту последовательность
* и после обработки n элементов выдаёт не более m наибольших чисел
* среди уже обработанных отсортированных в порядке возрастания или убывания.
* 2. Оценить временную сложность алгоритма как O(f(n, m)).
@vudaltsov
vudaltsov / benchmark.php
Last active November 18, 2023 22:50
Кэш через OPcache
<?php
use Typhoon\Exporter\Exporter;
require_once 'vendor/autoload.php';
final class City
{
public function __construct(
public string $name,
@vudaltsov
vudaltsov / src_Infrastructure_MessageBus_di.php
Last active October 20, 2023 01:07
Symfony PHP configurator ContainerBuilder injection example
<?php
declare(strict_types=1);
namespace HardcorePhpCourse2\Infrastructure\MessageBus;
use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use VUdaltsov\SymfonyCourse\Infrastructure\MessageBus\Handler;
@vudaltsov
vudaltsov / LoggerStub.php
Created September 28, 2023 22:06
LoggerStub
<?php
declare(strict_types=1);
namespace App;
use Psr\Log\AbstractLogger;
final class LoggerStub extends AbstractLogger
{
<?php
declare(strict_types=1);
namespace ExtendedTypeSystem\Reflection\ClassLocator;
use Composer\Autoload\ClassLoader;
use ExtendedTypeSystem\Reflection\ClassLocator;
use ExtendedTypeSystem\Reflection\Source;
@vudaltsov
vudaltsov / Makefile
Created January 9, 2023 15:45
WaitCommand.php
vendor: composer.json composer.lock
composer install
touch vendor
db: vendor
php bin/console wait $(DB_HOST):$(DB_PORT)
php bin/console doctrine:database:create --if-not-exists
php bin/console doctrine:migrations:migrate --no-interaction
.PHONY: db
@vudaltsov
vudaltsov / Message.php
Created December 31, 2022 03:41
Envelope
<?php
/**
* @psalm-immutable
* @template TResult
*/
interface Message
{
}
<?php
declare(strict_types=1);
use HappyInc\Tool\Rector\ReadOnlyPublicPropertyRector;
use HappyInc\Tool\Rector\UuidTRector;
use Rector\Config\RectorConfig;
use Rector\Core\Configuration\Option;
use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector;
use Rector\Php71\Rector\FuncCall\CountOnNullRector;
<?php
declare(strict_types=1);
namespace HappyInc\Infrastructure;
/**
* @psalm-pure
*/
function mb_ucfirst(string $string): string
@vudaltsov
vudaltsov / basic_functions.php
Last active May 12, 2022 12:59
PHP facade functions examples
<?php
declare(strict_types=1);
/**
* @throws JsonException
*/
function jsonEncode(mixed $data, int $flags = 0): string
{
return json_encode($data, $flags | JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE);