Skip to content

Instantly share code, notes, and snippets.

View tomschlick's full-sized avatar

Tom Schlick tomschlick

View GitHub Profile
@tomschlick
tomschlick / Environments to bypass .htpasswd protection
Created November 8, 2009 08:30
This allows you to set certain urls/domains that are allowed to bypass a htpasswd protection layer, which is very useful for multiple environment setups (developement, staging, production)
#allows a single uri through the .htaccess password protection
SetEnvIf Request_URI "/testing_uri$" test_uri
#allows everything if its on a certain host
SetEnvIf HOST "^testing.yoursite.com" testing_url
SetEnvIf HOST "^yoursite.com" live_url
Order Deny,Allow
AuthName "Restricted Area"
AuthType Basic
@tomschlick
tomschlick / gist:233561
Created November 13, 2009 03:21
checks to see if the current server request was made with AJAX , returns boolean TRUE or FALSE
function _is_ajax()
{
return (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'));
}
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MY_Log extends CI_Log
{
var $mongo;
function __construct()
{
$this->mongo = new Mongo("localhost");
< ?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Blog_model extends Model
{
function __construct()
{
parent::Model();
}
function insert_blog_post($data)
{
$this->db->insert('blog_posts', $data);
return $this->db->insert_id();
}
function get_blog_post($where)
{
$this->db->where($where);
$query = $this->db->get(‘blog_posts’, 1);
if($query->num_rows() == 1)
{
return $query->row_array();
}
return FALSE;
}
function update_blog_posts($where, $data)
{
$this->db->where($where);
$this->db->update(‘blog_posts’, $data);
return $this->db->affected_rows();
}
function delete_blog_posts($where)
{
$this->db->where($where);
$this->db->delete(‘blog_posts’);
return $this->db->affected_rows();
}
@tomschlick
tomschlick / gist:781663
Created January 16, 2011 09:06
php ordinal number helper function
function ordinal($n)
{
$ln = (int) substr($n, -1);
$sln = (int) substr($n, -2);
$r = array('st','nd','rd');
$es = (($sln < 11 || $sln > 19) && $ln > 0 && $ln < 4);
return $n . ($es ? $r[$ln - 1] : 'th');
}
@tomschlick
tomschlick / gist:791999
Created January 23, 2011 11:23
This function allows you to dive into an array and provide a fallback value in case the element you want does not exist.
<?php
function array_element($array, $key, $default = false)
{
$key = explode('.', $key);
if(count($key) > 1)
{
if ( ! is_array($array) || ! array_key_exists($key[0], $array))
{
return $default;