Skip to content

Instantly share code, notes, and snippets.

View tentacode's full-sized avatar
🐙
tentacoding

Gabriel Pillet tentacode

🐙
tentacoding
View GitHub Profile
@tentacode
tentacode / form_theme.twig
Created April 10, 2014 16:16
Displaying buttons at the end of a form in a Twig form theme for Symfony
{% block form_rows %}
{% spaceless %}
{% for child in form if child.vars.block_prefixes.1 != 'submit' %}
{{ form_row(child) }}
{% endfor %}
{% for child in form if child.vars.block_prefixes.1 == 'submit' %}
{{ form_row(child) }}
{% endfor %}
{% endspaceless %}
{% endblock form_rows %}
@tentacode
tentacode / validation.php
Created April 16, 2014 08:39
Know if a property is required for current validation groups using Validator metadatas
<?php
function isRequired($object, $property, $validationGroups = ['Default'])
{
$classMetadata = $this->validator->getMetadataFor($object);
$propertyMetadatas = $classMetadata->getPropertyMetadata($property);
foreach ($propertyMetadatas as $propertyMetadata) {
$constraintsByGroups = $propertyMetadata->constraintsByGroup;
@tentacode
tentacode / form.html
Created May 22, 2014 08:21
Small jQuery script that notices the user when leaving the page without saving after updating a form
<form action="..." data-unsaved-warning>
<!-- Something something the form -->
</form>
@tentacode
tentacode / CrazyCatLadyType.php
Last active August 29, 2015 14:01
PrototypeCollectionType is a new type I made to easily, generically, manage collection form with prototypes (add + remove), in a nicer way (IMO) than in the Symfony cookbook.
<?php
// src/Tentacode/LolcatBundle/Form/CrazyCatLadyType.php
namespace Tentacode\LolcatBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
class CrazyCatLadyType extends AbstractType
@tentacode
tentacode / RegistrationContext.php
Last active August 29, 2015 14:06
Make good use of the turnip syntax in Behat 3
<?php
namespace Context;
class RegistrationContext extends BaseContext
{
/**
* @When I go to the registration page
*/
public function iGoToTheRegistrationPage()
@tentacode
tentacode / PictureType.php
Created October 2, 2014 09:41
Using symfony type as a data transformer when it's its only purpose
<?php
namespace Tentacode\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\DataTransformerInterface;
class PictureType extends AbstractType implements DataTransformerInterface
{
@tentacode
tentacode / 0_reuse_code.js
Last active August 29, 2015 14:12
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@tentacode
tentacode / ScreenshotContext.php
Created February 6, 2015 13:33
After a Behat javascript scenario fails, taking a screenshot then sending it to wsend as an anonymous user. (could be improved, juste a POC really)
<?php
namespace Context;
use Behat\MinkExtension\Context\RawMinkContext;
use Behat\Testwork\Tester\Result\TestResult;
use Behat\Mink\Driver\Selenium2Driver;
class ScreenshotContext extends RawMinkContext
{
@tentacode
tentacode / loop.php
Last active August 29, 2015 14:19
Quick & dirty loop with pcntl_fork
<?php
// every thing before will be used in every child process
while(true) {
$pid = pcntl_fork();
if ($pid === -1) {
die('Could not fork process');
} elseif ($pid) {
@tentacode
tentacode / gist:1389156
Created November 23, 2011 16:36
Une commande pour lancer des tests Behat
<?php
namespace Pmsipilot\TestBundle\Command;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand,
Symfony\Component\HttpKernel\Util,
Symfony\Component\Console\Input\InputArgument,
Symfony\Component\Console\Input\InputOption,
Symfony\Component\Console\Input\InputInterface,
Symfony\Component\Console\Input\ArrayInput,