Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:
Working from home...

Massimiliano Arione garak

:octocat:
Working from home...
View GitHub Profile
@garak
garak / controller.php
Created Apr 30, 2021
renderForm helper method for Symfony base controller
View controller.php
<?php
protected function renderForm(string $template, FormInterface $form, array $params = []): Response
{
$code = $form->isSubmitted() && !$form->isValid() ? Response::HTTP_UNPROCESSABLE_ENTITY : Response::HTTP_OK;
return $this->render($template, array_merge($params, ['form' => $form->createView()]), new Response(null, $code));
}
@garak
garak / rte.html
Created Jul 7, 2020
Pure JS rich text editor
View rte.html
<!doctype html>
<html>
<head>
<title>Rich Text Editor</title>
<script type="text/javascript">
var oDoc, sDefTxt;
function initDoc() {
oDoc = document.getElementById("textBox");
sDefTxt = oDoc.innerHTML;
@garak
garak / README.md
Last active Dec 20, 2020
bitbucket pipeline configuration for a Symfony project
View README.md

This configuration is for a project running Symfony (2 or 3)

I did the image after not founding anything suitable (it was a quick search). If you found a better one, tell me.

The parameter.yml.dist file is supposed to contain sensible default values. Only the password is replaced at runtime. If you need to replace other values, just add other sed commands to the script node.

I load fixtures before running tests because I rely on a "load once" strategy (I use a bundle to revert all changes done by my tests). If you prefer to load fixtures inside your tests, you can remove thas command from script

@garak
garak / Foo.php
Created Feb 16, 2017
uploadable with embedded
View Foo.php
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
@garak
garak / list.html.twig
Last active Jul 18, 2020 — forked from tentacode/list.html.twig
Twig recursive macro
View list.html.twig
{% macro recursiveCategory(category) %}
{% import _self as self %}
<li>
<h4><a href="{{ path(category.route, category.routeParams) }}">{{ category }}</a></h4>
{% if category.children|length %}
<ul>
{% for child in category.children %}
{{ self.recursiveCategory(child) }}
{% endfor %}
View ContactType.php
<?php
namespace Acme\DemoBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\Validator\Constraints;
class ContactType extends AbstractType
@garak
garak / DefaultControllerTest.php
Last active Aug 29, 2015
Testing facebook login with FOSFacebookBundle (functional test)
View DefaultControllerTest.php
<?php
namespace Acme\DemoBundle\Tests\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class DefaultControllerTest extends WebTestCase
{
public function testLoginOK()
{
View WebTestCase.php
<?php
namespace MyNamespace\CoreBundle\Test;
use Symfony\Bundle\FrameworkBundle\Client;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase as SymfonyWebTestCase;
use Symfony\Component\Process\Process;
abstract class WebTestCase extends SymfonyWebTestCase
{
@garak
garak / RomanNumberTest.php
Created Jun 27, 2012
test usati per il code kata di giugno 2012 al PUG Roma
View RomanNumberTest.php
<?php
#require_once __DIR__ . '/../RomanNumber.php';
class romanNumberTest extends \PHPUnit_Framework_TestCase
{
public function testOne()
{
$this->assertEquals('I', rnConvert(1));
}
@garak
garak / estrazione_pug.php
Created Mar 29, 2012
script per estrare un biglietto gratis per il phpDay/jsDay
View estrazione_pug.php
<?php
$p = array(
// gennaio
'arnaldo',
'giorgio',
'antonio',
'david',
'jacopo',
'luca',