1. Лучший говнокод

    В номинации:
    За время:
  2. PHP / Говнокод #7756

    +149

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    <?php
    
    /**
     * Login class.
     * Login is the data structure for keeping
     * user login form data. It is used by the 'login' action of 'SiteController'.
     */
    class Login extends CFormModel
    {
    	public $login;
    	public $pass;
    	public $rememberMe;
    
    	private $_identity;
    
    	public function rules()
    	{
                return array(
                    // username and password are required
                    array('login, pass', 'required', 'message'=>'поле {attribute} не может быть пустым'),
                    // rememberMe needs to be a boolean
                    array('rememberMe', 'boolean'),
                    // password needs to be authenticated
                    array('pass', 'authenticate'),
                );
    	}
    
    	/**
    	 * Declares attribute labels.
    	 */
    	public function attributeLabels()
    	{
                return array(
                    'login'=>'Логин',
                    'pass'=>'Пароль',
                    'rememberMe'=>'Запомнить',
                );
    	}
    
    	/**
    	 * Authenticates the password.
    	 * This is the 'authenticate' validator as declared in rules().
    	 */
    	public function authenticate($pass,$params)
    	{
                $this->_identity=new UserIdentity($this->login,$this->pass);
                if(!$this->_identity->authenticate())
                    $this->addError($pass, empty($params['message'])?'неправильный лоин или пароль':$params['message']);
    	}
    
    	/**
    	 * Logs in the user using the given username and password in the model.
    	 * @return boolean whether login is successful
    	 */
    	public function login()
    	{
                if($this->_identity===null)
                {
                    $this->_identity=new UserIdentity($this->login,$this->pass);
                    $this->_identity->authenticate();
                }
                if($this->_identity->errorCode===UserIdentity::ERROR_NONE)
                {
                    $duration=$this->rememberMe ? 3600*24*30 : 0; // 30 days
                    Yii::app()->user->login($this->_identity,$duration);
                    return true;
                } else {
                    return false;
                }
    	}
    }

    модель логина

    xyzdsnxyz, 03 Сентября 2011

    Комментарии (2)
  3. PHP / Говнокод #7753

    +158

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    if ($_SERVER['HTTP_X_OPERAMINI_PHONE_UA']) {$browsus = htmlspecialchars(stripslashes($_SERVER['HTTP_X_OPERAMINI_PHONE_UA']));} elseif($_SERVER['HTTP_USER_AGENT']) {$browsus=htmlspecialchars(stripslashes($_SERVER['HTTP_USER_AGENT']));} else {$browsus='Неопределен';}
    $browser=strtok($browsus,'(');
    $browser=strtok($browser,' ');
    $browser=substr($browser,0,22);
    $browser=preg_replace('#http://#i','', $browser);

    о как

    jQuery, 02 Сентября 2011

    Комментарии (2)
  4. C++ / Говнокод #7737

    +153

    1. 1
    2. 2
    3. 3
    bool (A::*F[2])(int);
    //...
    return (this->*F[n])(i);

    CPPGovno, 02 Сентября 2011

    Комментарии (2)
  5. ActionScript / Говнокод #7705

    −124

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    if(!flashVarsPriority) //Если данные из конфига приоритетнее флешварсов
    	saveFlashVars(flashVars);
    
    //Тут парсим XML конфиг
    ...
    //много строк
    
    if(flashVarsPriority) //если флешварсы приоритетнее
    	saveFlashVars(flashVars);

    Werdn, 30 Августа 2011

    Комментарии (2)
  6. Python / Говнокод #7531

    −90

    1. 1
    2. 2
    def delay():
        return random.randrange(0,20)+20

    Pyhpon, 12 Августа 2011

    Комментарии (2)
  7. Java / Говнокод #7524

    +76

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    public static java.sql.Date StringToDate(String sDate) {
    	java.sql.Date Date = null;
    	if (!sDate.startsWith("00000000")) {
    		DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    		try {
    			Date rdate = dateFormat.parse(sDate);
    			Date = new java.sql.Date(rdate.getTime());
    		} catch (Exception e) {
    		}
    	}
    	return Date;
    }

    foGa, 12 Августа 2011

    Комментарии (2)
  8. PHP / Говнокод #7495

    +147

    1. 1
    2. 2
    3. 3
    4. 4
    <?php
    
    $cacheUrlKey = array( date( 'Y-m-d' ), $bsKey, $positionId, 'hopheynananei_tolidelvoprosovnet', $url );
    $cacheEverythingKey = array( date( 'Y-m-d' ), $bsKey, $positionId, 'hopheynananei_chtonigovori' );

    1999, 09 Августа 2011

    Комментарии (2)
  9. Куча / Говнокод #7464

    +128

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    $w=isset($_POST['w'])?(int)$_POST['w']:time();
        $p=$w-(24*3600)*7;
        $n=$w+(24*3600)*7;
    	mysql_query("set @start=date_format(date_sub(from_unixtime($w), interval weekday(from_unixtime($w)) day), '%m%d'),
    		@end=date_format(date_add(from_unixtime($w), interval 6-weekday(from_unixtime($w)) day), '%m%d')");
        
    	$ste=mysql_fetch_assoc(mysql_query('select @start as s,@end as e'));
    	 if($_SESSION['userinfo']['login']=='Stormsfb') echo "date_format(date_sub(from_unixtime($w), interval weekday(from_unixtime($w)) day), '%m%d') <br>date_format(date_add(from_unixtime($w), interval 6-weekday(from_unixtime($w)) day), '%m%d')<br>".
    							"select *,unix_timestamp(d) as u,
    							date_format(d,'%e %b') as dm,
    							date_format(d,'%m%d') as md,
    							date_format(d,'%d.%m.%y') as mdf from users where 
                        date_format(d, '%m%d') between 
                        ".($_POST['month']!='false'?
    					date('m',$w).'01 and '.date('mt',$w):
    					($ste['s']>$ste['e']?' @start and 1231
    					or date_format(d, "%m%d") between '.date('m',$n).'01 and @end ':' @start and @end '))." order by ".($_POST['month']=='false'?'weekday(d)':'date_format(d,"%m%d")');
    	$q=mysql_query("select *,unix_timestamp(d) as u,
    							date_format(d,'%e %b') as dm,
    							date_format(d,'%m%d') as md,
    							date_format(d,'%d.%m') as mdf from users where 
                        date_format(d, '%m%d') between 
                        ".($_POST['month']!='false'?
    					date('m',$w).'01 and '.date('mt',$w):
    					($ste['s']>$ste['e']?' @start and 1231
    					or date_format(d, "%m%d") between '.date('m',$n).'01 and @end ':' @start and @end '))." order by ".($_POST['month']=='false'?'md':'date_format(d,"%m%d")'),_LINK_) or die(mysql_error(_LINK_)); // || $ste['s']>$ste['e']
    					/*
    					это пиздец
    					"select *,unix_timestamp(d) as u,
    							date_format(d,'%e %b') as dm,
    							date_format(d,'%m%d') as md,
    							date_format(d,'%d.%m') as mdf from users where 
                        date_format(d, '%m%d') between 
                        ".($_POST['month']!='false'?
    					date('m',$w).'01 and '.date('mt',$w):
    					($ste['s']>$ste['e']?' @start and 1231
    					union select *,unix_timestamp(d) as u,
    							date_format(d,"%e %b") as dm,
    							date_format(d,"%m%d") as md,
    							date_format(d,"%d.%m") as mdf from users where 
                        date_format(d, "%m%d") 
    					between '.date('m',$n).'01 and @end ':' @start and @end '))." order by date_format(d, '%m%d')"
    					*/

    после нас хоть трава не расти!

    GoodTalkBot, 05 Августа 2011

    Комментарии (2)
  10. C# / Говнокод #7456

    +126

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    public bool NewOrder {
        get {
            if( !string.IsNullOrEmpty( Request.QueryString[ "NewOrder" ] ) ) {
                ViewState[ "NewOrder" ] = Request.QueryString[ "NewOrder" ] == "true" ? true : false;
            } else {
                if( ViewState[ "NewOrder" ] != null )
                    return ( bool ) ViewState[ "NewOrder" ];
                else
                    ViewState[ "NewOrder" ] = true;
                }
            return ( bool ) ViewState[ "NewOrder" ];
        }
        set { ViewState[ "NewOrder" ] = value; }
    }

    Eugene, 05 Августа 2011

    Комментарии (2)
  11. PHP / Говнокод #7450

    +147

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    $em = '';
    	    foreach(array_unique(explode(',', $ae)) as $u) {
    		 if(!$u)
    		    continue;
    		  if($em)
    		    $em .= ',';
    		$em .= $u;
    	    }

    Кому сколько времени понадобилось, чтоб понять, что делает этот код?

    partizan22, 05 Августа 2011

    Комментарии (2)