This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function exec_local_url($url) { | |
exec('/usr/bin/wget -O - -q -t 1 "http://'. $_SERVER['HTTP_HOST'] .'/' | |
. addslashes($url) . '" >/dev/null 2>&1' | |
); | |
} | |
exec_local_url('php -S localhost:1000 -t .'); | |
// exec(php -S localhost:1000); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_.mixin({ | |
findKeysByValue : function(object,value) { | |
var retVal=[] | |
for(var key in object){ | |
var obj=object[key] | |
if(obj==value){ | |
retVal.push(key) | |
} | |
} | |
return retVal; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('#select > option').each(function() { | |
alert($(this).text() + ' ' + $(this).val()); | |
}); | |
$('#select > option:selected').each(function() { | |
alert($(this).text() + ' ' + $(this).val()); | |
}); | |
// This function will return an array of text/value pairs for the selects matching the given class. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mysql> CREATE TABLE messages (id INT(11) NOT NULL AUTO_INCREMENT, | |
name VARCHAR(255) NULL, | |
text VARCHAR(255), | |
created_at INT(11), | |
updated_at INT(11), | |
PRIMARY KEY (id)) ENGINE=INNODB; | |
Query OK, 0 rows affected (0.05 sec) | |
mysql> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Loading dot dot dot | |
*/ | |
body { | |
padding: 100px; | |
font-size: 62.5%; | |
} | |
.loading { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// move to helper | |
// clean submitted data before handling in db realm (roll 32 sided di now...) | |
function scrubberUpper($str) { return filter_var(strtoupper(trim($str)), FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH); } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SimpleCounter { | |
protected $total = 0; | |
public function add($amount) | |
$this->total += $amount | |
return $this | |
} | |
public function subtract($amount) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Syntax A - 0.25367754 seconds | |
for($i=0; $i<1000000; $i++){} | |
Syntax B - 0.25415988 seconds | |
for($i=0; $i<=999999; $i++){} | |
Syntax C - 0.25957097 seconds | |
for($i=0; $i!=1000000; $i++){} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Syntax A - 0.25400330 seconds | |
$i = 0 ; | |
while($i<1000000){ $i++ ; } | |
Syntax B - 0.25518957 seconds | |
$i = 0 ; | |
while($i<=999999){ $i++ ; } | |
Syntax C - 0.26488042 seconds |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. Beware of class-only selectors | |
jQuery | |
A great part about using a JavaScript library like jQuery is its selectors. But before you use them all over the place, stop to think: what are the processing costs? | |
Basically, jQuery defines all the elements on a page as a huge JavaScript object, and then interacts with it. You don’t have to look into the source code to realize that the selector function works by iterating all objects that fit a certain criteria. Therefore, it makes sense to give the selection function a helping hand by defining the selection criteria more specifically. | |
Let’s do a quick case-study: | |
Pretend you’re doing site navigation and want to select an LI that has the CSS class ‘active.’ One way to select this element is: | |
$('.active') | |
This selector works just fine, but think about what the jQuery DOM traversal has to do here: iterating through hundreds of elements on the page, selecting any with the class ‘active.’ That’s a lot of processing for our little nav bar. | |
It turns out, according to selec |