Skip to content

Instantly share code, notes, and snippets.

@renan
renan / code.php
Last active August 27, 2015 08:54
<?php
public function __call($name, $arguments)
{
$callTypeIndex = 3;
if (substr($name, 0, 2) == "is") {
$callTypeIndex = 2;
}
$callType = substr($name, 0, $callTypeIndex);
$propertyName = substr($name, $callTypeIndex);
<?php
namespace App\Model;
use Cake\ORM\TableRegistry;
use Cake\Utility\Inflector;
trait ActiveRecordTrait {
protected static $overrideMethodMap = [
'fetch' => 'get',
];
@renan
renan / packages.sh
Last active August 29, 2015 14:07
Horde Packages with missing required for Composer or PEAR
#!/bin/bash
packages=(
ActiveSync Alarm Argv Auth Browser Cli Compress Core Crypt Data Date Dav
Exception Form Icalendar Image Imap_Client Imsp Itip Kolab_Cli Kolab_FreeBusy
Kolab_Resource Kolab_Storage ListHeaders LoginTasks Mail Mime Mime_Viewer
Model Nls Perms Prefs Push Rpc Service_Facebook Service_Scribd Service_Weather
Share Smtp SyncMl Text_Filter Vfs
)
for package in ${packages[*]}
@renan
renan / translator.php
Created October 24, 2014 11:25
Translator
<?php
use \MessageFormatter;
class Translator {
// This should be loading from a file. Eg: .po files (http://en.wikipedia.org/wiki/Gettext)
protected static $messages = [
'pt' => [
'Hello world' => 'Olá mundo',
],
'nl' => [
<?php
class Person
{
public function addPhoneNumber(PhoneNumber $phoneNumber)
{
$this->phoneNumbers[] = $phoneNumber;
}
}
Thais: Guess what I had for lunch today on my friend's house? You only have one chance.
Renan: Hmm ... Baião de dois? (typical Brazilian dish, we had it yesterday at home)
Thais: Nah! Lettuce crisp salad with avocado, zucchini and apple.
Dates (ref. http://en.wikipedia.org/wiki/Phoenix_dactylifera) with cheese inside.
The main dish was: rice with mango, eggplant stuffed with shrimp and salmon, pineapple with African pepper.
@renan
renan / gist:1066877
Created July 6, 2011 09:06
jQuery + innerShiv, checking if it have any html5 tag on it first, see https://github.com/jdbartlett/innershiv/issues/9
(function ($) {
var init = jQuery.fn.init; rootjQuery = jQuery(document);
var html5 = 'abbr article aside audio canvas datalist details figcaption figure footer header hgroup mark meter nav output progress section summary time video'.split(' ');
$.fn.init = function (selector, context, rootjQuery) {
if (typeof selector == 'string' && selector.indexOf('>') != -1 && selector.indexOf('<') != -1) {
for (var i in html5) {
if (selector.indexOf('<' + html5[i]) != -1) {
return new init(innerShiv(selector, false), context, rootjQuery);

I am running 2.0 on my app for almost 1 month. But when changed to 2.0 stable, got:

Fatal error: Nesting level too deep - recursive dependency? in /var/git/cakephp2.0/lib/Cake/Model/Datasource/DboSource.php on line 1501

Charging line 1491 from 'table' => $linkModel to 'table' => $this->fullTableName($linkModel) solved the issue.

On RC3, or pre-stable, this change was not present, but got introduced when merged 1.3 into 2.0 Tracked down to this commit: https://github.com/cakephp/cakephp/commit/d489d490

Two identical UUIDs in a row
How hard is it to generate two identical UUIDs in a row? Or, to put it another way, what’s the probability that two random UUID’s in a random set are identical? Well, the chance is the same as that you would generate one of those, you may try it!:
In fact you can’t do this. This is as much possible as tossing a coin 128 times in a row resulting with 128 heads (or tails) in a row. In Lotto game where you choose six numbers out of 49, winning is as probable as obtaining 24 heads in a row. You may try it yourself too
To say it another way, if one random UUID was a tile of area 1 mm2, when placed each by each other they would take some… 6,671,261,450,000,000,00 surfaces of Earth (including oceans). Imagine yourself on such an „infinite” tiled floor, what are the odds that you will find just the right tile once you know one is of a different color on the other side?
What about birthday paradox
Well, when you are considering using GUID as a key in your database, you certainly are g
@renan
renan / gist:1689380
Created January 27, 2012 15:48
GitHub error
Counting objects: 18, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (9/9), done.
Writing objects: 100% (10/10), 1.53 KiB, done.
Total 10 (delta 7), reused 0 (delta 0)
remote: /data/github/current/lib/github/config/resque.rb:27: undefined method `constantize' for "GitHub::Jobs::GistStats":String (NoMethodError)
remote: from /data/github/current/lib/github/config/resque.rb:26:in `each'
remote: from /data/github/current/lib/github/config/resque.rb:26
remote: from /data/github/current/lib/rock_queue.rb:9:in `require'
remote: from /data/github/current/lib/rock_queue.rb:9