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
@philsturgeon
philsturgeon / gist:1388885
Created November 23, 2011 14:58
Google analytics OAuth 2 + Refresh Tokens
<?php
class Controller_Metrics extends Controller {
public function action_index()
{
if ( ! Auth::check())
{
exit('not logged in');
}
@philsturgeon
philsturgeon / gist:1529194
Created December 28, 2011 19:03 — forked from adamfairholm/gist:1397939
PyroCMS Example Module details.php
<?php defined('BASEPATH') or exit('No direct script access allowed');
class Module_Sample extends Module {
public $version = '2.0';
public function info()
{
return array(
'name' => array(
@philsturgeon
philsturgeon / gist:1618268
Created January 16, 2012 00:48
Gearman Worker init.d
#!/bin/bash
#
# /etc/init.d/gearman-workers
### BEGIN INIT INFO
# Provides: gearman-workers
# Required-Start: $network $remote_fs $syslog
# Required-Stop: $network $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
@philsturgeon
philsturgeon / gearman-workers.sh
Created January 16, 2012 01:53 — forked from fabriziomachado/gearman-workers.sh
/etc/init.d/gearman-workers
#!/bin/bash
#
# /etc/init.d/gearman-workers
### BEGIN INIT INFO
# Provides: gearman-workers
# Required-Start: $network $remote_fs $syslog
# Required-Stop: $network $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
@philsturgeon
philsturgeon / gist:1777448
Created February 9, 2012 05:01
Keywords example
$id = $this->blog_m->insert(array(
'title' => $this->input->post('title'),
'slug' => $this->input->post('slug'),
'keywords' => Keywords::process($this->input->post('keywords')),
'intro' => $this->input->post('intro'),
'body' => $this->input->post('body'),
'status' => $this->input->post('status'),
));
@philsturgeon
philsturgeon / gist:2420813
Created April 19, 2012 13:00
API_Controller (PyroCMS)
<?php defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Shared logic and data for all CMS controllers
*
* @author Phil Sturgeon
* @package PyroCMS\Core\Controllers
*/
class API_Controller extends REST_Controller
{
@philsturgeon
philsturgeon / gist:2472086
Created April 23, 2012 16:27
Dealing with CodeIgniter's incorrect defaults
/*/*
* CodeIgniter likes to return FALSE instead of NULL, which means
* that you need to check for FALSE before sending things of to
* the DB - amonsgt other issues - as well as the fact that FALSE
* is actually a value and not a valid "I dont know" response.
*/
// NULL default in PHP 5.3
$foo = $this->input->post('foo') ?: NULL;
// 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;
@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);
@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;
}