Skip to content

Instantly share code, notes, and snippets.

dbu /
Last active Apr 6, 2021
image gallery for sculpin with and bootstrap. example for the article at
# the file is markdown, but gist renders markdown. remove ".raw" and this line
title: Pictures example post
file: TestImage.jpg
caption: This is a test
note: Additional stuff to print next to the image
file: TestImage2.jpg
dbu / DoctrineEncryptListener.php
Last active Apr 29, 2020
encrypting doctrine fields
View DoctrineEncryptListener.php
namespace App\EventListener;
use App\Doctrine\Encryption\EncryptingEntityInterface;
use App\Doctrine\Encryption\EncryptorInterface;
use Doctrine\Common\EventSubscriber;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\ORM\Event\PreFlushEventArgs;
use Doctrine\ORM\Events;
dbu / CacheWarmerCompilerPass.php
Last active Feb 16, 2020
Conditionally tag a service in Symfony
View CacheWarmerCompilerPass.php
// src/DependencyInjection/CacheWarmerCompilerPass.php
namespace App\DependencyInjection;
use App\Cache\MyCacheWarmer;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Exception\EnvNotFoundException;
dbu / CommandHelper.php
Created May 9, 2019
typed options and arguments for symfony console
View CommandHelper.php
abstract class CommandHelper
public static function getStringOption(InputInterface $input, string $name): ?string
$optionData = $input->getOption($name);
if (null !== $optionData && !\is_string($optionData)) {
throw new \InvalidArgumentException(sprintf('Invalid data provided for --%s', $name));
dbu / ValidateServiceDefinitions.php
Created Apr 18, 2019
symfony compiler pass to detect invalid classes on service configurations
View ValidateServiceDefinitions.php
namespace Infrastructure\Symfony\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
dbu /
Last active Nov 5, 2018
Elasticsearch: Find all documents that have invalid entries in an array

We had a problem where invalid data got stored in elasticsearch. An array of objects had some objects placed in it that are missing a mandatory field. After fixing the mistake, we wanted to update all offending entires. For this, we need to get the IDs of affected items.

The "obvious" query would be _exists_:general_information AND !(_exists_:general_information.value). But as soon as there is any array element with a value, the second condition will consider the value existing. If there are any valid entries in the array, the query will not work as expected.

The solution we found was to use an ES script that loops over the elements in the source document and returns 1 if it finds one that has no data. To our positive surprise, running this on an index with over 1M entries only took a couple of seconds. Definitely not something for a routine query, but an acceptable time for a one-off query to fix a problem.

dbu / Kernel.php
Last active Sep 12, 2018
Load environment specific configuration in symfony 4 kernel
View Kernel.php
namespace App;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
use Symfony\Component\Routing\RouteCollectionBuilder;
dbu / Dockerfile
Created Aug 7, 2018
why does the anchor folder not exist in the docker image?
View Dockerfile
FROM mprasil/dokuwiki
RUN apt-get update && \
apt-get install -y unzip curl && \
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN curl -O -L "" && \
unzip -d /dokuwiki/lib/plugins/ && \
mv /dokuwiki/lib/plugins/ckgedit-master /dokuwiki/lib/plugins/ckgedit && \
rm -f
RUN curl -O -L ""
RUN unzip -d /dokuwiki/lib/plugins
View fly.php
use League\Flysystem\Util;
public function read($path)
$path = Util::normalizePath($path);
if (! ($object = $this->flysystem->getAdapter()->read($path))) {
return false;
dbu /
Last active Oct 2, 2018
Convert NelmioApiDocBundle annotations to Swagger PHP

A Symfony command to convert from NelmioApiDocBundle annotations to Swagger-PHP annotations.

This code is provided as is. Make sure to have your code committed to version control before running the command. Check if things work out and if not, use version control to reset the automated changes and fix the command.