Skip to content

Instantly share code, notes, and snippets.

View philsturgeon's full-sized avatar
🌳
Planting Trees

Phil Sturgeon philsturgeon

🌳
Planting Trees
View GitHub Profile

DON'T BE A DICK PUBLIC LICENSE

Version 1, December 2009

Copyright (C) 2009 Philip Sturgeon email@philsturgeon.co.uk

Everyone is permitted to copy and distribute verbatim or modified copies of this license document, and changing it is allowed as long as the name is changed.

@philsturgeon
philsturgeon / composer.json
Created September 19, 2012 09:37
PHP Image Manipulation
{
"require": {
"illuminate/foundation": ">=1.0.0",
"illuminate/auth": ">=1.0.0",
"illuminate/database": ">=1.0.0",
"illuminate/view": ">=1.0.0",
"amazonwebservices/aws-sdk-for-php": "1.5.*",
"codeguy/upload": "*",
"sybio/image-workshop" : "*",
@philsturgeon
philsturgeon / gist:3343945
Created August 13, 2012 20:38
Dutch DBAD
WEES GEEN LUL PUBLIEKE LICENTIE
Versie 1, December 2009
Copyright (C) 2009 Philip Sturgeon <email@philsturgeon.co.uk>
Iedereen heeft toestemming dit document te kopiëren en te distribuëren,
en veranderen is toegestaan als je de naam van het document verandert.
WEES GEEN LUL PUBLIEKE LICENTIE
@philsturgeon
philsturgeon / gist:3228499
Created August 1, 2012 16:30
DateTime comparison (strings)
<?php
function calculateDateDiff($strStart, $strEnd) {
$objStart = DateTime::createFromFormat("m/j/Y g:i:s A", $strStart);
$objEnd = DateTime::createFromFormat("m/j/Y g:i:s A", $strEnd);
// Return Total Seconds
return $objEnd->getTimestamp() - $objStart->getTimestamp();
// Return formatted diference (7hrs 5mins and 43 seconds)
return $objStart->diff($objEnd)->format('%hhrs %imins and %sseconds ');
@philsturgeon
philsturgeon / gist:3228471
Created August 1, 2012 16:28
Complicated Compare date difference (Seconds)
<?php
function calculateDateDiff($strStart, $strEnd) {
$parts = explode(' ', $strStart);
$dates = explode('/', $parts[0]);
$times = explode(':', $parts[1]);
$unix_start = mktime($times[0], $times[1], $times[2], $dates[0], $dates[1], $dates[2]);
$parts = explode(' ', $strEnd);
$dates = explode('/', $parts[0]);
$times = explode(':', $parts[1]);
@philsturgeon
philsturgeon / gist:3228398
Created August 1, 2012 16:21
Simple DateTime Conversion
<?php
function formatDate($strDate) {
return DateTime::createFromFormat("m/j/Y g:i:s A", $strDate)->format('Y-m-d H:i:s');
}
@philsturgeon
philsturgeon / gist:3228301
Created August 1, 2012 16:12
Tricky Date Formating
<?php
function formatDate($strDate) {
$parts = explode(' ', $strDate);
$dates = explode('/', $parts[0]);
$times = explode(':', $parts[1]);
// check to see if it is am or pm
if(strtolower($parts[2]) == 'pm' && $times[0] != 12) {
// add 12 to the hour as it needs to be military time
$times[0]+=12;
}
@philsturgeon
philsturgeon / gist:3216320
Created July 31, 2012 11:21
Why DateTime Rocks
// Traditional
$parts = explode(' ', $dateTime);
$dates = explode('/', $parts[0]);
$times = explode(':', $parts[1]);
// check to see if it is am or pm
if(strtolower($parts[2]) == 'pm' && $times[0] != 12) {
// add 12 to the hour as it needs to be military time
$times[0]+=12;
}
@philsturgeon
philsturgeon / TwitterHighlights.snippet.php
Created June 23, 2012 18:19
MODX Revolution Output filter to create links from Twitter @name, #tag and URLs
<?php
/**
* TwitterHighlights
* Output filter to create links from Twitter @name, #tag and URLs
*/
$input = preg_replace("#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t< ]*)#", "\\1<a href=\"\\2\" rel=\"nofollow\">\\2</a>", $input);
$input = preg_replace("#(^|[\n ])((www|ftp)\.[^ \"\t\n\r< ]*)#", "\\1<a href=\"http://\\2\" rel=\"nofollow\">\\2</a>", $input);
$input = preg_replace("/@(\w+)/", "<a href=\"https://www.twitter.com/\\1\" rel=\"nofollow\">@\\1</a>", $input);
$input = preg_replace("/#(\w+)/", "<a href=\"https://www.twitter.com/search/\\1\" rel=\"nofollow\">#\\1</a>", $input);
// The result of the expression (true && false) is assigned to $g
// Acts like: ($g = (true && false))
$g = true && false;
// The constant true is assigned to $h and then false is ignored
// Acts like: (($h = true) and false)
$h = true and false;