Skip to content

Instantly share code, notes, and snippets.

View ekiwi111's full-sized avatar

Eugene ekiwi111

  • New Zealand
View GitHub Profile
@ekiwi111
ekiwi111 / underquerify.js
Created March 16, 2018 00:45
Make underscore and jQuery available on the page (e.g. to use in Google Chrome Dev Tools) if not violating CSP
var underscore = document.createElement('script');
underscore.src = "https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js";
underscore.type = "text/javascript";
document.head.appendChild(underscore);
var jquery = document.createElement('script');
jquery.src = "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js";
jquery.type = "text/javascript";
document.head.appendChild(jquery);
@ekiwi111
ekiwi111 / ProductsFormType.php
Last active October 31, 2017 22:08
Symfony 2.8 - Enforce minimum select amount for the form with integer data form fields
// ...
$builder->addEventListener(FormEvents::SUBMIT, function(FormEvent $event) {
$form = $event->getForm();
$productsAmount = array_reduce($form->all(), function($carry, $item) {
$carry += (int) $item->getData();
return $carry;
}, 0);