Skip to content

Instantly share code, notes, and snippets.

View mattpass's full-sized avatar

Matt Pass mattpass

View GitHub Profile
@mattpass
mattpass / get-last-query-rowcount.sql
Last active December 24, 2015 13:31
SQL - get number of rows from last query
SELECT SQL_CALC_FOUND_ROWS *, * FROM huge_table;
/* Then as 2nd query straight after... */
SELECT FOUND_ROWS() AS totalRows;
/* ...to get total records found */
@mattpass
mattpass / php-gitignore.php
Created June 13, 2014 10:23
PHP & .gitignore - Get list of exluded files in .gitignore file into array
<?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");
@mattpass
mattpass / file-system-tree.php
Created July 2, 2012 20:28
PHP: Show dir tree as a UL list
<?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) {
@mattpass
mattpass / PHPsec
Created June 22, 2012 07:00
PHP var security
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) {
@mattpass
mattpass / serverDateTime
Created June 9, 2012 11:49
Live server datetime golfing...
<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;
@mattpass
mattpass / uri.js
Created April 26, 2012 05:46 — forked from jlong/uri.js
URI Parsing with Javascript
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"
@mattpass
mattpass / upload.php
Created February 16, 2012 07:43
Drag & Drop File & Folder Uploader
<?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>';
}
}