1. PHP / Говнокод #1908

    +153.5

    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
    /**
    	* Выполняет запрос SELECT
    	*
    	* @param string  $tables      Список таблиц, разделённый запятыми
    	* @param string  $condition   Условие для выборки (WHERE)
    	* @param string  $order       Поля для сортировки (ORDER BY)
    	* @param string  $fields      Список полей для получения
    	* @param int     $lim_rows    Максимльное количество получаемых записей
    	* @param int     $lim_offset  Начальное смещение для выборки
    	* @param string  $group       Поле для группировки
    	* @param bool    $distinct    Вернуть только уникальные записи
    	*
    	* @return array
    	*/
    	function select($tables, $condition = '', $order = '', $fields = '', $lim_rows = 0, $lim_offset = 0, $group = '', $distinct = false)
    	{
    		if (is_bool($fields) || $fields == '1' || $fields == '0' || !is_numeric($lim_rows)) {
    			# Обратная совместимость c 1.2.x
    			$desc = $fields;
    			$fields = $lim_rows ? $lim_rows : '*';
    			$lim_rows = $lim_offset;
    			$lim_offset = $group;
    			$group = $distinct;
    			$distinct = func_num_args() == 9 ? func_get_arg(8) : false;
    			$query = 'SELECT ';
    			if ($distinct) $query .= 'DISTINCT ';
    			if (!strlen($fields)) $fields = '*';
    			$tables = str_replace('`' ,'', $tables);
    			$tables = preg_replace('/([\w.]+)/i', '`'.$this->prefix.'$1`', $tables);
    			$query .= $fields." FROM ".$tables;
    			if (strlen($condition)) $query .= " WHERE $condition";
    			if (strlen($group)) $query .= " GROUP BY $group";
    			if (strlen($order)) {
    				$query .= " ORDER BY $order";
    				if ($desc) $query .= ' DESC';
    			}
    			if ($lim_rows) {
    				$query .= ' LIMIT ';
    				if ($lim_offset) $query .= "$lim_offset, ";
    				$query .= $lim_rows;
    			}
    		} else {
    			$query = 'SELECT ';
    			if ($distinct) $query .= 'DISTINCT ';
    			if (!strlen($fields)) $fields = '*';
    			$tables = str_replace('`','',$tables);
    			$tables = preg_replace('/([\w.]+)/i', '`'.$this->prefix.'$1`', $tables);
    			$query .= $fields." FROM ".$tables;
    			if (strlen($condition)) $query .= " WHERE ".$condition;
    			if (strlen($group)) $query .= " GROUP BY ".$group."";
    			if (strlen($order)) {
    				$order = explode(',', $order);
    				for($i = 0; $i < count($order); $i++) switch ($order[$i]{0}) {
    					case '+': $order[$i] = substr($order[$i], 1); break;
    					case '-': $order[$i] = substr($order[$i], 1).' DESC'; break;
    				}
    				$query .= " ORDER BY ".implode(', ',$order);
    			}
    			if ($lim_rows) {
    				$query .= ' LIMIT ';
    				if ($lim_offset) $query .= "$lim_offset, ";
    				$query .= $lim_rows;
    			}
    		}
    		$result = $this->query_array($query);
    
    		return $result;
    	}

    nbyt, 28 Сентября 2009

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

    +100.4

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    public List<OrderGeneralVWJ> GetAll()
    {
         var q = from og in Context.OrderGeneralVWJs
              select new { 
                   og
              };
         return q.Select(r => r.og).ToList();
    }

    plsc_rover, 28 Сентября 2009

    Комментарии (10)
  3. Java / Говнокод #1906

    +76.3

    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
    Long orgId = 0L;
    try {
        orgId = Long.valueOf(textOrgId);
    } catch (Exception e) {
        orgId = 0L;
    }
    // ...
    Organization org = orgDAO.findById(orgId);
    if (org == null) {
        // не найдено? создать новую
        org = new Organization();
        // ...
    }

    Если с веба в поле textOrgId пришёл мусор, то создать новую организацию. Но перед этим всё равно поискать в базе несуществующий orgId=0.

    yvu, 28 Сентября 2009

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

    +83.5

    1. 1
    2. 2
    3. 3
    for (Person p : c) {
                return p;
            }

    yvu, 28 Сентября 2009

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

    −49.7

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    /**
     * Pause length in milliseconds.
     */
     private static final int _100000 = 100000;
     /**
     * Summary pause length in milliseconds.
     */
     private static final int _500000 = _100000 * 5;

    Автор творения сказал, что так удобнее читать код:)

    intr13, 28 Сентября 2009

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

    +94.5

    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
    /// Из aspx файла
    
    //<asp:Repeater ID="Repeater1" runat="server">
    //    <HeaderTemplate>
    //        <table width="100%" cellspacing="5">
    //    </HeaderTemplate>
    //    <ItemTemplate>
    //        <tr>
    //            <td>
    //                ...
    //            </td>
    //            <asp:Label runat="server" Visible='<%# DataBinder.Eval(Container.DataItem, "visibleCol2") %>'>
    //                <td>
    //                    ...
    //                </td>
    //            </asp:Label>
    //            <asp:Label ID="LCol3" runat="server" Visible='<%# DataBinder.Eval(Container.DataItem, "visibleCol3") %>'>
    //                <td>
    //                    ...
    //                </td>
    //            </asp:Label>
    //        </tr>
    //    </ItemTemplate>
    //    <FooterTemplate>
    //        </table>
    //    </FooterTemplate>
    //</asp:Repeater>
    
    // Из cs файла
    
    DataTable dtres = // получаем товары
    if (dtres != null && dtres.Rows.Count > 0)
    {
        DataTable dt = new DataTable();
    	/*...*/
        
        for (int i=0;i<dtres.Rows.Count;)
        {
            DataRow dr=dtres.Rows[i];
            /*...*/
    
            int col2Index = i + 1;
            if (col2Index < dtres.Rows.Count)
            {
                /*...*/
                i++;
                int col3Index = i + 1;
                if (col3Index < dtres.Rows.Count)
                {
                    /*...*/
                    i++;
                }
                else { /*...*/ }
            }
            else { /*...*/ }
    
            dt.Rows.Add(newRow);
            i++;
        }
    
        /*...*/
    }

    Человеку нужно было сделать товары в сетке 3x6.
    От того что он сделал у меня пропал дар речи. (Чтобы тут очень много кода не бы большую (не нужную для понимания) часть заменил на "...")
    Вобщем, в двух словах, он поместил вторую и третью ячейки таблицы в серверные контролы (причем в Label), а в коде берёт по три товара и засовывает в один RepeaterItem, ну а если количество товаров не делится нацело на три, то в последний RepeaterItem засовываются пустые данные, а Label делается невидимым.
    Как-то так.
    И самое главное, я не знаю, как человеку объяснить, что так нехорошо делать, т.к он главный программист...

    Ordos, 27 Сентября 2009

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

    +64.1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    <?php
    echo "<br><br>";
    echo "<a href='index.php'>На главную</a> |
    <a href='reg.php'>Регистрация</a> |
    <a href='stat.php'>Статистика</a><br><hr width=80%>
    <div class=info>Создано при участии gxcreator и kuprik17. Все права у них и ниипёт!<br>
    Кто спиздит код, тому просто пиздец будет,<br>
    руки оторвем и в жопу вставим!! Ясно, бля?!</div>";
    
    ?>

    Еще много интересного кода: http://www.google.com/codesearch?hl=ru&lr=&q=%D0%B6%D0%BE%D0%B F%D1%83&sbtn=%D0%9F%D0%BE%D0%B8%D1%81%D0 %BA

    Serge, 26 Сентября 2009

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

    +130.5

    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
    if (!passFlag)
                    {
                        switch (GetTreeNodeName)
                        {
                            case "group":
                                {
                                    if (GetTreeNode.Parent.Parent.Parent.Parent.Name != "StudySchedule")
                                    {
                                        StudentCard studentCard = new StudentCard(ExploreTree.SelectedNode.Text,
                                                                                  ExploreTree.SelectedNode.Parent.Parent.
                                                                                      Text,
                                                                                  ExploreView.SelectedItems[0]);
                                        studentCard.MdiParent = this.MdiParent;
                                        studentCard.Show();
                                        break;
                                    }
                                    else
                                    {
                                        StudySchedule schedule=new StudySchedule(ExploreView.SelectedItems[0], ExploreTree.SelectedNode.Parent.Nodes);
                                        schedule.MdiParent = this.MdiParent;
                                        schedule.Show();
                                        break;
                                    }
                                }

    Это мой говнокод, не знаю как строчку if (GetTreeNode.Parent.Parent.Parent.Parent .Name != "StudySchedule")
    написать по-нормальному)))

    FofanovIS, 26 Сентября 2009

    Комментарии (14)
  9. C++ / Говнокод #1900

    +62.3

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    void func(const char* str)
    {
      std::map<std::string, int>::iterator = my_map.find(str);
    
      .....
    }
    
    std::string str = "key";
    func(str.c_str());

    Уверен что это может найти каждый из вас в своих проектах, но может не в таком очевидном виде...

    pushkoff, 25 Сентября 2009

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

    +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
    <?php
    require_once ("../inc/core.php");
    require_once ("../inc/header.php");
    //
    require_once ("../inc/classAudioFile.php");
    require_once ("../inc/func.php");
    
    
    
    
    /// Форма загрузки файла
    if (!isset ($_POST['upload'])){
    echo '<form action="upload.php" method="post" enctype="multipart/form-data">';
    echo '<input type="file" name="fname"><br>';
    echo '<input type="submit" name="upload" value="Загрузить"><br></form>';
    }
    //
    $date = DATE ("Y-m-d");
    $scriptdir = "$siteurl/mp3/";
    $dir = "files/$date/";
    $tmpfilename = $_FILES['fname']['tmp_name'];
    $filename = $_FILES['fname']['name'];
    $nfilename = trans ("MixON.mobi_".$filename);
    $ext = explode (".",$filename);
    $size = $_FILES['fname']['size'];
    $adrfile = $dir.$nfilename;
    $mp3url = $scriptdir.$adrfile;
    //////////////
    
    if (!is_dir ("files/$date")) mkdir ("files/$date", 0770);
    
    
    if (isset($_POST['upload'])){
       if (count($ext) !=2) {
            echo "Файлы с двойным расширением запрещены. <br /> Должно быть так: <br /> filename.ext";
            exit;
        }
        if ($ext[1] != 'mp3' ){
            echo 'Разрешена загрузка только mp3 файлов.';
            exit;
        }
    if (file_exists ($tmpfilename)){
    copy ($tmpfilename, $adrfile);
    //// Получаем теги файла
    echo "Название файла: $filename <br />";
    $AF = new AudioFile;
    $AF->loadFile($adrfile);
    //$AF -> printSampleInfo();
    $channels = $AF -> wave_channels;
    $framerate = $AF -> wave_framerate;
    $byterate = $AF -> wave_byterate;
    $length = $AF -> wave_length;
    $title = $AF -> id3_title;
    $title = trim(iconv('windows-1251','UTF-8',$title));
    $artist = $AF -> id3_artist;
    $artist = trim (iconv('windows-1251','UTF-8',$artist));
    $album = $AF -> id3_album;
    $album = trim (iconv('windows-1251','UTF-8',$album));
    $year = $AF -> id3_year;
    $year = trim (iconv('windows-1251','UTF-8',$year));
    $genre = $AF -> id3_genre;
    $genre = trim (iconv('windows-1251','UTF-8',$genre));
    $comment = $AF -> id3_comment;
    $comment = trim (iconv('windows-1251','UTF-8',$comment));
    ///Выводим мп3 теги
    echo "Каналы: $channels <br /> Частота: $framerate <br /> Битрейт: $byterate <br /> ";
    echo "Продолжительность: ".date('i:s', mktime(0,0,round($length))). "мин. <br /> ";
    echo "Название: $title <br />";
    echo "Исполнитель: $artist <br />";
    echo "Стиль: $genre <br />";
    if ($album != null) echo "Альбом: $album <br />";
    if ($year != null) echo "Год: $year <br />";
    }// Если файл закачалься и удачно скопирован
    
    echo "<a href=\"http://$siteurl/$scriptdir/index.php?do=add\">Все верно</a>";
    $do = isset($_GET['do']) ? $_GET['do'] : '';
    switch ($do)
    {
        case 'admview':
    
    $sql = "INSERT INTO `files` ( `id` , `title` , `artist` , `genre` , `album` , `year` , `mp3url` )
    VALUES (
    '', '$title', '$artist', '$genre', '$album', '$year', '$mp3url'
    );";
    csql ($sql);
    mysql_query($sql);
    
    echo "<a href=\"http://$siteurl/$scriptdir/index.php?do=edit\">Нужно изменить</a>";
    
    }//switch do
    }// Если нажата кнопка
    require_once ("../inc/footer.php");
    ?>

    pivasyk, 25 Сентября 2009

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