Skip to content

Instantly share code, notes, and snippets.

View vertexvaar's full-sized avatar

Oliver Eglseder vertexvaar

View GitHub Profile
@vertexvaar
vertexvaar / _info.md
Last active January 20, 2022 09:55
Dual Web Setup

Project Structure

app/local <- contains a full TYPO3 project (and a composer.json)
app/foreign <- contains a full TYPO3 project (and a composer.json)
packages/ <- contains multiple repositories
app/tests <- codeception acceptance tests which test the interaction between multiple repositories.

repos from packages are installed via composer in both "local" and "foreign" TYPO3 instances.
Both composer.jsons has a repositories section with type path and url /packages/*

@vertexvaar
vertexvaar / aa_andreas.php
Last active December 9, 2021 10:24
Challenge: Find arrays by array
<?php
return [
'array_array_array_array' => static fn ($array, $search) => array_values(array_filter($array, static fn($item) => empty(array_diff_assoc($search, array_intersect_assoc($item, $search))))),
'array_array_array_array_keys' => static fn ($array, $search) => array_values(array_filter($array, static fn($item) => empty(array_diff_key($search, array_intersect_assoc($item, $search))))),
'array_array_array' => static fn ($array, $search) => array_values(array_filter($array, static fn($item) => array_intersect_assoc($item, $search) === $search)),
'array_array_array_long' => static function ($array, $search) {
$results = [];
$c = count($array);
@vertexvaar
vertexvaar / fair_random.php
Last active October 20, 2021 12:03
Making random fair again - for sorin
<?php
$original = $elements = [
'A' => 100,
'B' => 80,
'C' => 60,
'D' => 5,
];
function chooseElementFromWeightedList(array $list)
<?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 = [];