Skip to content

Instantly share code, notes, and snippets.

@ostrolucky
ostrolucky / Makefile
Created August 27, 2022 16:05
Makefile with dynamic jobs (separate job for each subdir). Great for monorepo
SUBDIRS := $(wildcard fe-*)
PROXIED_COMPOSER_COMMANDS := install build lint test
MAKEFLAGS := --jobs=$(words $(SUBDIRS))
define make-composer-dot-rules
$1.$2::
cd $1 && composer $2
endef
@ostrolucky
ostrolucky / AddDocumentEvent.php
Created July 7, 2021 13:58
Make FOSElasticsearchbundle working without doctrine
<?php
declare(strict_types=1);
namespace Elektronik\Bl\DomainBundle\Infrastructure\Elasticsearch\Event;
use Symfony\Contracts\EventDispatcher\Event;
class AddDocumentEvent extends Event
{
private string $index;
<?php
function array_select(array $array, array $filter): array
{
return array_map(function (array $object) use ($filter) {
$object = array_intersect_key($object, $filter);
foreach ($object as $key => $value) {
if (is_array($filter[$key])) {
$object[$key] = array_select($object[$key], $filter[$key]);
@ostrolucky
ostrolucky / transcript.txt
Created April 20, 2019 13:47
Using lldb to debug PHP code
Guilhermes-MacBook-Pro:orm guilhermeblanco$ lldb /usr/local/Cellar/php/7.3.2/bin/php
(lldb) target create "/usr/local/Cellar/php/7.3.2/bin/php"
Current executable set to '/usr/local/Cellar/php/7.3.2/bin/php' (x86_64).
(lldb) run ./vendor/bin/phpunit tests/Doctrine/Tests/ORM/Functional/PaginationTest.php --filter testIterateWithOutputWalkersWithRegularJoinWithComplexOrderByReferencingJoined
Process 99416 launched: '/usr/local/Cellar/php/7.3.2/bin/php' (x86_64)
PHPUnit 7.5.6 by Sebastian Bergmann and contributors.
Runtime: PHP 7.3.2 with Xdebug 2.7.0RC2
Configuration: /Users/guilhermeblanco/doctrine/orm/phpunit.xml.dist
@ostrolucky
ostrolucky / macflife.d
Created March 25, 2019 13:03
This script is from the DTrace book, and traces the creation and deletion of files
#!/usr/sbin/dtrace -s
/*
* maclife.d
*
* Example script from Chapter 5 of the book: DTrace: Dynamic Tracing in
* Oracle Solaris, Mac OS X, and FreeBSD", by Brendan Gregg and Jim Mauro,
* Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.
*
* See the book for the script description and warnings. Many of these are
* provided as example solutions, and will need changes to work on your OS.
@ostrolucky
ostrolucky / conflict-free-merge.sh
Created December 15, 2018 21:17
Apply only changes which are mergeable to upper branch without conflicts
UPPERBRANCH=master
BOTTOMBRANCH=3.4
DIR="src"
git checkout $BOTTOMBRANCH
php-cs-fixer fix $DIR --rules='{"array_syntax": {"syntax": "short"}}'
git diff > patch.patch && splitpatch patch.patch && rm patch.patch
git checkout $UPPERBRANCH --force
mkdir -p nonworkingpatches workingpatches && rm -rf nonworkingpatches/* workingpatches/*
for patchfile in *.patch*; do
<?php
declare(strict_types=1);
namespace App\EventListener;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
@ostrolucky
ostrolucky / StripeHttplugClient.php
Created August 17, 2018 11:15
StripeHttplugClient
<?php
declare(strict_types=1);
namespace App\Service\Http;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Uri;
use Http\Client\HttpClient;
use Stripe\HttpClient\ClientInterface;
@ostrolucky
ostrolucky / currency mapping.xml
Created July 20, 2018 08:15
Moneyphp embeddable
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
https://raw.github.com/doctrine/doctrine2/master/doctrine-mapping.xsd">
<embeddable name="Money\Currency">
<field name="code" length="3" />
</embeddable>
</doctrine-mapping>
@ostrolucky
ostrolucky / yaml-custom-tags.php
Last active January 3, 2018 23:39
Example usage Symfony Yaml custom tags
<?php
require 'vendor/autoload.php';
$parsed = \Symfony\Component\Yaml\Yaml::parse(<<<YAML
test:
a: !b64baby stuff
b: foo
YAML