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

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

    +58

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    if ($who == 'student') $answerArray['student_id'] = $this->people->id;
    if ($who == 'teacher') $answerArray['teacher_id'] = $this->people->id;
    if ($who == 'student') $answerArray['student_text'] = $post_array['message'];
    if ($who == 'teacher') $answerArray['teacher_text'] = $post_array['message'];
    if ($who == 'student') $answerArray['student_date'] = date('Y-m-d H:i:s');
    if ($who == 'teacher') $answerArray['teacher_date'] = date('Y-m-d H:i:s');
    if ($who == 'student' && $files) $answerArray['student_file'] = $files[0]['name'];
    if ($who == 'teacher' && $files) $answerArray['teacher_file'] = $files[0]['name'];
    if ($who == 'student' && $files) $answerArray['student_file_orig_name'] = $files[0]['orig_name'];
    if ($who == 'teacher' && $files) $answerArray['teacher_file_orig_name'] = $files[0]['orig_name'];
    if ($who == 'student') $answerArray['status'] = 0;
    if ($who == 'teacher') $answerArray['status'] = 1;

    Обнаружил в корпоративном коде. )

    MikleSmart, 15 Мая 2012

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

    +78

    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
    class uagent_info
    {
       //standardized values for true and false.
       var $true = 1;
       var $false = 0;
    
       function XXX() {
          if (...) {
          	return $this->true;
          } else {
          	return $this->false;
          }
       }
    }

    http://code.google.com/p/mobileesp/source/browse/PHP/mdetect.php

    neanton, 14 Мая 2012

    Комментарии (5)
  4. JavaScript / Говнокод #10260

    +157

    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
    $(document).click(function (e) {
        if ($(e.target).parents().filter('#idAddItTopPopUpMenu:visible').length != 1) {
            $('#idAddItTopPopUpMenu').hide();
        }
        if ($(e.target).parents().filter('#idAddItProductDetailPopUpMenu:visible').length != 1) {
            $('#idAddItProductDetailPopUpMenu').hide();
        }
        if ($(e.target).parents().filter('#idPampItProductDetailPopUpMenu:visible').length != 1) {
            $('#idPampItProductDetailPopUpMenu').hide();
        }
        if ($(e.target).parents().filter('#idPrivacyProductPopUpMenu:visible').length != 1) {
            $('#idPrivacyProductPopUpMenu').hide();
        }
        if ($(e.target).parents().filter('#idSocialNetworkMenu:visible').length != 1) {
            $('#idSocialNetworkMenu').hide();
        }
        if ($(e.target).parents().filter('#idPampItTopPopUpMenu:visible').length != 1) {
            $('#idPampItTopPopUpMenu').hide();
        }
    . . .
        if ($(e.target).parents().filter('div[id=idAreaLastMessage]:visible').length != 1 && $(e.target).parents().filter('div[id=idbtnMessages]').length != 1) {
            $('div[id=idListLastMessage]').hide();
        }
        if ($(e.target).parents().filter('div[id=idAreaLastAlert]:visible').length != 1 && $(e.target).parents().filter('div[id=idbtnAlert]').length != 1) {
            $('div[id=idListLastAlert]').hide();
        }
        if ($(e.target).parents().filter('div[id=idAreaNearestCalendar]:visible').length != 1 && $(e.target).parents().filter('div[id=idbtnNearestCalendar]').length != 1) {
            $('div[id=idListNearestCalendar]').hide();
        }
    });

    нет слов o_O

    DarkThinker, 14 Мая 2012

    Комментарии (5)
  5. PHP / Говнокод #10254

    +68

    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
    <span class="realty_price"><?php echo $ad['price']?>
                        <?php if(! empty($ad['addinfo']['unit'])): ?>
                          <?php echo $ad['addinfo']['unit']['value'] ?>
                          <?php
                          unset($ad['addinfo']['unit']);
                          else:
                          ?>
                          <?php
    					  // Говнокод
    					  if($ad['addinfo']['type_service']['value'] == 'аренда'):
    					  ?>
                          руб.мес.
                          <?php else: ?>
                          тыс.руб.
                          <?php endif; ?>
                        <?php endif; ?>
                      </span>

    Хороший человек, искренний...

    nethak, 12 Мая 2012

    Комментарии (5)
  6. C# / Говнокод #10244

    +96

    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
    List<LocalBusiness> sortedLocalBusinesses = new List<LocalBusiness>();
    foreach (LocalBusiness business in foundLocalBusinesses)
    {
    	if (!business.Logo.UrlSmall.Equals("/images/local_business_default_logo.png"))
    	{
    		sortedLocalBusinesses.Add(business);
    	}
    }
    foreach (LocalBusiness business in foundLocalBusinesses)
    {
    	if (business.Logo.UrlSmall.Equals("/images/local_business_default_logo.png"))
    	{
    		sortedLocalBusinesses.Add(business);
    	}
    }

    Сортировка - первыми должны быть объекты с не дефолтными картинками.

    mastermindCsharp, 11 Мая 2012

    Комментарии (5)
  7. PHP / Говнокод #10224

    +74

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    if($this->getRequest()->isPost()) {
    			$month = $this->getRequest()->getPost('month', null);
    			$year  = $this->getRequest()->getPost('year', null);
    		} else {
    			$month = $this->getRequest()->getParam('month', null);
    			$year  = $this->getRequest()->getParam('year', null);
    		}

    Индусы, такие индусы.

    anycolor, 09 Мая 2012

    Комментарии (5)
  8. Куча / Говнокод #10207

    +123

    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
    <table border="0" id="table" width="800" align="center">
    <tr><td colspan="5" align="center">Ваш заказ:</td></tr>
    
    <? $query=mysql_query("Select * from `$name`");
    for ($c=0; $c<mysql_num_rows($query);$c++){
    ?><?
    $result=mysql_fetch_array($query);
    $a=$result['menu_id'];
    $query1=mysql_query("SELECT * FROM menu WHERE id=$a");
    $result1=mysql_fetch_array($query1);
    ?>
    
    <tr><td width="50"><? echo $c+'1'; ?></td><td width="50" align="center"><img src="img/tira.png" style="height:20px; width:20px;"/></td><td><? echo $result1['name'];?></td><td><a href="#">-</a><input type="text" min="1" value="<? echo $result['count'];?>" max="40" size="2" /><a href="#" onclick="up()">+</a></td><td>удалить</td></tr>
    <script language="javascript" type="application/javascript">
    var a=parseInt("<? echo $result['count'];?>");
    function up(){
    var b = a + 1;
    document.write(b);
    }
    </script>
    <?
    }
    ?>

    "Создаю корзину покупателя! Формирую таблицу выбранных пользователем товаров и его кол-во в цикле! добавил функцию на OnClick с выводом значение в ячейке! при нажатии выводит только значение последнего товара из цикла." Слов нет.

    zloirock, 06 Мая 2012

    Комментарии (5)
  9. Objective C / Говнокод #10200

    −153

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    - (void)dealloc {
        LandscapeNote *tempCell;
        for (NSInteger i = 0; i < [_scrollView.subviews count]; i++) {
            tempCell = [_scrollView.subviews objectAtIndex:i];
            [tempCell removeFromSuperview];
        }
        [notesArray release];
        [self viewDidUnload];
        [super dealloc];
    }

    смотрим название метода...

    kilovata, 05 Мая 2012

    Комментарии (5)
  10. PHP / Говнокод #10167

    +90

    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
    if(!empty($_POST))
    {
    	include("dbconnect.php");
    
    	$shown_name=$_POST['shown_name'];
    	$username=$_POST['username'];
    	$header=$_POST['header'];
    	$text=$_POST['text'];
    
    	$date_array=getdate(time());
    
    	$date=$date_array['hours'].":".$date_array['minutes'].":".$date_array['seconds']." ".$date_array['weekday']." ".$date_array['mday']." ".$date_array['month']." ".$date_array['year'];
    
    
    	$filename=$date_array['hours']."-".$date_array['minutes']."-".$date_array['seconds']."-".$date_array['mday'].$date_array['month']."-".$date_array['year']."-".$username.".php";
    
    	$path="posts/".$filename;
    
    	$addpost="INSERT INTO posts(author, header, text, date, path) VALUES ('$shown_name', '$header', '$text', '$date', '$path')";
    	$add=$db->prepare($addpost);
    	$add->execute();
    
    
    
    
    	$file=fopen($path, 'w');
    	$content="<?php \$shown_name=\"".$shown_name."\"; \$header=\"".$header."\"; \$text=\"".$text."\";  include(\"template.html\"); ?>";
    
    	$write=fwrite($file, $content);
    
    	fclose($file);
    
    
    	header('Location: index.php');
    	$db=null;
    }

    Добавление поста в блог. Радует каждая строчка.

    nucleartux, 02 Мая 2012

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

    +93

    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
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    class Auth_Yadis_ParanoidHTTPFetcher extends Auth_Yadis_HTTPFetcher {
        function get($url, $extra_headers = null)
        {
        /* неcущественное пропущено */
                if (defined('CURLOPT_NOSIGNAL')) {
                    curl_setopt($c, CURLOPT_NOSIGNAL, true);
                }
    
                if (!$this->allowedURL($url)) {
                    Auth_OpenID::log("Fetching URL not allowed: %s",
                                     $url);
                    return null;
                }
    
                curl_setopt($c, CURLOPT_WRITEFUNCTION,
                            array($this, "_writeData"));
                curl_setopt($c, CURLOPT_HEADERFUNCTION,
                            array($this, "_writeHeader"));
    
                if ($extra_headers) {
                    curl_setopt($c, CURLOPT_HTTPHEADER, $extra_headers);
                }
    
                $cv = curl_version();
                if(is_array($cv)) {
                  $curl_user_agent = 'curl/'.$cv['version'];
                } else {
                  $curl_user_agent = $cv;
                }
                curl_setopt($c, CURLOPT_USERAGENT,
                            Auth_OpenID_USER_AGENT.' '.$curl_user_agent);
                curl_setopt($c, CURLOPT_TIMEOUT, $off);
                curl_setopt($c, CURLOPT_URL, $url);
    
                if (defined('Auth_OpenID_VERIFY_HOST')) {
                    // set SSL verification options only if Auth_OpenID_VERIFY_HOST
                    // is explicitly set, otherwise use system default.
                    if (Auth_OpenID_VERIFY_HOST) {
                        curl_setopt($c, CURLOPT_SSL_VERIFYPEER, true);
                        curl_setopt($c, CURLOPT_SSL_VERIFYHOST, 2);
                        if (defined('Auth_OpenID_CAINFO')) {
                            curl_setopt($c, CURLOPT_CAINFO, Auth_OpenID_CAINFO);
                        }
                    } else {
                        curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
                    }
                }
    
                curl_exec($c);
        /* неинтересное пропущено */
        }
        
        function post($url, $body, $extra_headers = null)
        {
            if (!$this->canFetchURL($url)) {
                return null;
            }
    
            $this->reset();
    
            $c = curl_init();
    
            if (defined('CURLOPT_NOSIGNAL')) {
                curl_setopt($c, CURLOPT_NOSIGNAL, true);
            }
    
            curl_setopt($c, CURLOPT_POST, true);
            curl_setopt($c, CURLOPT_POSTFIELDS, $body);
            curl_setopt($c, CURLOPT_TIMEOUT, $this->timeout);
            curl_setopt($c, CURLOPT_URL, $url);
            curl_setopt($c, CURLOPT_WRITEFUNCTION,
                        array($this, "_writeData"));
    
            if (defined('Auth_OpenID_VERIFY_HOST')) {
                // set SSL verification options only if Auth_OpenID_VERIFY_HOST
                // is explicitly set, otherwise use system default.
                if (Auth_OpenID_VERIFY_HOST) {
                    curl_setopt($c, CURLOPT_SSL_VERIFYPEER, true);
                    curl_setopt($c, CURLOPT_SSL_VERIFYHOST, 2);
                    if (defined('Auth_OpenID_CAINFO')) {
                        curl_setopt($c, CURLOPT_CAINFO, Auth_OpenID_CAINFO);
                    }
                } else {
                    curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
                }
            }
    
            curl_exec($c);
    /* to be continued */

    Фрагмент едва ли не самой популярной библиотеки OpenID, а именно клиентской части: http://janrain.com/openid-enabled/
    Всё бы было хорошо, но залогиниться, используя лайвджорналовский опенайдишник, не получается. По форумам поползли слухи, что ЖЖ не полностью поддерживает протокол OpenID (хотя протокол разработал Фицпатрик, один из создателей LiveJournal); что он метод POST не поддерживает, поэтому его нужно менять на GET; предлагались совершенно безумные хаки, которые на самом деле не работают...

    А ларчик просто открывался. Для поддержки ЖЖ достаточно в приведённый код добавить пару строк. Открыть спойлер или кто-нибудь угадает?

    inkanus-gray, 25 Апреля 2012

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