This file contains hidden or 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
| Document.prototype.find = function (query) { | |
| if (document.querySelectorAll) { | |
| var query = this.querySelectorAll(query); | |
| if (query.length == 1) | |
| return query[0]; | |
| else | |
| return query; | |
| } | |
| } |
This file contains hidden or 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
| Element.prototype.data = function(attr, value) { | |
| var attr = 'data-'+attr; | |
| if (value) { | |
| return this.setAttribute(attr, value); | |
| } else { | |
| return this.getAttribute(attr) | |
| } | |
| } |
This file contains hidden or 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
| Object.prototype.merge = function (toMerge) { | |
| var obj = {}; | |
| // first object | |
| for (var i in this) { | |
| obj[i] = this[i]; | |
| } | |
| // second object | |
| for (var i in toMerge) { | |
| obj[i] = toMerge[i]; | |
| } |
This file contains hidden or 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
| Element.prototype.on = function (evnt, func) { | |
| if (this.addEventListener) // W3C DOM | |
| this.addEventListener(evnt, func, false); | |
| else if (this.attachEvent) { // IE DOM | |
| var r = this.attachEvent("on"+evnt, func); | |
| return r; | |
| } | |
| } |
This file contains hidden or 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 | |
| if (!function_exists('facebook_request')) { | |
| function facebook_request () { | |
| if (isset($_REQUEST['signed_request'])) { | |
| if ($request = $_REQUEST['signed_request']) { | |
| list($encoded_sig, $payload) = explode('.', $request, 2); | |
| $decoded = base64_decode(strtr($encoded_sig, '-_', '+/')); | |
| $data = base64_decode(strtr($payload, '-_', '+/')); | |
| return json_decode($data, true); |
This file contains hidden or 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 | |
| if (!function_exists('p')) { | |
| function p($array) { | |
| echo '<pre>'; | |
| print_r($array); | |
| echo '</pre>'; | |
| } | |
| } |
This file contains hidden or 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 | |
| if (!function_exists('get_called_class') && version_compare(PHP_VERSION, '5.3', '<')) { | |
| function get_called_class() { | |
| $bt = debug_backtrace(); | |
| $l = 0; | |
| do { | |
| $l++; | |
| $lines = file($bt[$l]['file']); | |
| $callerLine = $lines[$bt[$l]['line']-1]; |
This file contains hidden or 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 | |
| if (!function_exists('json')) { | |
| function json ($data) { | |
| // if string we return as array | |
| if (is_string($data)) { | |
| return json_decode($data, true); | |
| // if array or object we encode it | |
| } else if (is_array($data) || is_object($data)) { | |
| return json_encode($data); | |
| } |
This file contains hidden or 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 | |
| if (!function_exists('slugify')) { | |
| function slugify ($str, $replace="-") { | |
| // replace all non letters or digits by $replace | |
| $str = preg_replace('/\W+/', $replace, $str); | |
| // trim and lowercase | |
| $str = strtolower(trim($str, $replace)); | |
| return $str; | |
| } |
This file contains hidden or 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 | |
| abstract class Singleton { | |
| protected function __construct() {} | |
| final public static function instance () { | |
| static $instances = array(); | |
| $calledClass = get_called_class(); | |
| if (!isset($instances[$calledClass])) { |
OlderNewer