- 1
- 2
- 3
- 4
- 5
findTariffPlans = function(setValue) {findTariffPlans(setValue, null)};
findTariffPlans = function(setValue, closure) {
// bla-bla-bla
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+162
findTariffPlans = function(setValue) {findTariffPlans(setValue, null)};
findTariffPlans = function(setValue, closure) {
// bla-bla-bla
}
"Я перегрузил"
−163
SELECT news_tbl.*, users_tbl.*,
GROUP_CONCAT(comments_tbl.comments_id) AS commentsid,
GROUP_CONCAT(CONCAT ('<hr><h6>Navn: ', comments_tbl.name,'</h6>','<p>',comments_tbl.comment, '</p>') SEPARATOR '<br><br>') AS comments,
COUNT(comments_tbl.comments_id) AS comments_count
FROM news_tbl
LEFT JOIN comments_tbl ON comments_tbl.news_id = news_tbl.news_id
LEFT JOIN users_tbl ON news_tbl.user = users_tbl.username
GROUP BY news_tbl.news_id
ORDER BY news_tbl.news_id DESC LIMIT 5
Наткнулся на SO.
+55
function _bool($var){
if(is_bool($var)){
return $var;
} else if($var === NULL || $var === 'NULL' || $var === 'null'){
return false;
} else if(is_string($var)){
$var = trim($var);
if($var=='false'){ return false;
} else if($var=='true'){ return true;
} else if($var=='no'){ return false;
} else if($var=='yes'){ return true;
} else if($var=='off'){ return false;
} else if($var=='on'){ return true;
} else if($var==''){ return false;
} else if(ctype_digit($var)){
if((int) $var)
return true;
else
return false;
} else { return true; }
} else if(ctype_digit((string) $var)){
if((int) $var)
return true;
else
return false;
} else if(is_array($var)){
if(count($var))
return true;
else
return false;
} else if(is_object($var)){
return true;// No reason to (bool) an object, we assume OK for crazy logic
} else {
return true;// Whatever came though must be something, OK for crazy logic
}
}
Я, конечно, понимаю, не во всех школах учат использованию массивов...
+58
// Released Under Affero General Public License, Version 3 (AGPL3)
// Author: [email protected]
$result = "TRUE";
$testable_string = strtolower($string_to_test);
$testable_string_length = strlen($string_to_test);
for($i_string = 0; $i_string < $testable_string_length; $i_string++)
{
$current_value_to_test = $testable_string[$i_string];
if( ($current_value_to_test != "0") &&
($current_value_to_test != "1") &&
($current_value_to_test != "2") &&
($current_value_to_test != "3") &&
($current_value_to_test != "4") &&
($current_value_to_test != "5") &&
($current_value_to_test != "6") &&
($current_value_to_test != "7") &&
($current_value_to_test != "8") &&
($current_value_to_test != "9") &&
($current_value_to_test != "a") &&
($current_value_to_test != "b") &&
($current_value_to_test != "c") &&
($current_value_to_test != "d") &&
($current_value_to_test != "e") &&
($current_value_to_test != "f") )
{
$result = "FALSE";
$i_string = $testable_string_length;
}
}
Смахивает на баян, но тем не менее.
http://php.net/manual/ru/function.is-numeric.php, из комментов.
+43
<?php
session_start();
if(empty($_SESSION['UserLogin']) or empty($_SESSION['UserId']))
{
header('Location: /');
}
else
{
if($_GET['mess_id'] == "")
{
header('Location: /');
}
else
{
include("application/db.config.php");
$GetUserIdQuery = mysql_query("SELECT id FROM Users WHERE id=".$_SESSION['UserId'], $db);
$UserIdArr = mysql_fetch_array($GetUserIdQuery);
$GetMessInfoQuery = mysql_query("SELECT * FROM Messages WHERE DialogId=".$_GET['mess_id'], $db);
$MessageInfoArr = mysql_fetch_array($GetMessInfoQuery);
if($UserIdArr['id'] != $MessageInfoArr['UserTo'])
{
header('Location: /');
}
else
{
mysql_close($db);
......................................................... и так далее...
}
}
}
В довесок к этому(http://govnokod.ru/12268), БЛ*АТЬ!
−113
-(void) reloadHelpMessage:(BOOL) _isPortrait
{
//ignoreDisappear = NO;
//ingnoreWillAppear = NO;
if (_isPortrait)
{
helpMessage.frame = CGRectMake(helpMessage.frame.origin.x, helpMessage.frame.origin.y, self.view.bounds.size.width, 175);
for (UIView* sub in [helpMessage subviews])
{
NSLog(@"__%@",[sub description]);
switch (sub.tag)
{
case 1:
sub.frame = CGRectMake(68, 17, 200, 18);
break;
case 2:
sub.frame = CGRectMake(68, 40, self.view.bounds.size.width - 70, 80);
break;
case 3:
sub.frame = CGRectMake(267, 3, 35, 29);
break;
case 4:
sub.frame = CGRectMake(10, 8, 48, 53);
break;
case 5:
sub.frame = CGRectMake(11, 128, roundf((self.view.bounds.size.width - 32)/2), 36);
break;
case 6:
sub.frame = CGRectMake(roundf((self.view.bounds.size.width/2) + 5), 128, roundf((self.view.bounds.size.width - 32)/2), 36);
break;
default:
break;
}
}
}
else
{
helpMessage.frame = CGRectMake(helpMessage.frame.origin.x, helpMessage.frame.origin.y, self.view.frame.size.width, 138);
for (UIView* sub in [helpMessage subviews])
{
NSLog(@"__%@",[sub description]);
switch (sub.tag)
{
case 1:
sub.frame = CGRectMake(68, 17, 200, 18);
break;
case 2:
sub.frame = CGRectMake(68, 40, self.view.bounds.size.width - 80, 40);
break;
case 3:
sub.frame = CGRectMake(400, 3, 35, 29);
break;
case 4:
sub.frame = CGRectMake(10, 8, 48, 53);
break;
case 5:
sub.frame = CGRectMake(11, 91, roundf((self.view.bounds.size.width - 32)/2), 36);
break;
case 6:
sub.frame = CGRectMake(roundf((self.view.bounds.size.width/2) + 5), 91, roundf((self.view.bounds.size.width - 32)/2), 36);
break;
default:
break;
}
}
}
}
+41
# POST /register
Public Function Register(){
foreach((array)$_POST as $k=>$v)
$_POST[$k] = addslashes(strip_tags($v));
$login = $_POST['Login'];
$password = $_POST['Password'];
$email = $_POST['Email'];
$firstname = $_POST['FirstName'];
$lastname = $_POST['LastName'];
$errors = array();
IF(!Session::Restore()){
Driver::Init();
IF(String::is_valid_email_address($email)){
IF(strlen($login) > 3 && strlen($login) <= 12 && String::Check('([a-zA-Z0-9_]+)', $login) ){
IF(strlen($password) > 5 && $password == $_POST['RePassword']){
$users = Collection::Get('users')->Select(Query::Equal('login', $login));
IF(!sizeof($users)){
$user = new User;
$user->login = strtolower($login);
$user->password = md5($password);
$user->regtime = time();
$photo = UploadedFiles::Get('Photo');
IF($photo)
IF($photo->exists){
$photoHash = md5('photo_'.$user->login);
$photosPath = APPLICATION_DIR.'/assets/uploads/photos';
$photo->Path = $photosPath.'/tmp/'.$photoHash;
ImageProcessing::MakeThumb($photo->Path, $photosPath.'/300/'.$photoHash.'.jpg', 100, 300, 500);
ImageProcessing::MakeThumb($photo->Path, $photosPath.'/100/'.$photoHash.'.jpg', 100, 100);
ImageProcessing::MakeThumb($photo->Path, $photosPath.'/50/'.$photoHash.'.jpg', 100, 50);
@unlink($photo->Path);
$user->photo = $photoHash;
}
$user->save();
Session::Link($login, $password);
return Router::Redirect('/profile');
}
else $errors[] = l('This username is already taken');
}
else $errors[] = l('Password length must be more than 3');
}
else $errors[] = l('Login length must be more than 3, and less than 13 characters and contain only Latin characters');
}
else $errors[] = l('Your email address must be in the format of [email protected]');
}
else $errors[] = l("You are already registered");
$view = new View('main.php');
return $view->Set('Content', 'registration.php')->Set('login', $login)->Set('email', $email)->Set('firstname', $firstname)->Set('lastname', $lastname)->Set('errors', $errors);
}
Ну так.
+57
// Просто удаляет элемент из массива
function delElement($arr, $index)
{
$result = Array();
for($i=0;$i<count($arr);$i++)
if($index != $i) $result[] = $arr[$i];
return $result;
}
- Ваше мнение, коллега?
- Кал молодой особи пыхаписта, коллега. Очень ярко выражены типичные признаки.
+161
function setOptionText(the_select1, the_array1, the_select2, the_array2)
{
the_select1.options.length=the_array1.length;
for (loop=0; loop < the_array1.length; loop++)
{
the_select1.options[loop].text = the_array1[loop];
the_select1.options[loop].value = the_array1[loop];
if (loop==0){
the_select1.options[loop].selected=true;
}
}
the_select2.options.length=the_array2.length;
for (loop=0; loop < the_array2.length; loop++)
{
the_select2.options[loop].text = the_array2[loop];
the_select2.options[loop].value = the_array2[loop];
if (loop==0){
the_select2.options[loop].selected=true;
}
}
}
Моему предшественнику, видимо, было лень вызывать два раза одну и ту же функцию, и потому он добавил в неё ещё два параметра и ещё девять строк кода.
+83
try{
name.toLowerCase();
}catch (NullPointerException e) {
report().error("java.lang.NullPointerException", e);
name = "";
}
Перспективная проверка на null