Skip to content

Instantly share code, notes, and snippets.

@adrienbrault
adrienbrault / gist:1401812
Created November 28, 2011 20:07
Install coffee script compiler on CentOS

You are going to install some things. Login in root or use sudo for most of the followings commands.

su -

First you need git.

yum install git
@adrienbrault
adrienbrault / gist:1455111
Created December 10, 2011 13:00
jQuery.ajax with and without deferred
//
// With classic callbacks
//
var callApi = function(success) {
$.ajax({
url: '/hello',
success: function(data) {
// Do callApi stuff here.

Count how many variables have an underscore inside grep -E -r --include=*.php "[$][a-zA-Z\x7f-\xff]([a-zA-Z0-9\x7f-\xff]*_[a-zA-Z0-9\x7f-\xff]*)+" . | wc -l

Count how many variables have no underscore inside grep -E -r --include=*.php "[$][a-zA-Z\x7f-\xff][a-zA-Z0-9\x7f-\xff]*" . | wc -l

The regex is from : http://php.net/manual/en/language.variables.basics.php

Process: php [14202]
Path: /usr/bin/php
Identifier: php
Version: ??? (???)
Code Type: X86-64 (Native)
Parent Process: bash [5788]
Date/Time: 2012-05-24 02:27:12.208 +0200
OS Version: Mac OS X 10.7.4 (11E53)
Report Version: 9
@adrienbrault
adrienbrault / a.php
Created May 25, 2012 18:49
TimelineBundle suggestions
// This feels weird, usually create returns a new instance or something like that
$entry = new TimelineAction();
$entry->create($chuckNorrisObject, 'control', 'The world');
// This would be better
$entry = TimelineAction::create($chuckNorrisObject, 'control', 'The world');
// Or maybe something more like that
$entry = new TimelineAction();
$entry->configure/setup/fill/etc...($chuckNorrisObject, 'control', 'The world');
@adrienbrault
adrienbrault / i_am_a_rockstar.php
Created May 25, 2012 20:31
PHP static keyword example
<?php
class A
{
public static function create()
{
return new static();
}
}
SELECT RELATION_ID(p.author) AS author_id
FROM Post AS p
// On utilise toujours ca ....
try {
$result = $qb->getQuery()->getSingleResult();
} catch (NoResultException $e) {
$result = null;
}
// Mais magie, magie, cette méthode non documentée fait la meme chose!
$result = $qb->getQuery()->getOneOrNullResult();
{
"name": "jms/payment-core-bundle",
"type": "symfony-bundle",
"description": "This bundle is providing the foundation for various payment plugins.",
"keywords": ["payment"],
"homepage": "http://jmsyst.com/bundles/JMSPaymentCoreBundle",
"license": "Apache2",
"authors": [
{
"name": "Johannes M. Schmitt",
<?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.
*/