Skip to content

Instantly share code, notes, and snippets.

@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);
@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";
<?php
$obj1 = new StdClass;
$obj2 = new StdClass;
$obj3 = new StdClass;
$obj1->name = "Joe";
$obj2->name = "Jane";
$obj3->name = "Johnny";
@jakefolio
jakefolio / gist:c898b387147578051f36
Created May 10, 2015 14:40
10 Steps to Maintainable Software
Writing maintainable software is something we all strive to do when we start a project.
The problem is, there is no simple checklist that states whether your code is maintainable or not.
I once read it is much easier to recognize the absence of maintainable software than to define it.
In this session we will lay out a foundation to building more maintainable software and practices
to better your team workflow. We will cover anything from naming of methods/variables, VCS commit
messages, and code reviews.
APIs are becoming the preferred data source for applications everywhere. Whether your API
is being consumed by JavaScript frontend, mobile app, or a microservice; you need
a solid foundation. With a plethora of information to sort through you can become
overwhelmed with questions: "Is this RESTful enough?" and "What the hell is HATEOAS, and
why should I care?" This talk will bring focus to the core building blocks of an API,
including: URI structure, response codes, pagination, documentation, authentication, and much more.
Having a solid API is becoming more necessary with the rise of JavaScript
frameworks and mobile apps. Structuring your API response to handle growth
and edge cases can be a daunting task. With JSON API, you have defined spec
for handling related resources, pagination, sorting, filtering, and tools/libraries.
In this session we will cover API responses, hypermedia linking, handling
errors, and serializing your data.
Do new team members struggle to gain traction in your code base? Do you have a certain
section of their code base that no one speaks of, and where all estimates grow exponentially.
This talk provides a guidline for identifying complex/confusing code and transforming it
into a comprehendible code base. We will cover variable/method naming, coding standards, and
finding/fixing complex code.
Our bodies are just like a legacy code base, we are old in internet years! Just like most legacy
code bases rewriting isn't an option, so you have to slowly refactor. We, developers, spend the majority
of our time sitting and possibly with terrible posture. Our schedules lead to poor eating choices and
physical exercise falls to the wayside. I will discuss the way I refactored my physical body and the incremental
changes that has lead to a more enjoyable life. You will leave with a plan to improve your overall health.
@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';
});
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() {