Skip to content

Instantly share code, notes, and snippets.

View DennisRas's full-sized avatar
💪
Let's do this !

Dennis Rasmussen DennisRas

💪
Let's do this !
View GitHub Profile
@DennisRas
DennisRas / config.php
Created November 5, 2011 20:44
Autoloader for CodeIgniter
function __autoload($class)
{
if (strpos($class, 'CI_') !== 0)
{
if (file_exists($file = APPPATH . 'core/' . $class . EXT))
{
include $file;
}
elseif (file_exists($file = APPPATH . 'libraries/' . $class . EXT))
{
@DennisRas
DennisRas / gist:1313736
Created October 25, 2011 18:23
Convert assoc values from alpha to numeric position of the alhapbet
<?php
$array = array('hi' => 'a', 'yo' => 'b');
array_walk($array, function(&$value, $key){
$value = strpos('abcdefghijklmnopqrstuvwxyz', $value) + 1;
});
print_r($array); // Array ( [hi] => 1 [yo] => 2 )
// < PHP 5.3
function alphanum(&$value, $key){
<snippet>
<content><![CDATA[
<div class="clearfix">
<label for="$1">$2</label>
<div class="input">
<?=form_input('$1', set_value('$1'), 'id="$1"')?>
</div>
</div>
]]></content>
<tabTrigger>formtext</tabTrigger>
@DennisRas
DennisRas / .htaccess
Created August 26, 2011 14:32
CodeIgniter .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
@DennisRas
DennisRas / time_ago.php
Created August 26, 2011 14:24
My suggestion for a time function
<?php
if ( ! function_exists('time_ago'))
{
function time_ago($time, $max_units = NULL)
{
$lengths = array(1, 60, 3600, 86400, 604800, 2630880, 31570560, 315705600);
$units = array('second', 'minute', 'hour', 'day', 'week', 'month', 'year', 'decade');
$unit_string_array = array();