Skip to content

Instantly share code, notes, and snippets.

View lorenzo's full-sized avatar

José Lorenzo Rodríguez lorenzo

View GitHub Profile
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
colors="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="./tests/init.php"
>
<php>
<?php
/**
* Custom redis client class to be able to set a custom prefix for every key
*
* @see https://github.com/nicolasff/phpredis
**/
class RedisClient extends Redis {
/**
* Default prefix
public $paypal = array(
'datasource' => 'PaypalIpn.PaypalIpnSource',
'environment' => 'sandbox',
'business' => '[email protected]',
);
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
@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];
}
}
<?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));
}
}
}
<?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
{
"name": "bakers",
"repositories": [
{
"type": "pear",
"url": "http://pear.cakephp.org"
}
],
"require": {
"pear-cakephp/cakephp": "2.4.0-RC2",
@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;
# 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