Skip to content

Instantly share code, notes, and snippets.

View vertexvaar's full-sized avatar

Oliver Eglseder vertexvaar

View GitHub Profile
<?php
$functions = [
'array_flip & isset' => function (array $haystack, array $needles) {
$haystackFlip = array_flip($haystack);
foreach ($needles as $key => $needle) {
if (!isset($haystackFlip[$needle])) {
unset($needles[$key]);
}
}
@vertexvaar
vertexvaar / filter.php
Created December 4, 2020 17:16
Create a filter function by assembling the factory function as PHP code and eval
<?php
define('FILTER_MATCH_EXACT', 1 << 0);
define('FILTER_MATCH_LOOSE', 1 << 1);
define('FILTER_INVERT', 1 << 2);
function filter(mixed $specimen, int $flags = FILTER_MATCH_EXACT): Closure
{
// Unset FILTER_MATCH_EXACT if FILTER_MATCH_LOOSE is set.
if ($flags & FILTER_MATCH_LOOSE) {
<?php
class Cache
{
public function has(string $id): bool
{
}
public function get(string $id): array
{
@vertexvaar
vertexvaar / Browser.php
Created November 5, 2020 18:10
Parallel Browser Crawler concept
<?php
// Library Code
class Browser
{
public function createPage(): Page
{
return new Page();
}
}
@vertexvaar
vertexvaar / easy_things.php
Last active September 10, 2020 13:25
"Das war zu einfach" - Sorin
<?php
declare(strict_types=1);
function assertConstantOfClass(string $class, $constantValue): void
{
$reflection = new ReflectionClass($class);
$constants = $reflection->getConstants();
foreach ($constants as $value) {
if ($value === $constantValue) {
@vertexvaar
vertexvaar / php_pattern_matching.php
Created September 8, 2020 12:27
"Java isn't that complicated, you can build it with PHP" - Sorin
<?php
class Magic
{
public function add()
{
$args = func_get_args();
$count = count($args);
$methods = [];
@vertexvaar
vertexvaar / sortArrayCustom.php
Last active April 17, 2020 15:24
Sort an multi dimensional array by unique array value in custom order
<?php
$functions = [
'usort (from stackoverflow)' => function (array $input, array $order): array {
usort(
$input,
function ($a, $b) use ($order) {
$pos_a = array_search($a['id'], $order);
$pos_b = array_search($b['id'], $order);
return $pos_a - $pos_b;
@vertexvaar
vertexvaar / SomeCommand.php
Last active October 21, 2022 15:55
Symfony Console mulitple subprocess status bar with overall progress and message
<?php
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Output\OutputInterface;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;
@vertexvaar
vertexvaar / query.sql
Created November 29, 2019 09:52
SQL query select News Plugin with "List News" action
SELECT *
FROM tt_content
WHERE `CType` = 'list'
AND `list_type` = 'news_pi1'
AND ExtractValue(`pi_flexform`,
'/T3FlexForms/data/sheet[@index="sDEF"]/language[@index="lDEF"]/field[@index="switchableControllerActions"]/value[@index="vDEF"]/text()')
IN ("News->list;News->detail", "News-&gt;list;News-&gt;detail");
@vertexvaar
vertexvaar / .env
Last active November 26, 2019 08:22
Create host entry in makefile if it does not exist for linux and mac
HOST=local.project.com