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

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

    +166

    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
    void СSomeClass::InternalRemovePath( QString qsPath, int pUIModule )
    {
      QProgressDialog * pDlg = (QProgressDialog *)pUIModule;
    ...................
    }
    .......................
    void someFunction ()
    {
    ..................
    QProgressDialog * pProgress = NULL;
    pProgress = new QProgressDialog( QObject::tr( "Deleting...") , QObject::tr( "Abort" ), 0, nTotal, NULL );
    InternalRemovePath( qsPath , (int) pProgress );
    ..................
    }

    И по коду таких вещей (приведение указателей к int при передаче в функции) очень много. Пока собрал проект, задолбался.
    Интересно, что автор курил? Хотя, нет - тут уже что-то потяжелее.

    panter_dsd, 23 Марта 2011

    Комментарии (52)
  3. C++ / Говнокод #5018

    +181

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    int maxOf5(int a, int b, int c, int d, int e) {
            int arr[5];
            arr[0] = a;
            arr[1] = b;
            arr[2] = c;
            arr[3] = d;
            arr[4] = e;
            bubbleSort(&arr, 5);
            return arr[0];
    }

    no comments...

    wh_, 22 Декабря 2010

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

    +145

    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
    <? 
    // Функция для того, чтобы иЗ***оВаТь текст 
    $str = 'бросайте вы корявить текст'; 
    
    function koryavka ($t){ 
    $c = strlen($t); 
    
    for($i=0;$i<$c;$i++) { 
    $t[$i] = (is_int($i/2)) ? strtoupper($t[$i]) : $t[$i]; 
    $ret[] =  $t[$i];  
    } 
    
    return implode('',$ret); 
    } 
    
    echo koryavka ($str); 
    ?>

    Aligan, 01 Декабря 2010

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

    +151

    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
    function addimagesave()
    	{
    		if (!$this->Login->isLogged())
            {
                $this->loginto();
                return;
            }
            else $this->Login->Update();
    		$error = '';
    		$recordExists = false;
    		$post_name = trim($this->input->post('name'));
    		if ($post_name != '') $insert['file_name'] = $post_name;
    		// now need to get from db if id_all in i_pics
    		$this->db->where('id_all',$this->input->post('id_all'));
    		$this->db->limit(1);
    		$query = $this->db->get('i_pics');
    		if ($query->num_rows() == 1)
    		{
    			$row = $query->row();
    			$recordExists = true;
    			$file_name = $row->file_name;
    			$id_pics = $row->id_pics;
    		}
    		if (isset($_FILES['upload']) && ($_FILES['upload']['error'] == 0)) // is file loaded?
    		{
    			$ext = getExtensionOnly($_FILES['upload']['name']);
    			if ($post_name != '') $_FILES['upload']['name'] = $post_name.'.'.$ext;
    			else $post_name = delExtensionWithDot($_FILES['upload']['name']);
    			$_FILES['upload']['name'] = translitIt(delExtensionWithDot($_FILES['upload']['name'])).'.'.$ext;
    			$config['upload_path'] = './pics/';
    			$config['allowed_types'] = 'gif|jpg|png|bmp';
    			$this->load->library('upload', $config);
    			if ($this->upload->do_upload('upload'))
    			{
    				$this->General->setEmes(array('roster'=>"Картинку загружено."), true);
    				$data = $this->upload->data();
    				$insert['file_name'] = $data['file_name'];
    				// resize now
    				$config1['image_library'] = 'gd2'; // выбираем библиотеку
    				$config1['source_image'] = 'pics/'.$data['file_name'];
    				$config1['create_thumb'] = TRUE; // ставим флаг создания эскиза
    				$config1['maintain_ratio'] = true; // сохранять пропорции
    				$config1['width'] = 250; // и задаем размеры
    				$config1['height'] = 180;
    				// pre crack image for resizing! )))
    				$this->load->model('Image');
    				$this->Image->smartsigninto('pics/'.$data['file_name'], 250, 180);
    				$this->load->library('image_lib', $config1); // загружаем библиотеку
    				$this->image_lib->resize(); // и вызываем функцию
    				// now rename and owerwrite original image
    				$ext = getExtensionOnly($data['file_name']);
    				$fol = "pics/";
    				if (is_file($fol.$data['raw_name'].'_thumb.'.$ext))
    				rename($fol.$data['raw_name'].'_thumb.'.$ext, $fol.$data['file_name']);
    				else $this->General->setEmes(array('roster'=>"Файл *_thumb не был создан!"));
    				// now set new file size
    				$insert['size'] = round(filesize($fol.$data['file_name'])/1024 , 2);
    			}
    			else $this->General->setEmes(array('roster'=>$this->upload->display_errors()));
    		}
    		else // we need to try to rename assigned file if name is not empty and file exists
    		{
    			if ($recordExists && is_file('pics/'.$file_name) && ($post_name != ''))
    			{
    				$ext = getExtensionOnly($file_name);
    				$fol = "pics/";
    				$newName = translitIt($post_name).'.'.$ext;
    				if (is_file('pics/'.$newName))
    				{
    					$this->General->setEmes(array('roster'=>"Имя уже существует"), true);
    					$insert['file_name'] = $file_name;
    				}
    				else
    				{
    					rename($fol.$file_name, $fol.$newName);
    					$insert['file_name'] = $newName;
    				}
    			}
    		}
    		// prepare data to be ins or upd
    		$insert['lang'] = 'ru';
    		$insert['title'] = $this->input->post('title');
    		$insert['alt'] = $this->input->post('alt');
    		$insert['id_all'] = $this->input->post('id_all');
    		if ($recordExists)
    		{
    			$this->db->where('id_pics',$id_pics);
    			$this->db->update('i_pics', $insert);
    			$this->General->setEmes(array('roster'=>"Данные обновлены"), true);
    		}
    		else $this->db->insert('i_pics', $insert);
    		$this->redirect('roster/'.$this->input->post('type'));
    	}

    Функция - контроллер сохранения, resize на лету картинки для новости или прочей байды. Есть все проверки. Любая картинка которая приходит, становится размером 250, 180 , причем без растяжения. Это задача типа вписать прямоугольник в прямоугольник, которую я сейчас ночью выполнил - даже если картинка меньше оно впишет. I must be proud about this functionality! Заметим, что в интернете все и умеют что вырезать квадраты из картинки, а произвольный размер - НЕТ такого. Код выложен чтобы вы посмотрели, нравятся ли вам имена переменных, логическое мышление, форматирование, коментарии (на русском - то не мои коментарии). Код CodeIgniter powered.

    increazon, 25 Июня 2010

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

    +162

    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
    <a href="/otherss/foto/">Фото</a><br>
    <!-- *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= -->
    <?
    $ip=$REMOTE_ADDR;
    $modip=substr($ip,0,7);
        if ($modip=="192.168")
        {
        echo "<a href=\"http://192.168.1.1:8000/\">Радио</a><hr>";
    //    echo "<a>Радио</a><br>";
        }
        else
        {
        echo "<a href=\"http://92.255.xxx.10:8000/\">Радио</a><hr>";
    //    echo "<a>Радио</a><br>";
        }
    
        if ($modip=="192.168")
        {
        echo "<a href=\"http://192.168.1.1:3000/\">Вэб-Почта</a><br>";
        }
        else
        {
        echo "<a href=\"http://92.255.xxx.10:3000/\">Вэб-Почта</a><br>";
        }
    ?>
    <a href="/filesearch/index.php">Поиск</a><br>
    <a href="http://192.168.1.1/stat/kabinet">Кабинет&#133;</a><br>
    <a href="/phone_book/">Телефон</a><a href="/phone_book/index_all.php">ы</a><br>
    <br>

    снова один из отжигов)
    маска xxx в третьем бите ип моя, чтоб не палить)

    nur, 18 Июня 2010

    Комментарии (52)
  7. C# / Говнокод #3334

    +124

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    char arr[] = ... // Здесь происходит чтение массива, неважно как
    string result = "";
    for(int i = 0; i < arr.Length; i++) 
    {
        result += Char.ToString(arr[i]);
    }
    
    Console.WriteLine(result);

    Что интересно, автор уже пол года на C# пишет, до этого 2 года на Java. Решение ко всему прочему еще и очевидно с квадратичной сложностью. А должно быть, естественно Console.WriteLine(new String(array));

    theos, 27 Мая 2010

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

    +162.1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    if ( !empty($a1) ||
         !empty($a1) && !empty($a2) ||
         !empty($a1) && !empty($a2) && !empty($a3) ||
         !empty($a1) && !empty($a2) && !empty($a3) || && !empty($a4) ||
         !empty($a1) && !empty($a2) && !empty($a3) || && !empty($a4) || && !empty($a5) ||
    ...
         !empty($a1) && !empty($a2) && !empty($a3) || && !empty($a4) || && !empty($a5) || && ... !empty($a8) )
    {
     // что-то делать...
    }

    Уже и не припомню где именно, но всретил я такую проверочку на рабочем сайте:
    После небольшой оптимизации получилось нормально условие... кто скажет какое ???

    Death, 24 Февраля 2010

    Комментарии (52)
  9. PHP / Говнокод #1773

    +152.8

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    function clearUsers()
    {
    	$f=fopen("users", "w");
    	fclose($f);
    	return 0;
    }

    Tanger, 06 Сентября 2009

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

    −115.8

    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
    try{
       memcpy(pbSourceData, pbDestData + sizeof(tc_version) + sizeof(dwSenderNameLen) + dwSenderNameLen, key_len);
    }
    catch(...) {
       ret = EX_ERROR;
       goto err;
    }
    
    try{
       memcpy(pbKeyData, pbSignData + sizeof(tc_version) + sizeof(dwSenderTPLen) + dwSenderTPLen, key_len);
    }
    catch(...) {
       ret = EX_ERROR;
       goto err;
    }

    Аналогичные куски повторяются раз 10 друг за другом с другими переменными.

    guest, 12 Декабря 2008

    Комментарии (52)
  11. Си / Говнокод #29101

    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
    typedef struct ll_node
    {
      struct ll_node *prev;
      struct ll_node *next;
      int val;
    } ll_node;
    
    ll_node a;
    ll_node b;
    ll_node c = {&a, &b,3};
    
    // не работает
    a.next = &b;
    a.prev = &c;
    
    b.next = &c;
    b.prev = &a;
    
    /*
    c.next = &a;
    c.prev = &b;
    */
    
    // зато так работает:
    ll_node arr[3] = {
      {&arr[2], &arr[1],1},
      {&arr[0], &arr[2],2},
      {&arr[1], &arr[0],3}
    };

    Кольцевой двусвязный список.

    j123123, 10 Марта 2025

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