Skip to content

Instantly share code, notes, and snippets.

@arnaud-lb
arnaud-lb / logrotate.conf
Created July 13, 2012 16:19
backuprotate
/var/lib/redis/dump.rdb {
# rotate every day and keep 30 backups
daily
rotate 30
missingok
# rename backups dump.rdb-YYYYMMDD
# instead of dump.rdb.X: more rsync friendly
dateext
# create a new dump
postrotate
@arnaud-lb
arnaud-lb / UseIndexWalker.php
Created May 15, 2012 19:27
USE INDEX / FORCE INDEX in a Doctrine2 DQL query
<?php
use Doctrine\ORM\Query\SqlWalker;
/**
* Quick hack to allow adding a USE INDEX on the query
*/
class UseIndexWalker extends SqlWalker
{
const HINT_USE_INDEX = 'UseIndexWalker.UseIndex';
<?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 / 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)
{
@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);
<?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 / __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[)];;