This file contains 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 SQL_CALC_FOUND_ROWS *, * FROM huge_table; | |
/* Then as 2nd query straight after... */ | |
SELECT FOUND_ROWS() AS totalRows; | |
/* ...to get total records found */ |
This file contains 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 | |
$root = '/xampp/htdocs/repo'; | |
$iter = new RecursiveIteratorIterator( | |
new RecursiveDirectoryIterator($root, RecursiveDirectoryIterator::SKIP_DOTS), | |
RecursiveIteratorIterator::SELF_FIRST, | |
RecursiveIteratorIterator::CATCH_GET_CHILD // Ignore "Permission denied" | |
); | |
function has_gitignore_file($dir) { | |
return is_file("$dir/.gitignore"); |
This file contains 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 to sort given values alphabetically | |
function alphasort($a, $b) { | |
return strcasecmp($a->getPathname(), $b->getPathname()); | |
} | |
// Class to put forward the values for sorting | |
class SortingIterator implements IteratorAggregate { | |
private $iterator = null; | |
public function __construct(Traversable $iterator, $callback) { |
This file contains 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
Looking for functions to clean vars for different situations. | |
Can you improve on these, returning strings, urls and numbers: | |
function strClean($var) { | |
// returns converted entities where there are HTML entity equivalents | |
return htmlentities($var, ENT_QUOTES, "UTF-8"); | |
} | |
function urlClean($var) { |
This file contains 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
<span id="serverDT"></span> | |
<script> | |
var nDT = <?php echo time()*1000; ?>; | |
setInterval(function(){ | |
var s=(new Date(nDT+=1e3)+'').split(' '), | |
d=s[2]*1, | |
t=s[4].split(':'), | |
p=t[0]>11?'pm':'am', | |
e=d%20==1|d>30?'st':d%20==2?'nd':d%20==3?'rd':'th'; | |
t[0]=--t[0]%12+1; |
This file contains 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
var parser = document.createElement('a'); | |
parser.href = "http://example.com:3000/pathname/?search=test#hash"; | |
parser.protocol; // => "http:" | |
parser.hostname; // => "example.com" | |
parser.port; // => "3000" | |
parser.pathname; // => "/pathname/" | |
parser.search; // => "?search=test" | |
parser.hash; // => "#hash" | |
parser.host; // => "example.com:3000" |
This file contains 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 | |
echo 'Received by PHP:<br><br>'; | |
for ($i=1;$i<=($_POST['numFiles']*1);$i++) { | |
echo $_POST['fileName'.$i].'<br>'; | |
if (!strpos($_POST['fileName'.$i],".")) { | |
echo '[DIR]<br><br>'; | |
} else { | |
echo $_POST['fileContent'.$i].'<br><br>'; | |
} | |
} |