Skip to content

Instantly share code, notes, and snippets.

View benjaminrau's full-sized avatar

Benjamin Rau benjaminrau

View GitHub Profile
@benjaminrau
benjaminrau / Query.php
Created September 17, 2013 14:00
Set Orderings for an IN Statement
$query = $this->createQuery();
$results = $query->matching($query->in('objectProfile.geoLocation', $geoLocations));
# Sort by distance
if($geoLocations) {
foreach($geoLocations AS $geoLoc) {
$key = 'objectProfile.geoLocation = '.$geoLoc->getUid();
$orderings[$key] = Tx_Extbase_Persistence_QueryInterface::ORDER_ASCENDING;
}
$results = $results->setOrderings($orderings);
@benjaminrau
benjaminrau / shell_log.txt
Last active July 17, 2024 13:08
Setup virtual machine and typo3 with one command
Benjamin-Rau-iMac:~ benjaminrau$ git clone https://github.com/benjaminrau/devbox && cd devbox && ./up
Cloning into 'devbox'...
remote: Counting objects: 117, done.
remote: Compressing objects: 100% (85/85), done.
remote: Total 117 (delta 19), reused 39 (delta 2)
Receiving objects: 100% (117/117), 32.22 KiB | 0 bytes/s, done.
Resolving deltas: 100% (19/19), done.
Checking connectivity... done
Bringing machine 't3devbox' up with 'virtualbox' provider...
==> t3devbox: Importing base box 'vagrant-debian-wheezy64'...
@benjaminrau
benjaminrau / Readme.md
Last active March 12, 2024 09:15
Home Assistant (HASS) with Homekit, Television Volume Control and Fire TV Stick connected to Sony Bravia

Home Assistant (HASS) with Homekit, Television Volume Control and Fire TV Stick connected to Sony Bravia

Basically it integrates and older Sony Bravia TV with Fire TV Stick on HDMI via Home Assistant in Apple Homekit with Siri Voice Control for Volume, Mute and Turning TV on and off.

Features of my setup

  • Voice control for television on, off, mute, set volume, play, pause
  • Control for television on, off, mute, set volume and input (which app to start) in Home app
  • Turn on TV light scene when TV starts playing
  • iOS Remote Widget inputs are forwarded to media player & Android TV

Used Integrations

@benjaminrau
benjaminrau / Emma_MediaBundle_EventListener_SerializeListener.php
Last active June 7, 2021 07:53
File Upload (JSON) and store with Sonata Media Bundle (based on ApiPlatform 2.0, Symfony 3.1)
<?php
namespace Emma\MediaBundle\EventListener;
use ApiPlatform\Core\Serializer\SerializerContextBuilderInterface;
use Emma\MediaBundle\Entity\MediaElement;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
use Symfony\Component\Serializer\SerializerInterface;
@benjaminrau
benjaminrau / InvalidateTokenEventListener.php
Last active May 19, 2021 19:57
Mechanism to invalidate JWT for specific User in Symfony with Lexik JWT Bundle
<?php
namespace Emma\UserBundle\EventListener;
use Doctrine\ORM\EntityManagerInterface;
use Emma\UserBundle\Entity\User;
use FOS\UserBundle\Event\FormEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use FOS\UserBundle\FOSUserEvents;
use Symfony\Component\HttpFoundation\JsonResponse;
@benjaminrau
benjaminrau / ItemJsonNormalizer.php
Last active December 13, 2019 20:44
Allow to have different serialization groups for root resource and embedded relations
<?php
namespace Emma\AppBundle\Serializer;
use ApiPlatform\Core\Util\ClassInfoTrait;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
/**
@benjaminrau
benjaminrau / Controller.php
Last active October 10, 2019 13:07
Fill ObjectStorage from QueryResult
$objectStorage = $this->fillOjectStorageFromQueryResult($this->myRepository->findAll()));
/**
* Fill objectStorage from QueryResult
*
* @param \TYPO3\CMS\Extbase\Persistence\QueryResultInterface $queryResult
* @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage
*/
protected function fillOjectStorageFromQueryResult(\TYPO3\CMS\Extbase\Persistence\QueryResultInterface $queryResult=NULL) {
@benjaminrau
benjaminrau / gist:9896177
Created March 31, 2014 16:25
Access Media Files related to TYPO3 pages / FAL on page properties
{v:resource.record.fal(record: page, field: 'media', table: 'pages') -> v:iterator.extract(key: 'id') -> v:iterator.first() -> v:var.set(name: 'pageMedia')}
<f:if condition="{pageMedia}">
<v:page.header.meta name="og:image" content="{f:uri.image(src: pageMedia, treatIdAsReference: 1) -> v:format.prepend(add: '{v:page.siteUrl() -> v:format.substring(length: \'-1\')}')}" />
</f:if>
@benjaminrau
benjaminrau / outdatedBrowser.js
Last active February 7, 2019 08:55
Outdated Browser - minified to return just boolean
/**
* Outdated Browser
* Version: 1.1.2 - 2015
* author: Burocratik
* website: http://www.burocratik.com
*/
var isOutdatedBrowser = function(lowerThan) {
//assign css3 property or js property to IE browser version
if (lowerThan == 'IE8' || lowerThan == 'borderSpacing') {
@benjaminrau
benjaminrau / AllowedTags.php
Last active July 30, 2018 18:03
XSS Protection - will remove all html tags onFlush (before they are persisted) from fields which are ORM type text or string, with option to define allowed html tags by annotation
<?php
namespace AppBundle\Annotation\Xss;
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
/**
* @Annotation
* @Target({"PROPERTY"})
*/