Skip to content

Instantly share code, notes, and snippets.

View joshtronic's full-sized avatar
🐢
🐢 🐢 🐢

Josh Sherman joshtronic

🐢
🐢 🐢 🐢
View GitHub Profile
@joshtronic
joshtronic / gist:597309
Created September 25, 2010 21:12
JavaScript Mobile Browser Detection
var userAgent = navigator.userAgent.toLowerCase();
var isIE = userAgent.indexOf('msie') != -1;
var isIphone = userAgent.indexOf('iphone') != -1 || userAgent.indexOf('ipad') != -1
var isAndroid = userAgent.indexOf('android') != -1;
@joshtronic
joshtronic / gist:598285
Created September 26, 2010 20:17
Magic Setter Example
public function __set($name, $value)
{
if (isset($this->$name))
{
trigger_error('Cannot set variable after declaration', E_USER_ERROR);
return false;
}
else
{
$this->$name = $value;
@joshtronic
joshtronic / index.php
Created September 29, 2010 23:54
PICKLES Custom Controller Example
<?php
require_once 'pickles.php';
new CustomController();
?>
@joshtronic
joshtronic / gist:608170
Created October 3, 2010 01:29
PICKLES Proposed "Find All" Syntax
<?php
// Empty model
$model = new Model();
// Pull by ID
$model = new Model(123);
// Pull by condition(s)
$model = new Model(array('conditions' => array('id' => 123)));
@joshtronic
joshtronic / gist:608919
Created October 3, 2010 20:46
PICKLES Private Module Function
<?php
class search extends Module
{
public function __default()
{
// Pulls all the active cities
$city = new City('list', array('fields' => 'slug, name', 'conditions' => array('active' => '1')));
$cities = array_merge(array(null => 'select your city'), $city->records);
@joshtronic
joshtronic / gist:608676
Created October 3, 2010 15:39
PICKLES Model Example
<?php
// Pulls the records with ID 1-10
$city = new City(array('conditions' => array('id BETWEEN' => array(1, 10))));
// Loops through the records
while ($city->record)
{
// Sets the active field to 0 for the current record
$city->record['active'] = 0;
@joshtronic
joshtronic / new-search.php
Created October 3, 2010 18:57
PICKLES Old Model versus New Model
<?php
class search extends Module
{
public function __default()
{
// Pulls all the active cities
$city = new City('list', array('fields' => 'slug, name', 'conditions' => array('active' => '1')));
$cities = array_merge(array(null => 'select your city'), $city->records);
@joshtronic
joshtronic / gist:614183
Created October 6, 2010 22:03
Round with Precision
<?php
/**
* Rounds a float with direction.
*
* Since round() doesn't support an optional rounding mode until 5.3 I
* had to roll my own function to do so in the meantime.
*
* Note: Does not support negative precision.
*
@joshtronic
joshtronic / config.ini
Created October 12, 2010 01:13
Multiple Database Driver Support in PICKLES
[DATABASE]
default = DBMS
[DBMS]
driver = mysql
hostname = localhost
username = username
password = password
database = database
<?php
$parameters = array (
'actionID' => 'GetSamples',
'parameters' => array (
array('date_start' => $date_range_start),
array('date_end' => $date_range_end)
),
'UserName' => $this->getSoapUsername(),
'Password' => $this->getSoapPassword()