Skip to content

Instantly share code, notes, and snippets.

View renan's full-sized avatar

Renan Gonçalves renan

View GitHub Profile
@renan
renan / gist:5063785
Last active December 14, 2015 09:19
diff --git a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php
index 4b14a4f..5401ea9 100644
--- a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php
+++ b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php
@@ -6288,6 +6288,29 @@ class FormHelperTest extends CakeTestCase {
}
/**
+ * testYearAutoExpand method
+ *
<?php
echo $this->Form->input('Applicant.tel_code_id', array(
'label' => 'International Telephone Code',
'options' => $telCode,
'empty' => $applicationData['Applicant']['tel_code_id'] === null,
'selected' => $applicationData['Applicant']['tel_code_id'],
));
diff --git a/CurlResponse.php b/CurlResponse.php
index dda2e62..6095fda 100644
--- a/CurlResponse.php
+++ b/CurlResponse.php
@@ -38,26 +38,47 @@ class CurlResponse {
# Headers regex
$pattern = '#HTTP/\d\.\d.*?$.*?\r\n\r\n#ims';
+ # Start the body
+ $this->body = $response;
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
@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
<?php
namespace App\Controller;
use App\Model\News;
class News {
public function test() {
News::doSomething();
}
}
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"
}
@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');
}
@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
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