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

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

    +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
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    <?php
    
    require_once '../vendor/autoload.php';
    require_once 'functions.php';
    require_once 'KPFile.php';
    require_once 'KPLogger.php';
    
    use Intervention\Image\ImageManagerStatic as Шакализатор;
    
    Шакализатор::configure(array('driver' => 'imagick'));
    
    $logger = new KPLogger();
    
    function сжать(KPFile $шакал, $степеньСжатия, Array $ебучесть, $output) {
        $индексЕбучести = 0;
        if (!is_null($ебучесть[0])) {
            $индексЕбучести = $ебучесть[0];
        }
        if (!is_null($ебучесть[1]) && ($ебучесть[1] > $ебучесть[0])) {
            $индексЕбучести = $ебучесть[1];
        }
    
        $img = Шакализатор::make($шакал->path);
        $img->resize($ебучесть[0], $ебучесть[1], function ($constraint) {
            $constraint->aspectRatio();
            $constraint->upsize();
        });
        if ($img->mime() !== 'image/jpeg') {
            $img->encode('jpg', 100);
        }
        $img->save($output."$шакал->name-$индексЕбучести.jpg", $степеньСжатия);
    }
    
    function сжатьВсехШакалов($path, $степеньСжатия, $ебучестьШакалов, $output) {
        global $logger;
        $files = scandir($path);
        foreach($files as $key => $file) {
            $logger->colorLogWithFiles('blue', $file, $key);
            try {
                $шакал = new KPFile($path.$file);
                if ($шакал->type !== KPFile::FILE_TYPE_IMAGE) {
                    continue;
                }
                if (trim($шакал->name) == '') {
                    throw new Exception("file=$file, kpFileName=$шакал->name");
                }
                foreach ($ебучестьШакалов as $ебучесть) {
                    сжать($шакал, $степеньСжатия, $ебучесть, $output);
                }
            } catch (Exception $e) {
                $logger->exception($e, $key);
            }
        }
    }
    
    $степеньСжатия = 22;
    $ебучестьШакалов = [
        [60, 60],
        [38, 38]
    ];
    сжатьВсехШакалов('dataHeavy/carsOrig/', $степеньСжатия, $ебучестьШакалов, "../public/img/cars/");
    
    
    $logger->colorLogWithFiles('blue', '10/10 *** еб/шакалов', null, "\n");

    shakal of jpeg-street

    raduloh, 17 Октября 2019

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

    −105

    1. 1
    2. 2
    Это ATGC в заповеднике
    https://pbs.twimg.com/media/DofuZTmWsAEWfxw.jpg

    Я считаю, что после всех катастроф, которые обрушились на Россию в двадцатом веке, начиная с первой мировой и заканчивая перестройкой, тот факт, что Россия еще сохранилась и развивается, говорит, что у нашего народа имеется одна лишняя хромосома

    Dpyrou_Pycoqpo6_CEMA, 08 Октября 2019

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

    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
    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
    function toUrl(url, key, value) {
      if(url=='') url=window.location.href; 
      if(url.indexOf('//')<0) url='//'+url;
    
      // protocol
      var u=url.split(/\/?\//); 
      url={}; url.protocol=u.shift()+'//';
    
      // hostname
      url.hostname=u.shift().split(':'); 
      if(url.hostname.length>1) url.port=':'+url.hostname.pop()
      url.hostname=url.hostname.pop().split('@').pop();
    
      // сохраним порядок для последующей свертки
      url.pathname='/'; url.pagename=''; 
    
      try { 
        // hash
        url.search=u.pop().split(/#/); 
        if(url.search.length==2) url.sh='#'+url.search.pop();
        url.search=url.search.shift().split(/\?/);
        
        // pagename
        url.pagename=url.search.shift(); url.search=url.search[0]
      
        // pathname
        url.pathname+=u.join('/')+(u.length?'/':'');
      
        // разбор search, (c) Steven Benner, 2010
        try {
          var u = {};
          url.search.replace(
            new RegExp('([^?=&]+)(=([^&]*))?', 'g'),
            function($0, $1, $2, $3) { 
               u[$1] = decodeURIComponent($3); 
            }
          );
          url.search=u;
        } catch(e) { 
          delete url.search; 
        }
      } catch(e) { };
    
      // вернем URL как объект, где search так же
      // представлен объектом {key:value}
      if(!key && !value) return(url);
    
      // возвращаем значение ключа
      if(key && !value) return(url.search[key]);
    
      // roll up url
      var roll = function(url,search){
        var out='';
        for(var key in url) {
          out+=(search?'&'+key+'=':'')+(key=='search'?'?'+roll(url[key],1).substr(1):url[key]);
        };
        return out;
      };
      
      // устанавливаем значение ключа
      if(value) url.search[key]=value.toString(); 
      
      // сворачиваемся, с учетом порядка следования свойств
      return(roll(url));    
    }
    
    // применение
    console.log(toUrl('http://site.my:81/home/path/page.htm?a=1&b=2#hash','a',5));

    https://habr.com/ru/sandbox/126206/

    OCETuHCKuu_nemyx, 06 Октября 2019

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

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    ((ax + b)mod p) mod m
    
    Какое вообще у этой хеш-функции название?
    
    Я нашел только "Семейство универсальных хеш-функций"

    OlegUP, 02 Октября 2019

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

    −100

    1. 1
    Я Stertor

    rHujlb, 27 Сентября 2019

    Комментарии (4)
  7. 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)
  8. 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)
  9. Си / Говнокод #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)
  10. 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)
  11. 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)