Skip to content

Instantly share code, notes, and snippets.

Benjamin Rau benjaminrau

View GitHub Profile
@benjaminrau
benjaminrau / InvalidateTokenEventListener.php
Last active May 29, 2020
Mechanism to invalidate JWT for specific User in Symfony with Lexik JWT Bundle
View InvalidateTokenEventListener.php
<?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 Dec 13, 2019
Allow to have different serialization groups for root resource and embedded relations
View ItemJsonNormalizer.php
<?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 / outdatedBrowser.js
Last active Feb 7, 2019
Outdated Browser - minified to return just boolean
View outdatedBrowser.js
/**
* 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') {
View EntityEventSubscriber.php
<?php
namespace Emma\AppBundle\EventSubscriber;
use ApiPlatform\Core\EventListener\EventPriorities;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Emma\AppBundle\AppBundleEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Request;
@benjaminrau
benjaminrau / AllowedTags.php
Last active Jul 30, 2018
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
View AllowedTags.php
<?php
namespace AppBundle\Annotation\Xss;
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
/**
* @Annotation
* @Target({"PROPERTY"})
*/
@benjaminrau
benjaminrau / Emma_MediaBundle_EventListener_SerializeListener.php
Last active Jun 18, 2018
File Upload (JSON) and store with Sonata Media Bundle (based on ApiPlatform 2.0, Symfony 3.1)
View Emma_MediaBundle_EventListener_SerializeListener.php
<?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 / lowBatteryShutdown.py
Created Apr 6, 2016
Onion Omega with Adafruit Power Board 500 mA, shutting down the onion when battery is now or power disconnected
View lowBatteryShutdown.py
import sys, os, datetime
from gpiohelper import GPIOHelper
helper = GPIOHelper()
vInPin = 12
lowBatteryPin = 8
pinToCheck = vInPin;
durationOfNotOKInMinutesBeforeShutdown = 1
@benjaminrau
benjaminrau / main.js
Created Mar 18, 2016
Read gps device with nodejs under openwrt and cp2102 ttl to usb converter
View main.js
var nmea = require('nmea');
var trycatch = require('trycatch');
function watchGps() {
var spawn = require('child_process').spawn;
var child = spawn("python", [tempDir + "readGpsDevice.py"]);
child.stdout.on('data', function (buffer) {
trycatch(function() {
var gpsOut = nmea.parse(buffer.toString());
@benjaminrau
benjaminrau / Form.html
Last active Jan 25, 2016
HTML5 LocalStorage used to fill form
View Form.html
<script>
$(document).ready(function() {
function initFormStorage(registrationFormId) {
console.log('Initializing storage for form#' + registrationFormId);
/*
* when a form field changes store it's value in local storage
*/
$("#" + registrationFormId + " input[type=text], #" + registrationFormId + " select, #" + registrationFormId + " textarea").change(function() {
$this = $(this);
console.log('Update value for ' + $this.attr("name") + 'to ' + $this.val());
@benjaminrau
benjaminrau / Scripts.php
Created Jun 29, 2015
Fixed buildSubprocessCommand for Expose Beard Patch
View Scripts.php
/**
* @param string $commandIdentifier E.g. typo3.flow:cache:flush
* @param array $settings The TYPO3.Flow settings
* @param array $commandArguments Command arguments
*
* @return string A command line command ready for being exec()uted
*/
protected static function buildSubprocessCommand($commandIdentifier, $settings, array $commandArguments = array()) {
$subRequestEnvironmentVariables = array(
'FLOW_ROOTPATH' => FLOW_PATH_ROOT,
You can’t perform that action at this time.