Skip to content

Instantly share code, notes, and snippets.

View ruthlessfish's full-sized avatar

Shane Pearson ruthlessfish

View GitHub Profile
@ruthlessfish
ruthlessfish / MY_url_helper.php
Created August 24, 2011 20:57
Url helper function overrides
<?php defined('BASEPATH') or exit('No direct script access allowed');
/**
* Anchor Link
*
* Creates an anchor based on the local URL.
*
* @access public
* @param string the URL
* @param string the link title
@ruthlessfish
ruthlessfish / haversine.php
Created August 24, 2011 21:06
haversine formula for MySQL in PHP
<?php
function haversine($lat1, $long1, $lat2, $long2)
{
return "(3959 * acos(cos(radians($lat1)) * cos(radians($lat2)) * cos(radians($long2) - radians($long1)) + sin(radians($lat1)) * sin(radians($lat2))))";
}
@ruthlessfish
ruthlessfish / output_helper.php
Created August 29, 2011 00:01
serve assets with correct content type header
<?php defined('BASEPATH') OR exit('No direct script access allowed');
if( ! function_exists('show_css'))
{
function show_css($content)
{
show_output('text/css', $content);
}
}
@ruthlessfish
ruthlessfish / setup-config.php
Created August 29, 2011 22:29
crude script to update base_url and index_page in CodeIgniter config.php
<?php
$base_url = 'http://localhost';
$index_page = '';
$find = array();
$rep = array();
if(php_sapi_name() == 'cli')
{
@ruthlessfish
ruthlessfish / Cli_Controller.php
Created August 30, 2011 04:50
CLI base controller
<?php
class Cli_Controller extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->input->is_cli_request() OR die('Access denied.');
$this->load->library('cli');
}
@ruthlessfish
ruthlessfish / migrate.php
Created August 30, 2011 04:55
sample migration controller (CLI)
<?php
/**
* Sample Usage:
*
* $php index.php migrate version 5
* $php index.php migrate latest
* $php index.php migrate current
*
*/
// namespace
var WTF = {};
// --------------------------------------------------------------------
// database configuration
WTF.dbConfig = {
'username': 'root',
'password': 'root',
'database': 'poopy',
@ruthlessfish
ruthlessfish / manifest.php
Created September 9, 2011 01:11
convert an array of files into a multi-dimensional array
<?php
/**
* Build Manifest
*
* Requires: PHP 5.3+
*
* Takes an array of file names and builds a multi-dimensional array
* representing a simple file-system.
*
* NOTE: Files are only currently supported as leaf elements in the array.
@ruthlessfish
ruthlessfish / growl.php
Created September 12, 2011 23:03
Growl notifications in php
<?php
class Growl {
private $_command;
private $_valid_args = array('title', 'name', 'appicon', 'message', 'icon', 'iconpath', 'image', 'priority', 'identifier', 'wait', 'host', 'password', 'upd', 'port', 'auth', 'progress');
public function __construct($options = array())
{
if( ! empty($options))
@ruthlessfish
ruthlessfish / MY_Hooks.php
Created November 12, 2011 03:30
Custom hooks with arguments
<?php defined('BASEPATH') OR exit('No direct script access allowed');
/**
* MY_Hooks Class
*
* Extends Hooks by allowing you to pass parameters on the fly
* with custom hook calls. Much of the logic is borrowed from the
* core CI_Hooks class.
*
* Ex:
*