Skip to content

Instantly share code, notes, and snippets.

SELECT RELATION_ID(p.author) AS author_id
FROM Post AS p
@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();
}
}
@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');
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

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

@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.
@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
<?php
$entities = array(
new User(1, 'John'),
new User(2, 'Steve'),
);
$ids = array_map(function ($entity) {
return $entity->getId();
}, $entities);
- (void)drawRect:(NSRect)dirtyRect
{
NSGraphicsContext *graphicContext = [NSGraphicsContext currentContext];
CGContextRef context = [graphicContext graphicsPort];
// Set the origin of the coordinate system in the upper left corner instead of the lower left corner.
CGContextConcatCTM(context,
CGAffineTransformMake(1.0, 0.0, 0.0, -1.0, 0.0, self.frame.size.height));
}
{
case 1:
callFirstFunction();
break;
case 2:
callFirstFunction();
break;
case 3: