Skip to content

Instantly share code, notes, and snippets.

View lorenzo's full-sized avatar

José Lorenzo Rodríguez lorenzo

View GitHub Profile
trait foo { function bob() { echo 'from trait'; }}
class bar { use foo; }
class baz extends bar { function bob() { parent::bob(); echo ' from child'; }}
$a = new baz;
$a->bob();
//result: from trait from child
On 2/14/13, at 1:18 PM, (Nodes / DK / Mobile) Casper Rasmussen wrote:
> add windows phone os 7.1
android 2.33
ios 5.1
blackberry 10
@lorenzo
lorenzo / topics.md
Created July 24, 2013 11:48
Workshop topics
  • Modelling and implementing advanced authorization patterns. Use case: an user logged in with facebook and another logged via the API will be handed out different permissions.
  • Effective use of the event systems: Injecting listener callbacks to any model in the system
  • Background processing: Extracting slow pieces of functionality to offline processes
  • Custom datasources: Using elastic search to build a cakephp interface to a search engine
  • Advanced logging: How to extract useful information out of your log messages
  • Hardcore unit testing, converting a badly designed code into something testable using mocks and alternative fixture handling
  • Transforming model results via iterators: How to alter your data or extract info out of it using iterators.
  • Optional: leveraging newrelic and xhprof

My requirements:

# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults env_reset
Defaults mail_badpass
@lorenzo
lorenzo / wtf.php
Created August 21, 2013 08:23
This shows that calling a closure magically is faster than calling the margin method directly
<?php
/**
* Configuration options
*
*/
$iterations = 1000000;
info();
$callable = function() {
return 1 + 1;
{
"name": "bakers",
"repositories": [
{
"type": "pear",
"url": "http://pear.cakephp.org"
}
],
"require": {
"pear-cakephp/cakephp": "2.4.0-RC2",
<?php
/**
* Name of database configuration resource to use for storing data in Elastic Search
*
* @var string
**/
public $useIndexConfig = 'index';
/**
* Check if DataSource currently is ElasticSource
<?php
$formatter = function($entity) use ($preferredlanguage, $translatedFields) {
foreach ($entity->translations as $translation) {
if ($translation->locale === $preferredlanguage) {
foreach ($translatedFields as $f) {
$entity->set($f, $translation->get($f));
}
}
}
@lorenzo
lorenzo / finonacci.php
Created January 10, 2014 08:35
A non-recursive and stack overflow safe fibonacci function in PHP
<?php
function fib() {
list($x, $y) = [0, 1];
while(1) {
yield $y;
list($x, $y) = [$y, $x + $y];
}
}
server {
# Enable Gzip compressed.
gzip on;
# Enable compression both for HTTP/1.0 and HTTP/1.1 (required for CloudFront).
gzip_http_version 1.0;
gzip_comp_level 5;
# Don't compress anything that's already small and unlikely to shrink much
# if at all (the default is 20 bytes, which is bad as that usually leads to