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 | |
class singleton | |
{ | |
public $var; | |
public function __construct() | |
{ | |
$this->var = false; | |
} |
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 | |
function headers_send($type, $charset = 'utf-8') | |
{ | |
switch ($type) | |
{ | |
case 'txt': | |
case 'text': | |
case 'plain': | |
header('Content-type: text/plain; charset='.$charset.''); | |
break; |
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 | |
function dump_var($var, $tab = 1) | |
{ | |
if (is_null($var)) | |
return 'null'; | |
if (is_numeric($var)) | |
return $var; | |
if (is_string($var)) | |
return "'".$var."'"; | |
if (is_array($var)) |
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 | |
class _ | |
{ | |
/** | |
* @param string $name | |
* @return null|mixed | |
*/ | |
function __get($name) | |
{ | |
return isset($_REQUEST[$name]) ? $_REQUEST[$name] : null; |
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 | |
function object_to_array($obj) | |
{ | |
$arr = array(); | |
foreach (($obj = is_object($obj) ? get_object_vars($obj) : $obj) as $key=> $val) | |
$arr[$key] = (is_array($val) or is_object($val)) ? $this->object_to_array($val) : $val; | |
return $arr; | |
} |
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
<img src="http://www.gravatar.com/avatar/<?=md5($email_address)?>?s=32" width="32" height="32"> |
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 | |
function is_includable($path) | |
{ | |
return file_exists($path) and is_readable($path); | |
} |
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 | |
function phone_format($phone) | |
{ | |
$phone = preg_replace('/[^0-9]/', '', $phone); | |
switch(strlen($phone)) | |
{ | |
case 6: | |
return preg_replace('/([0-9]{2})([0-9]{2})([0-9]{2})/', '$1-$2-$3', $phone); | |
break; | |
case 7: |
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
// --------------- | |
// Dynamic objects | |
// --------------- | |
/** | |
* Creates object on the fly (literal version) | |
* @type {Object} | |
*/ | |
var DynamicObject = { | |
/** |
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
// as property | |
event.currentTarget.dataset.id | |
// as array element | |
event.currentTarget.dataset['id'] | |
// jquery method | |
$(event.currentTarget).data('id') |