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

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

    0

    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
    void Obmen_RS1(void)
    {
      uint8_t txbuf[7], rxbuf[43], CheckSum;
      //если сформирован запрос на чтение по RS1 - SSPC data
      if (SoftFlag.RS_Flag3.bit.RS1_Read_Req)
      {
        txbuf[0] = 0x7B; //{
        txbuf[1] = SSPC_Addr_RS[RS1_Counter];
        txbuf[2] = 0x00; //d0, b00000000 - команда для формирования и отправки посылки данных от SSPC
        txbuf[3] = 0x00;
        txbuf[4] = 0x00;
        txbuf[5] = txbuf[1];//(txbuf[1] ^ txbuf[2] ^ txbuf[3] ^ txbuf[4]); //xor [1..4]
        txbuf[6] = 0x7D; //}
        HAL_UART_Transmit(&huart1, (uint8_t *)&txbuf, 7, 1);
        //HAL_Delay(1)
        if (HAL_UART_Receive(&huart1, (uint8_t *)&rxbuf, 43, 9) == HAL_OK)
        { //если пришел правильный пакет
          if ((rxbuf[0] == 0x5B) 
           && (rxbuf[40] == SSPC_Addr_RS[RS1_Counter])
           && (rxbuf[42] == 0x5D))
          { //считаем КС
            for (j = 1; j < 41; j++)
              CheckSum ^= rxbuf[j];
            if (CheckSum == rxbuf[41])  //Если КС совпадает
            {
              for (j = 1; j < 41; j++)  //Сохраняем пакет в двумерный буфер
                RS1_Paket[RS1_Counter][j] = rxbuf[j];
            }
            else 
            {
              for (j = 1; j < 41; j++)
                RS1_Paket[RS1_Counter][j] = 0;  //Иначе пишем нули
            }
          }
        }
        RS1_Counter++;
        if (RS1_Counter > 15) 
          RS1_Counter = 0;
        SoftFlag.RS_Flag3.bit.RS1_Read_Req = 0; //сбрасываем флаг запроса чтения данных и ждем следующего по таймеру (100мс)
      }
    }

    Процедура чтения данных от 16 модулей управления нагрузками по RS-485...
    для STM32F4x с использованием калокуба

    ykypeHHbIu_nemyx, 10 Июля 2019

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

    −2

    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
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    <template>
      <div class="side-effects">
        <div class="side-effects__text" v-html="text"></div>
      </div>
    </template>
    
    <script>
        export default {
          name: 'SideEffects',
          data () {
            return {
              text: '<strong>JORNAY PM can cause serious side effects, including: </strong>' +
            '<ul>' +
            '<li>' +
            '<strong>Abuse and dependence.</strong> JORNAY PM contains methylphenidate. JORNAY PM, other methylphenidate-containing products, and\n' +
            'amphetamines have a high chance for abuse and can cause physical and psychological dependence. Your healthcare provider should check\n' +
            'you or your child for signs of abuse and dependence before and during treatment with JORNAY PM.' +
            '<ul>' +
            '<li>Tell your healthcare provider if you or your child has ever abused or been dependent on alcohol, prescription medicines, or street\n' +
            'drugs. </li>' +
            '<li> Your healthcare provider can tell you more about the differences between physical and psychological dependence and drug addiction. </li>' +
            '</ul>' +
            '</li>' +
            '<li>' +
            '<p class="mb-0"><strong>Heart-related problems, including:</strong></p>' +
            '<ul>' +
            '<li>sudden death, stroke, and heart attack in adults</li>' +
            '<li>sudden death in children who have heart problems or heart defects</li>' +
            '<li> increased blood pressure and heart rate </li>' +
            '</ul>' +
            '</li>' +
            '</ul>' +
            'Your healthcare provider should check you or your child carefully for heart problems before starting JORNAY PM. Tell your healthcare provider\n' +
            'if you or your child has any heart problems, heart defects, or high blood pressure.' +
            ' <p>Your healthcare provider should check your or your child’s blood pressure and heart rate regularly during treatment with JORNAY PM. </p>' +
            '<p><strong>Call your healthcare provider right away or go to the nearest hospital emergency room right away if you or your child has any signs of\n' +
            'heart problems such as chest pain, shortness of breath, or fainting during treatment with JORNAY PM. </strong></p>' +
            '<ul>' +
            '<li>' +
            '<strong>Mental (psychiatric) problems, including:</strong>' +
            '<ul>' +
            '<li>new or worse behavior and thought problems</li>' +
            '<li>new or worse bipolar illness</li>' +
            '<li>new psychotic symptoms (such as hearing voices, or seeing or believing things that are not real) or new manic symptoms </li>' +
            '</ul>' +
            '</li>' +
            '</ul>' +
            'Tell your healthcare provider about any mental problems you or your child has, or about a family history of suicide, bipolar illness, or\n' +
            'depression. ' +
            '<p><strong>Call your healthcare provider right away if you or your child have any new or worsening mental symptoms or problems during treatment\n' +
            'with JORNAY PM, especially hearing voices, seeing or believing things that are not real, or new manic symptoms</strong></p>' +
            '<strong>JORNAY PM can cause other serious side effects, including:</strong>' +
            '<ul>' +
            '<li>See <strong>“What is the most important information I should know about JORNAY PM?” </strong></li>' +
            '<li><strong>Painful and prolonged erections (priapism). </strong>Priapism has happened in males who take products that contain methylphenidate. If you or\n' +
            'your child develops priapism, get medical help right away</li>' +
            '<li>' +
            '<strong>Circulation problems in fingers and toes (peripheral vasculopathy, including Raynaud’s phenomenon). Signs and symptoms may\n' +
            'include:</strong>' +
            '<ul>' +
            '<li>fingers or toes may feel numb, cool, or painful</li>' +
            '<li> fingers or toes may change color from pale, to blue, to red </li>' +
            '</ul>' +
            '</li>' +
            '</ul>' +
            'Tell your healthcare provider if you or your child has numbness, pain, skin color change, or sensitivity to temperature in the fingers or toes. ' +
            '<strong>Call your healthcare provider right away if you or your child has any signs of unexplained wounds appearing on fingers or toes during\n' +
            'treatment with JORNAY PM.</strong>' +
            '<ul>' +
            '<li>' +
            '<strong>Slowing of growth (height and weight) in children</strong> Children should have their height and weight checked often during treatment with\n' +
            'JORNAY PM. JORNAY PM treatment may be stopped if your child is not gaining weight or height. ' +
            '</li>' +
            '</ul>' +
            '<strong>The most common side effects of methylphenidate products in children, adolescents, and adults with ADHD include:</strong>' +
            '<ul>' +
            '<li>decreased appetite</li>' +
            '<li>stomach pain</li>' +
            '<li>irritability</li>' +
            '<li>trouble sleeping</li>' +
            '<li>weight loss</li>' +
            '<li>mood swings (affect lability)</li>' +
            '<li>nausea</li>' +
            '<li>anxiety</li>' +
            '<li>increased heart rate</li>' +
            '<li>vomiting</li>' +
            '<li>dizziness</li>' +
            '<li>increased blood pressure</li>' +
            '<li>indigestion</li>' +
            '</ul>' +
            '<strorg>The most common side effects of JORNAY PM in children age 6 to 12 with ADHD include: </strorg>';
            }
          }
        }
    </script>

    Так вот зачем нужна data и v-html (VueJS)

    websbkinfo, 30 Мая 2019

    Комментарии (4)
  4. Си / Говнокод #25612

    +1

    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
    namespace belugina
    {
    void Simple_Merging_Sort (char *name){ 
    	 int a1, a2, k, i, j, kol, tmp;  
    	FILE *f, *f1, *f2;  
    	kol = 0;  
    	if ( (f = fopen(name,"r")) == NULL )    
    		printf("\nИсходный файл не может быть прочитан...");  
    	else {    while ( !feof(f) ) {      
    		fscanf(f,"%d",&a1);      
    		kol++;    
    		}   
    	 fclose(f);  
    	} 
    k = 1;  
    while ( k < kol ){ 
    	f = fopen(name,"r");    
    	f1 = fopen("smsort_1","w");    
    	f2 = fopen("smsort_2","w");   
    	if ( !feof(f) ) fscanf(f,"%d",&a1);    
    	while ( !feof(f) ){     
    		 for ( i = 0; i < k && !feof(f) ; i++ ){        
    			fprintf(f1,"%d ",a1); fscanf(f,"%d",&a1); }      
    		for ( j = 0; j < k && !feof(f) ; j++ ){        
    			fprintf(f2,"%d ",a1);  fscanf(f,"%d",&a1);}   
    	 }   
    	 fclose(f2);    fclose(f1);    fclose(f); 
    f = fopen(name,"w");   f1 = fopen("smsort_1","r");    
    	f2 = fopen("smsort_2","r");    
    	if ( !feof(f1) ) fscanf(f1,"%d",&a1);   
    	if ( !feof(f2) ) fscanf(f2,"%d",&a2);    
    	while ( !feof(f1) && !feof(f2) ){     
    	 	i = 0;      j = 0;     
    	 	while ( i < k && j < k && !feof(f1) && !feof(f2) ) {        
    			if ( a1 < a2 ) {          
    			fprintf(f,"%d ",a1); fscanf(f1,"%d",&a1);i++;}        
    			else {          
    			fprintf(f,"%d ",a2);fscanf(f2,"%d",&a2); j++;}      
    	   	} 
    while ( i < k && !feof(f1) ) {        
    		     fprintf(f,"%d ",a1);  fscanf(f1,"%d",&a1); i++;}      
    		while ( j < k && !feof(f2) ) {        
    		     fprintf(f,"%d ",a2);   fscanf(f2,"%d",&a2);  j++;}   
     	 }    
    	while ( !feof(f1) ) {      
    		fprintf(f,"%d ",a1);      fscanf(f1,"%d",&a1);    }    
    	while ( !feof(f2) ) {      
    		fprintf(f,"%d ",a2);      fscanf(f2,"%d",&a2);    }   
    	fclose(f2);    fclose(f1);    fclose(f);    k *= 2;  
    	}  
    	remove("smsort_1");  remove("smsort_2");
    } 
    }

    Вектор это не динамический массив.

    dethless, 19 Мая 2019

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

    +1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    function managerLogin(){
    	... //Запрос для входа менеджера
    	cookie.set('MANAGERSESSID', response.MANAGERSESSID);
           ...
    }
    
    function userLogin(){
    	... //Запрос для входа пользователя
    	cookie.set('LKSESSID', response.LKSESSID);
           ...
    }

    Фронтендер решил что бэки слишком медленные и тупые и поэтому теперь он сам будет заниматься менеджментом сессии.
    До этого был бэкер который тоже свои сесии изобретал, кое как починили.
    Но теперь у нас вместо одной сессии две.
    Теоретически их может быть больше.
    Код написан на react с очень большим кол-ом native js.
    Что посоветуете человеке?

    petrun, 03 Мая 2019

    Комментарии (4)
  6. PHP / Говнокод #25529

    0

    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
    // table for cart must have unique index for both columns for correct effect of this function
        function save() {
            if ($this->errno_ || !$this->db_link_)
                return;
                
            // optimized loop
            $n = count($this->products_) - 1;
            $s_query = "REPLACE INTO `". Config::DB_CART_TABLE_NAME ."` VALUES ";
            for($i = 0; $i < $n; ++$i) {
                $s_query .= "('". $this->phpsessid_ ."',". $this->products_[$i]->getId() .",". $this->counts_[$i] .",'". $this->sizes_[$i] ."')"; 
            }
            if ($n + 1) 
                $s_query .= "('". $this->phpsessid_ ."',". $this->products_[$n]->getId() .",". $this->counts_[$n] .",'". $this->sizes_[$n] ."')";
            
            print($s_query);
            $res = mysqli_query($this->db_link_, $s_query);
            if (!$res)
                $this->errno_ = IModel::E_DB_QUERY;
        }
    
    // Запрос сформирован некорректно, нету запятых между кортежами значений:/
    // REPLACE INTO `cart` VALUES ('cbn1c7ljjd3gglb2lmpa96grnq3prq2iefb2elvcb4fhr9r0qls1',700,4,'')('cbn1c7ljjd3gglb2lmpa96grnq3prq2iefb2elvcb4fhr9r0qls1',701,2,'')

    Опять мой говнокод.
    И это как-то србатывало О_о

    OlegUP, 10 Апреля 2019

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

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    foreach ($result->getDataCollection() as $data) {
        if (!$data->getStatus() === Status::PAID)
            continue;
    
        // ACTIONS
    }

    Зачем использовать !== если есть ===

    P/s
    Смотрим на if (

    genkaok, 21 Марта 2019

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

    0

    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
    protected function validateArguments(array $argv = null)
    {
            $argc = count($argv);
    
            if (1 == $argc && is_array($argv[0])) {
                return $argv[0];
            }
    
            if (2 == $argc) {
                if (is_array($argv[0]) && (is_numeric($argv[1]) || is_null($argv[1]) || is_string($argv[1]))) {
                    $argv[0][] = $argv[1];
    
                    return $argv[0];
                }
    
                if ((is_numeric($argv[0]) || is_string($argv[0])) && (is_numeric($argv[1]) || is_string($argv[1]))) {
                    return $argv;
                }
            }
    
            if (3 == $argc) {
                if ((is_numeric($argv[0]) || is_string($argv[0])) && (is_numeric($argv[1]) || is_string($argv[1])) && (is_numeric($argv[2]) || is_null($argv[2]) || is_string($argv[2]))) {
                    return $argv;
                }
            }
    
            array_walk($argv, function (&$value) {
                if (is_array($value)) {
                    $value = 'Array';
                } else {
                    $value = sprintf('"%s"', $value);
                }
            });
    
            throw new InvalidValueException(sprintf('Invalid parameters passed to %s::%s: %s', get_class($this), '__construct', implode(', ', $argv)));
    }

    pahhan, 20 Февраля 2019

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

    0

    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
    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="UTF-8">
        <title>Calendar</title>
    </head>
    <body>
    
    <style>
    .month, .month.vert .week, .day { display:inline-block; }
    .month.vert .day { display:block; }
    .day { border:1px solid #ccc; width:30px; line-height:30px; text-align:center; }
    </style>
    
    <div class="month"></div>
    
    <script>
    var calendar = {
        update: function (year, month) {
            this.days.length = 7;
            var stepDay = new Date(year, month, 1);
            stepDay.setDate(1 - stepDay.getDay());
            var lastDay = new Date(year, month + 1, 0);
            lastDay.setDate(lastDay.getDate() + 6 - lastDay.getDay());
            while (stepDay <= lastDay) {
                this.days.push(stepDay.getDate());
                stepDay.setHours(24);
            }
        },
        render: function () {
            var html = '';
            for (var i = 0, j = 0; i < this.days.length; j = ++i % 7) {
                if (j == 0) html += '<div class="week">';
                html += '<div class="day">' +  this.days[i] + '</div>';
                if (j == 6) html += '</div>';
            }
            this.element.innerHTML = html;
        },
        toggle: function () {
            this.element.classList.toggle('vert');
        }
    };
    var today =  new Date, thisYear = today.getFullYear(), thisMonth = today.getMonth();
    calendar.days = ['S', 'M', 'T', 'W', 'T', 'F', 'S'];
    calendar.element = document.querySelector('.month');
    calendar.element.addEventListener('click', function () { calendar.toggle() });
    calendar.update(thisYear, thisMonth);
    calendar.render();
    </script>
    
    </body>
    </html>

    unicorn, 16 Февраля 2019

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

    +1

    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
    <div class="tablicmagazov">
        <h2>Розничные магазины</h2>
    
        <div class="tablica_magazinov">
            <div class="stroka_zagolovok_magazin">
                <div class="kolonka_magazin"></div>
                <div class="kolonka_magazin"></div>
                <div class="kolonka_magazin zagolovok_ico">Груминг</div>
                <div class="kolonka_magazin zagolovok_ico">Ветеринар</div>
                <div class="kolonka_magazin zagolovok_ico">Самовывоз</div>
            </div>
    	    <?foreach($arResult["ITEMS"] as $arItem):?>
                <div class="stroka_magazina">
                    <div class="kolonka_magazin">
                        <a href="<?echo $arItem['DETAIL_PAGE_URL']?>"><?echo $magazviv->metro($arItem['ID'], $magazviv->masskarta[0])[0];?></a>
                        <div class="voprosik_magazini">
                            ?
                            <div class="soderzimoe_voprosa">
                                <?echo $magazviv->metro($arItem['ID'], $magazviv->masskarta[3])[4];?>
                                <?echo $magazviv->metro($arItem['ID'], $magazviv->masskarta[4])[4];?>
                                <?echo $magazviv->metro($arItem['ID'], $magazviv->masskarta[5])[4];?>
                                <div class="strelka_dop_uslugi_vspliv"></div>
                            </div>
                        </div>
                    </div>
                    <div class="kolonka_magazin magaz_metro">
                        <div class="znachek_metro"><?echo $magazviv->metro($arItem['ID'], $magazviv->masskarta[2])[2];?></div>
                        <?echo $magazviv->metro($arItem['ID'], $magazviv->masskarta[1])[0];?>
                    </div>
                    <div class="kolonka_magazin ico_magaz"><?echo $magazviv->metro($arItem['ID'], $magazviv->masskarta[3])[1];?></div>
                    <div class="kolonka_magazin ico_magaz"><?echo $magazviv->metro($arItem['ID'], $magazviv->masskarta[4])[1];?></div>
                    <div class="kolonka_magazin ico_magaz"><?echo $magazviv->metro($arItem['ID'], $magazviv->masskarta[5])[1];?></div>
                </div>
    	    <?endforeach;?>
        </div>
    </div>

    #bitrix

    cheburator, 24 Января 2019

    Комментарии (4)
  11. 1C / Говнокод #25301

    +4

    1. 1
    2. 2
    3. 3
    Если ЭтаФорма.ВладелецФормы.ВладелецФормы.Объект.Заголовок = "Согласование контрагента " Или ЭтаФорма.ВладелецФормы.ВладелецФормы.Объект.Заголовок = "" Тогда
                 ЭтаФорма.ВладелецФормы.ВладелецФормы.Объект.Заголовок = "Согласование контрагента " + КонтрагентДО;
    КонецЕсли;

    Просто оставлю это здесь.
    Когда ж вы все передохните любители ВладельцевФормы через ВладельцаФормы.

    MaxBS, 11 Января 2019

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