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
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
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 | |
$iterator = new RecursiveIteratorIterator( | |
new RecursiveDirectoryIterator('/home/nepster/www/test.ru'), | |
RecursiveIteratorIterator::SELF_FIRST); | |
foreach($iterator as $file) { | |
if($file->isDir()) { | |
echo $file->getRealpath(), PHP_EOL; | |
} | |
} |
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 | |
public function beforeAction($action) | |
{ | |
if (!parent::beforeAction($action)) { | |
return false; | |
} | |
if(\Yii::$app->user->getIsGuest()){ | |
$this->redirect('/'); |
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 | |
public static function ip_info($ip = NULL, $purpose = "location", $deep_detect = TRUE) { | |
$output = NULL; | |
if (filter_var($ip, FILTER_VALIDATE_IP) === FALSE) { | |
$ip = $_SERVER["REMOTE_ADDR"]; | |
if ($deep_detect) { | |
if (filter_var(@$_SERVER['HTTP_X_FORWARDED_FOR'], FILTER_VALIDATE_IP)) | |
$ip = $_SERVER['HTTP_X_FORWARDED_FOR']; | |
if (filter_var(@$_SERVER['HTTP_CLIENT_IP'], FILTER_VALIDATE_IP)) | |
$ip = $_SERVER['HTTP_CLIENT_IP']; |
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 | |
$url = 'http://example.com/search?keyword=test&category=1&tags[]=fun&tags[]=great'; | |
$url_parts = parse_url($url); | |
parse_str($url_parts['query'], $params); | |
$params['category'] = 2; // Overwrite if exists | |
$params['tags'][] = 'cool'; // Allows multiple values | |
// Note that this will url_encode all values |
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
$("input[type='number']").on('keyup keypress blur change', function(e) { | |
//return false if not 0-9 | |
if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) { | |
return false; | |
}else{ | |
//limit length but allow backspace so that you can still delete the numbers. | |
if( $(this).val().length >= parseInt($(this).attr('maxlength')) && (e.which != 8 && e.which != 0)){ | |
return false; | |
} | |
} |
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 youTubeGetId(url) { | |
var expression = /^(?:https?:\/\/)?(?:www\.)?(?:youtu\.be[.]?\/|youtube\.com[.]?\/(?:embed\/|v\/|watch\/?\?(?:\S+=\S*&)*v=))([\w-]{11})\S*$/; | |
return url.match(expression) ? RegExp.$1 : undefined; | |
} |
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 readURL(input) { | |
if (input.files && input.files[0]) { | |
var reader = new FileReader(); | |
reader.onload = function (e) { | |
$(input).siblings('img').attr('src', e.target.result); | |
} | |
reader.readAsDataURL(input.files[0]); | |
} |
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
<select onchange="document.location='?sort='+this.options[this.selectedIndex].value"> | |
<option value="alphabet">Алфавит</option> | |
<option value="rating">Рейтинг</option> | |
<option value="date">Дата создания</option> | |
</select> |