Skip to content

Instantly share code, notes, and snippets.

@arnaud-lb
arnaud-lb / __thread-tls-2.patch
Created November 2, 2010 14:53
__thread-tls-2.patch
Index: acinclude.m4
===================================================================
RCS file: /repository/php-src/acinclude.m4,v
retrieving revision 1.332.2.14.2.26.2.9
diff -u -r1.332.2.14.2.26.2.9 acinclude.m4
--- acinclude.m4 24 Jul 2008 14:17:54 -0000 1.332.2.14.2.26.2.9
+++ acinclude.m4 24 Aug 2008 15:16:48 -0000
@@ -2703,7 +2703,7 @@
enable-libtool-lock | with-pic | with-tags | enable-shared | enable-static | enable-fast-install | with-gnu-ld[)];;
<?php
class foo implements IteratorAggregate
{
public $a;
public $b;
public function getIterator()
{
return new ArrayIterator(array('foo', 'bar'));
@arnaud-lb
arnaud-lb / gist:1382400
Created November 21, 2011 11:44 — forked from pierrejoye/gist:1382376
get_ vs reflection
<?php
class foo {
public $a = 1;
private $b = 2;
public $c = 3;
public $d = 4;
protected $e = 5;
public function methodA() {}
@arnaud-lb
arnaud-lb / RelDate.php
Created December 4, 2011 14:12
4 lines relative date formatter with DateInterval and Symfony2 Translator
<?php
use Symfony\Component\Translation\TranslatorInterface;
function format(\DateTime $date, TranslatorInterface $translator)
{
$diff = date_create()->diff($date);
$seconds = $diff->days * 86400 + $diff->h * 3600 + $diff->i * 60 + $diff->s;
$format = $translator->transChoice('reldate', $seconds);
@arnaud-lb
arnaud-lb / gist:1673119
Created January 24, 2012 22:27
Array of booleans stored in a string
<?php
/**
* @author Arnaud Le Blanc <arnaud.lb@gmail.com>
*/
class Bitfield implements ArrayAccess
{
protected $field;
public function __construct($size)
@arnaud-lb
arnaud-lb / gist:1673067
Created January 24, 2012 22:17
bit field in a string
<?php
/**
* @author Arnaud Le Blanc <arnaud.lb@gmail.com>
*/
// 255*8 booleans initialized to true
$field = str_repeat("\xFF", 255);
function read_bit(&$str, $offset)
{
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
@arnaud-lb
arnaud-lb / html2haml.py
Created July 13, 2012 17:15
html2haml code style fixed
#!/usr/bin/env python
import subprocess
import re
orig = subprocess.check_output(["/usr/local/bin/html2haml"])
result = orig
result = re.sub(r' ', ' ', result)
Assign $a *1(!2(1)) NULL dim:NULL property:NULL
Assign $b *4(!5(2)) NULL dim:NULL property:NULL
Add $a $b *8(!9)
PrintOp *8(!9) NULL *10(!11)
ReturnOp NULL NULL NULL
@arnaud-lb
arnaud-lb / ClearListener.php
Last active December 16, 2015 21:39
Clear DoctrineExtensions entity wrapper cache when clearing entity manager
<?php
use Doctrine\ORM\Event\OnClearEventArgs;
use Gedmo\Tool\Wrapper\AbstractWrapper;
/**
* Register the listener with $em->getEventManager()->addEventListener('onClear', new ClearListener())
*/
class ClearListener
{