Skip to content

Instantly share code, notes, and snippets.

View garak's full-sized avatar
:octocat:
Working from home...

Massimiliano Arione garak

:octocat:
Working from home...
View GitHub Profile
@garak
garak / controller.php
Created April 30, 2021 13:27
renderForm helper method for Symfony base controller
<?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 July 7, 2020 16:21
Pure JS rich text editor
<!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 May 14, 2022 01:45
bitbucket pipeline configuration for a Symfony project

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 February 16, 2017 13:40
uploadable with embedded
<?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 September 9, 2024 21:51 — forked from tentacode/list.html.twig
Twig recursive macro
{% 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 %}
<?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 August 29, 2015 14:01
Testing facebook login with FOSFacebookBundle (functional test)
<?php
namespace Acme\DemoBundle\Tests\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class DefaultControllerTest extends WebTestCase
{
public function testLoginOK()
{
<?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 June 27, 2012 08:05
test usati per il code kata di giugno 2012 al PUG Roma
<?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 March 29, 2012 12:23
script per estrare un biglietto gratis per il phpDay/jsDay
<?php
$p = array(
// gennaio
'arnaldo',
'giorgio',
'antonio',
'david',
'jacopo',
'luca',