Skip to content

Instantly share code, notes, and snippets.

View Ph3nol's full-sized avatar
🦄
Riding a Unicorn. From ::1 to the moon.

Cédric Dugat Ph3nol

🦄
Riding a Unicorn. From ::1 to the moon.
View GitHub Profile
@Ph3nol
Ph3nol / RelDate.php
Created December 5, 2011 08:02 — forked from arnaud-lb/RelDate.php
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);
@Ph3nol
Ph3nol / gist:1647991
Created January 20, 2012 15:56
Symfony2 1 single Doctrine result
<?php
$query = $em->createQuery('SELECT ....')
->setMaxResults(1);
try {
$product = $query->getSingleResult();
} catch (\Doctrine\Orm\NoResultException $e) {
$product = null;
}
@Ph3nol
Ph3nol / gist:1723221
Created February 2, 2012 12:22
Symfony 1.4 route separators
foo_route:
url: /location-:url
options: { segment_separators: ['/', '.', '-'] }
@Ph3nol
Ph3nol / gist:1780293
Created February 9, 2012 14:18
RSync command
rsync --exclude-from=<rsync-dir>/rsync_exclude.txt --include-from=<rsync-dir>/rsync_include.txt --files-from=<rsync-dir>/rsync.txt -e ssh -p <port> ./ <user><host>:<dir>
rsync --dry-run -azC --force --delete --progress --exclude-from=config/rsync_exclude.txt -e "ssh -p22" ./ user@host.com:/destination/path/httpdocs/
@Ph3nol
Ph3nol / evi.php
Created February 16, 2012 16:05
Vimeo video informations extraction from API
<?php
function extractVimeoInformations($videoID, $fieldToExtract = 'id')
{
$apiExtraction = unserialize(file_get_contents(sprintf('http://vimeo.com/api/v2/video/%s.php', $videoID)));
return $apiExtraction[0];
}
?>
@Ph3nol
Ph3nol / listGeneratedModels.class.php
Created June 5, 2012 09:32
List a symfony 1.4 project models
<?php
// List models
echo implode(', ', Doctrine::loadModels(sfConfig::get('sf_lib_dir') . '/model/'));
// List models without Base* ones
$models = array();
@Ph3nol
Ph3nol / sphinx-macosx.sh
Created June 6, 2012 05:14 — forked from ubermuda/sphinx-macosx.sh
Installing sphinxsearch on macosx
# first sphinx
brew install sphinx
# the formula does not install libsphinxclient :/
wget http://sphinxsearch.com/files/sphinx-2.0.4-release.tar.gz
tar xzf sphinx-2.0.4-release.tar.gz
cd sphinx-2.0.4-release/api/libsphinxclient/
CXXCPP="gcc -E" ./configure --prefix=/usr/local
make
make install
@Ph3nol
Ph3nol / gist:3187434
Created July 27, 2012 11:08
array_diff ...
<?php
function array_diff_simple($a, $b)
{
$r = array();
foreach($a as $key => $val) {
if(!isset($b[$key])) {
$r[$key] = $val;
} else {
if(is_array($b[$key]) && !is_array($val)) {
@Ph3nol
Ph3nol / QSAListener.php
Created August 8, 2012 18:36 — forked from kriswallsmith/QSAListener.php
implements QSA on Symfony2 redirects
<?php
use JMS\DiExtraBundle\Annotation as DI;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
/** @DI\Service */
class QSAListener
{
private $blacklist;
@Ph3nol
Ph3nol / gist:3470847
Created August 25, 2012 20:53
Symfony DiC: register new Definition
<?php
use Symfony\Component\DependencyInjection\DefinitionDecorator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
// ...