Skip to content

Instantly share code, notes, and snippets.

View bobmagicii's full-sized avatar
🤌

Bob Magic II bobmagicii

🤌
View GitHub Profile
<?php
class AncientFileFilter extends \FilterIterator {
protected $DaysOld = 7;
public function __construct($dir,$days=null) {
// is the specified directory valid?
if(!is_string($dir) || !is_dir($dir) || !is_readable($dir))
<?php
class AncientFileFilter extends \FilterIterator {
protected $DaysOld = 7;
public function __construct($dir,$days=null) {
// is the specified directory valid?
if(!is_string($dir) || !is_dir($dir) || !is_readable($dir))
<?php
$dirname = dirname(__FILE__);
$paths = array(
"{$dirname}/controllers",
"{$dirname}/models",
"{$dirname}/views"
);
set_include_path(get_include_path().PATH_SEPARATOR.implode(PATH_SEPARATOR,$paths));
<?php
/*
protected function ReturnFileProperties($File)
{
if($Fileprops = new Imagick($File))
{
$FileProps = array();
$FileProps['MimeType'] = "IMAGE/".$Fileprops->getImageFormat();
$FileProps['FileSize'] = $Fileprops->getImageLength();
@bobmagicii
bobmagicii / gist:4685064
Created January 31, 2013 18:29
testing how good is_callable is about method accessibility.
<?php
class BobTest {
public function PublicMethod() { return; }
protected function ProtectedMethod() { return; }
private function PrivateMethod() { return; }
public function TestCallables() {
echo "testing myself...", PHP_EOL;
@bobmagicii
bobmagicii / gist:4770578
Last active December 12, 2015 12:18
explicit shutdown for exception handler
<?php
// set an exception handler so that we can render nice errors when bad thigns
// happen instead of spaming the user with garbage.
set_exception_handler(function($e){
echo 'somebody derped in the waterhole';
// your framework logging utility to log this
// ...
<?php
// set an exception handler so that we can render nice errors when bad thigns
// happen instead of spaming the user with garbage.
set_exception_handler(function(){
echo 'somebody derped in the waterhole';
// your framework logging utility to log this
// ...
@bobmagicii
bobmagicii / gist:5136321
Created March 11, 2013 18:13
ImageFilterIterator extends FilterIterator (basic)
<?php
class ImageFilterIterator extends FilterIterator {
public function accept() {
if(preg_match('/^(?:gif|jpe?g|png)$/i',$this->getExtension())) {
return true;
} else {
return false;
}
@bobmagicii
bobmagicii / gist:5136344
Created March 11, 2013 18:15
using the basic ImageFilterIterator
<?php
$path = dirname(__FILE__);
foreach(new ImageFilterIterator(new FilesystemIterator($path)) as $image) {
echo $image, PHP_EOL;
}
@bobmagicii
bobmagicii / gist:5136370
Created March 11, 2013 18:18
ImageFilterIterator extends FilterIterator and uses FilesystemIterator itself
<?php
class ImageFilterIterator extends FilterIterator {
// overwriting the constructor to automagically create an inner iterator
// to surf the file system when given a path name.
public function __construct($path) {
parent::__construct(new FilesystemIterator($path));
return;