Skip to content

Instantly share code, notes, and snippets.

View zavodnoyapl1992's full-sized avatar

Aleksey Dovbenko zavodnoyapl1992

View GitHub Profile
@zavodnoyapl1992
zavodnoyapl1992 / after_FactoryA.php
Last active February 18, 2024 20:42
Before/After
<?php
class FactoryA implements FactoryInterface {
public function __construct(
private readonly ARepository $aRepository,
private readonly ExtractorFactory $extractorFactory
) { }
public static function getType(): ObjectType {
import Data.List.Split(splitOn)
isWin :: [[Maybe Integer]] -> Bool
isWin xs = any isWin1 [xs, revertMatrix xs []] where
revertMatrix [] newMat = newMat
revertMatrix xs newMat = revertMatrix (filter (\y -> length y > 0) (map tail xs)) (newMat ++ [map head xs])
isWin1 [] = False
<?php
function sumStrings($a, $b) {
$intMaxLength = strlen((string)PHP_INT_MAX) - 2;
$aArr = str_split(strrev($a), ($intMaxLength));
$bArr = str_split(strrev($b), $intMaxLength);
$add = 0;
$res = [];
$aArrLength = (count($aArr));
foreach ($aArr as $k => $block) {
$i = (int)(strrev($block)) + (int)strrev($bArr[$k] ?? '0') + $add;
class Number {
private $precision;
private $int;
public function __construct($number)
{
$this->precision = (int)$this->getPrecision($number);
$this->int = pow(10, $this->precision) * $number;
<?php
class Trans {
private $word;
public function __construct(string $word) {
$this->word = $word;
}
public function __invoke(array $replaces) {
return str_replace(array_keys($replaces), array_values($replaces), $this->word);
@zavodnoyapl1992
zavodnoyapl1992 / layout_parser.php
Last active November 26, 2015 09:31
layout parser primitive example
<?php
$url1 = 'https://vk.com/t_baks';
$url2 = 'https://vk.com/mih_in';
$content = preg_replace("(\n)", "", file_get_contents($url1));
$content2 = preg_replace("(\n)", "", file_get_contents($url2));
preg_match_all("#<head>(.*)<\/head>#i", $content, $head);
preg_match_all("#<head>(.*)<\/head>#i", $content2, $head2);
$match = explode('<',$head[1][0]);
$match2 = explode('<',$head2[1][0]);
$headLayout = array_intersect($match, $match2);
@zavodnoyapl1992
zavodnoyapl1992 / Abstract
Created March 4, 2015 08:46
Mongo ActiveRecord
<?php
namespace Library\Mongo;
abstract class AbstractEntity
{
private $fields = array();
private $_id;
/**
* @var $mongoCollection /MongoCollection
@zavodnoyapl1992
zavodnoyapl1992 / gist:8930836
Last active August 29, 2015 13:56
mini-app for visual test
<?php
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/config/constant.php';
function requireAllConfigFilesFrom($dir)
{
foreach (new DirectoryIterator($dir) as $fileInfo) {
if ($fileInfo->isDot()) {
continue;