Skip to content

Instantly share code, notes, and snippets.

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
@renan
renan / Post.php
Created April 16, 2012 12:42
CakePHP HABTM save
<?php
class Post extends AppModel {
public $hasMany = array('PostsTag');
public $hasAndBelongsToMany = array('Tag');
}
array(3) {
["subject"]=>
string(47) "Normal text www.foo.com
Normal text on new line"
["result"]=>
string(80) "Normal text <a href="http://www.foo.com">www.foo.com</a> Normal text on new line"
["expected"]=>
string(80) "Normal text <a href="http://www.foo.com">www.foo.com</a>
Normal text on new line"
}
<?php
namespace App\Controller;
use App\Model\News;
class News {
public function test() {
News::doSomething();
}
}
@renan
renan / bash
Created September 21, 2012 14:25
Session Locking
# Make sure you copy-paste all commands, so there is no delay between them
wget -q http://localhost/test.php -O first.txt &
sleep 1s
wget -q http://localhost/test.php -O second.txt
cat first.txt second.txt
diff --git a/EventCacheInst.php b/EventCacheInst.php
index b0dcee9..6ef92b6 100644
--- a/EventCacheInst.php
+++ b/EventCacheInst.php
@@ -391,7 +391,13 @@ class EventCacheInst {
return $safeKeys[$type.','.$key];
}
- $safeKey = $this->_config['app'] .
+ // Use the trackEvents as namespace in case more than one application wants to share the same events