Skip to content

Instantly share code, notes, and snippets.

@jakefolio
jakefolio / RecursiveNavigationIterator
Last active August 29, 2015 14:09
Simple Navigation Iterator (Fun With Iterators)
<?php
/**
* RecursiveNavigationIterator
*/
class RecursiveNavigationIterator extends RecursiveIteratorIterator
{
public $openTag = "<ul>\n";
public $closeTag = "</ul>\n";
@jakefolio
jakefolio / gist:3d7d9a890de268f22318
Created May 15, 2014 20:53
REGEX to find all links with the class of "demo" that do not have a </i> preceding the </a>
<?php
$content = '<div class="actions">
<a href="http://davidwalsh.name/demo/folding-animation.php" class="demo">Some text<i class="something"></i></a>
<a href="http://davidwalsh.name/demo/folding-animation.php" class="demo">Some other text</a>
<div class="clear"></div>
</div>';
$results = preg_replace('/(<a\s+.*?class="demo".*?)((?<!<\/i>)<\/a>)/i', '${1}<i class="something"></i></a>', $content);
var fs = require('fs');
var stream = fs.createReadStream('./test/fixtures/current');
var currentData = '';
stream.on('error', function (err) {
throw err;
});
stream.on('data', function (data) {
currentData += data;
});
<?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))
I have my model here:
// transactionmodel.js
function TransactionModel() {
var pg = require('pg');
var connectionString = "pg://chartjes:******@localhost:5432/ibl_stats";
this.client = new pg.Client(connectionString);
this.client.connect();
this.getCurrent = function() {
@jakefolio
jakefolio / index.php
Created February 16, 2012 21:38
Only load the routes you want based off of URI params
<?php
// Stupid dirty example of how to load only the routes you want.
$app->hook('slim.before.router', function() use ($app) {
$uri = $app->request()->getResourceUri();
$params = explode('/', substr($uri, 1, strlen($uri)));
if (file_exists(APP_ROOT . '/app/routes/' . $params[0] . '.php'))
include APP_ROOT . '/app/routes/' . $params[0] . '.php';
});