This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 () { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* ProductStore - Constructor. | |
*/ | |
function ProductStore() | |
{ | |
} | |
/** | |
* Checks to see whether the product store is open and in-app purchases can be made. | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
var $data // is not; private $data, public $data and protected $data | |
class This | |
{ | |
var $data; | |
function getData($key) | |
{ | |
return $this->data[$key]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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. | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function (window, document, $, undefined) { | |
var dataKey = 'MyPlugin'; | |
var methods = { | |
init: function (opts) { | |
var defaults = { | |
'offset': 0 | |
}, o = $.extend(defaults, opts); | |
return this.each(function () { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// == 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 |
OlderNewer