Skip to content

Instantly share code, notes, and snippets.

View gcoop's full-sized avatar

Gavin Cooper gcoop

  • Surfline.com
  • Newport Beach, CA
View GitHub Profile
var Application = window.Application || {}; // Creates a namespace called Application.
Application.Config = function () {
var instance = (function () {
var privateVar;
function privateMethod() {
return 'privateMethod';
}
return { // Public interface.
publicMethod: function () {
var current_orientation; // Cache orientation.
x$('body').orientationchange(function() {
var newOrientation;
switch (window.orientation) // Switch out the windows orientation
{
case 0:
case 180: // Upside down.
newOrientation = 'portrait';
/**
* ProductStore - Constructor.
*/
function ProductStore()
{
}
/**
* Checks to see whether the product store is open and in-app purchases can be made.
*
/**
* Interogates a target class to return the full path to that file.
*
* @param string $target Class name in Refraction convention [pkg]_[sub-pkg]_[class], which translates to [folder]/[folder]/[full target].php.
*
* @return string
*/
static function load($target)
{
// Explode class name and put back together with '/' for the path but leave of the last part because this is the full $target.
<?php
var $data // is not; private $data, public $data and protected $data
class This
{
var $data;
function getData($key)
{
return $this->data[$key];
<?php
class This
{
private $data; // Actually protects data enforcing client code to write $obj->getData('foobar');
public function getData($key) // public not needed, but lets be concise and obvious, code for idiots, simple as that because when you look back at your code in 6 months time you are that idiot!
{
if (isset($this->data[$key])) // You will get a notice if you don't check before you do Coding rule #1, check before you presume.
return $this->data[$key];
<?php
class FooBar {
private $id = 1;
private $user;
public function getUser() {
if (!$this->user instanceof User) { // Only load it if we don’t have it.
$this->user = DB::load(‘User’, $this->id); // Cache the result in the object.
}
@gcoop
gcoop / jquery.plugin.tpl.js
Created October 25, 2010 10:41
jQuery Plugin Template Code
(function (window, document, $, undefined) {
var dataKey = 'MyPlugin';
var methods = {
init: function (opts) {
var defaults = {
'offset': 0
}, o = $.extend(defaults, opts);
return this.each(function () {
<?php
function _browser($a_browser = false, $a_version = false, $name = false)
{
$browser_list = 'msie firefox konqueror safari netscape navigator opera mosaic lynx amaya omniweb chrome avant camino flock seamonkey aol mozilla gecko';
$user_browser = strtolower($_SERVER['HTTP_USER_AGENT']);
$this_version = $this_browser = '';
$browser_limit = strlen($user_browser);
foreach (w($browser_list) as $row)
{
@gcoop
gcoop / javascript-performance.js
Created November 2, 2010 19:13
A load of JavaScript things that can be done slowly or quickly.
// == parseInt();
var width = parseInt("12.5"); // Slow
var width = ~~(1 * "12.5"); // Fast 1 * "12.5" turns string to float, ~~ double bit operator floors float to int. Chrome this is slower.
// == new Array();
var arr = new Array(); // Slow
var obj = new Object(); // Slow
var arr = []; // Fast