Skip to content

Instantly share code, notes, and snippets.

View dunglas's full-sized avatar

Kévin Dunglas dunglas

View GitHub Profile
@dunglas
dunglas / bench.php
Last active August 29, 2015 14:05
hash_equals benchmark
<?php
/**
* Constant-time comparision length leak benchmark.
* Inspirated by https://gist.github.com/yohgaki/ede544f290c6cf9fa90d
*
* @author Kévin Dunglas
*/
$knownSize = 1024;
$userShortSize = 512;
@dunglas
dunglas / serializer-test-null.php
Created December 14, 2014 15:32
Symfony's Serializer null handling
<?php
<<<CONFIG
packages:
- "symfony/serializer: ~2.6"
CONFIG;
use Symfony\Component\Serializer\Serializer;
use Symfony\Component\Serializer\Encoder\XmlEncoder;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer;
<?php
<<<CONFIG
packages:
- "dunglas/php-property-info: dev-master"
- "doctrine/orm: ~2.3"
- "phpdocumentor/reflection: ~1.0"
CONFIG;
use Doctrine\ORM\EntityManager;
@dunglas
dunglas / sfFacebookNewDoctrineGuardAdapter.class.php
Created March 8, 2011 08:55
sfFacebookConnectPlugin Adapter for recents sfDoctrineGuardPlugin versions.
<?php
/**
*
* @package sfFacebookConnectPlugin
* @author Kévin Dunglas <dunglas@gmail.com>
* @author Fabrice Bernhard
*
*/
class sfFacebookNewDoctrineGuardAdapter extends sfFacebookGuardAdapter {
<?php
trait T
{
public function __construct()
{
echo "Trait contructor";
}
}
@dunglas
dunglas / sleep-AuthController.php
Created November 22, 2012 20:24
Un sleep inutile
// Prestashop 1.5.2, controllers/front/AuthController.php, line 278
$customer = new Customer();
$authentication = $customer->getByEmail(trim($email), trim($passwd));
if (!$authentication || !$customer->id)
{
// Handle brute force attacks
sleep(1);
$this->errors[] = Tools::displayError('Authentication failed');
}
@dunglas
dunglas / config.yml
Last active December 10, 2015 06:58
Symfony's Assetic configuration to compile CoffeeScript files.
# Assetic Configuration
assetic:
debug: %kernel.debug%
use_controller: false
bundles: [ DunglasChaplinDemoBundle ]
# java: /usr/bin/java
filters:
cssrewrite: ~
coffee:
bin: %coffee_path%
parameters:
# ...
coffee_path: /usr/local/share/npm/bin/coffee
node_path: /usr/local/bin/node
@dunglas
dunglas / DefaultController.php
Last active December 10, 2015 06:58
Controller to load the SPA
<?php
// Part of the Dunglas' Symfony 2 / Chaplin.js tutorial
// http://dunglas.fr/2012/12/utiliser-chaplin-js-et-backbone-js-avec-symfony-2-installation-et-configuration/
namespace Dunglas\ChaplinDemoBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
@dunglas
dunglas / index.html.twig
Last active December 10, 2015 07:38
Chaplin.js boilerplate for Symfony (Twig)
{#
Part of the Dunglas' Symfony 2 / Chaplin.js tutorial
http://dunglas.fr/2012/12/utiliser-chaplin-js-et-backbone-js-avec-symfony-2-installation-et-configuration/
#}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Chaplin Boilerplate Application</title>
<style>