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

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

    +113

    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
    //чОткая функция которая возвращает количество отображаемых узлов
    //в дереве без скролла
    int GetcountVisibleNodesInList()
    {
        int res = 0;
    
        if (FormGUI.c_MainWorkSpaseTree.Nodes.Count == 0)
        {
            this.FormGUI.c_MainWorkSpaseTree.Nodes.Add(new TreeNode());
            res = this.FormGUI.c_MainWorkSpaseTree.Height / FormGUI.c_MainWorkSpaseTree.getNodeRectangle(this.FormGUI.c_MainWorkSpaseTree.Nodes[0]).Height;
            this.FormGUI.c_MainWorkSpaseTree.Nodes[0].Remove();
        }
        else
        {
            res = this.FormGUI.c_MainWorkSpaseTree.Height / FormGUI.c_MainWorkSpaseTree.getNodeRectangle(this.FormGUI.c_MainWorkSpaseTree.Nodes[0]).Height;
        }
    
        //и незабываем воткнуть вычисленное значение в комбобокс
        this.FormGUI.c_cmb_countRowsInPage.Text = (res - 4).ToString();
        return res;
    }
    
    //пример использования функции
    void FormGUI_Load(object sender, EventArgs e)
    {
        //возвращается интовое значение и ложится в комбобокс
        GetcountVisibleNodesInList();
    
        int CountRows = 0;
        if (int.TryParse(FormGUI.c_cmb_countRowsInPage.Text, out CountRows))
        {
            _LastShowedRowNumber = 0;
            GoToNextPage(); //там же комбобокс опять парсится
        }
    }

    обратите внимание на обработчик загрузки формы.
    Из нужного кода там только вызов GoToNextPage() в котором опять же парсим комбобокс

    UgayNick, 04 Июля 2011

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

    +163

    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
    Example #3 preg_replace_callback() using recursive structure to handle encapsulated BB code
    <?php
    $input = "plain [indent] deep [indent] deeper [/indent] deep [/indent] plain";
    
    function parseTagsRecursive($input)
    {
    
        $regex = '#\[indent]((?:[^[]|\[(?!/?indent])|(?R))+)\[/indent]#';
    
        if (is_array($input)) {
            $input = '<div style="margin-left: 10px">'.$input[1].'</div>';
        }
    
        return preg_replace_callback($regex, 'parseTagsRecursive', $input);
    }
    
    $output = parseTagsRecursive($input);
    
    echo $output;
    ?>

    Не знаю, баян или нет. Поиском не смог найти preg_replace_callback на этом сайте.
    В таком недлинном коде есть очень аппетитное дерьмецо (кроме языка). Если в качестве $input взять строку подлиннее, то интерпретатор, как Чак Норрис, сосчитает до бесконечности. Исправляется добавлением одного символа к коду.

    inkanus-gray, 03 Июля 2011

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

    +151

    1. 1
    var GetUrl = /\[(.*)\]/g.exec("$SECTION_NAME$")[1].replace(/\-/i, '~').replace(/\-/i, '~');

    фу ;(

    substr, 02 Июля 2011

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

    +155

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    if($inc == true){
         $counter_val = $cat[$this->FileCounterKey] + 1;
    }else{
         $counter_val = $cat[$this->FileCounterKey] - 1;
    }

    Класс деревьев в одной русской CMS. Метод пересчитывает кол-во файлов в категории после добавления/удаления.

    Мартин, 02 Июля 2011

    Комментарии (2)
  6. Java / Говнокод #7133

    +75

    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
    <% ServicePackage servicePackage = null; %>
    	<% char fi [] = {'g', 'v', 'p'}; %>
    	<% int  ni [] = {3, 7, 11}; %>
    	
    	<% for(int i = 0; i < fi.length; i++)
    		 for(int j = 1; j <= ni[i]; j++)
    		 	{
    		 		String id = "", name = null, brief = null, price = null;
    		 		id += (char)fi[i];
    		 		if (j >= 10) 
    		 			id += (char)('0' + j / 10);
    		 		id += (char)('0' + j % 10);
    		 		
    		 		servicePackage = AllServicePackages.map.get(id);
    		 		if (servicePackage != null)
    		 		{
    		 			name = servicePackage.getName();
    		 			brief = servicePackage.getBrief();
    		 			price = servicePackage.getPrise();
    		 		}
    		 		%>
    		 <%	} %>

    Автору хотелось перебрать все эл-ты map'а.

    qweqweqwe, 02 Июля 2011

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

    +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
    $currN = 0;
            $countN = count($news);        
            $currW = 0;
            $countW = count($wall);
            $time = time();
            $date = date('Y-m-d H:i:s');
    
            // Жестянка в сферическом ваккуме куба
    		foreach($lenta as $k => &$v)
    		{
    		    while (($v['DZ'] <= $news[$currN]['DZ']))
    		    {
    		        while (($news[$currN]['DZ'] <= $wall[$currW]['DZ']) && ($currW < $countW))
    		        {
    		            $this->create_time($wall[$currW]['DZ'], $time, $date);
    		            $this->display_wall($wall[$currW]);
    		            ++$currW;		            
    		        }
    		        $this->create_time($news[$currN]['DZ'], $time, $date);
    		        $this->display_news($news[$currN]);
    		        ++$currN;
    		    }
    		    $this->create_time($v['DZ'], $time, $date);
    			$this->display_lenta($v, $usr);
    		}
    		
    		while ($currN < $countN)
    		{
    		    while (($news[$currN]['DZ'] <= $wall[$currW]['DZ']) && ($currW < $countW))
    		    {
    		        $this->create_time($wall[$currW]['DZ'], $time, $date);
    		        $this->display_wall($wall[$currW]);
    		        ++$currW;
    		    }		
    		    $this->create_time($news[$currN]['DZ'], $time, $date);
    		    $this->display_news($news[$currN]);
    		    ++$currN;		
    		}
    		
    		while ($currW < $countW)
    		{
    		    $this->create_time($wall[$currW]['DZ'], $time, $date);
    		    $this->display_wall($wall[$currW]);
    		    ++$currW;
    		}

    Просто и со вкусом.

    advvzlol, 01 Июля 2011

    Комментарии (2)
  8. SQL / Говнокод #7066

    −108

    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
    function t()
    {
         setTimeout('document.getElementById("qwezxc").innerHTML+="H"',1000)
         setTimeout('document.getElementById("qwezxc").innerHTML+="e"',2000)
         setTimeout('document.getElementById("qwezxc").innerHTML+="l"',3000)
         setTimeout('document.getElementById("qwezxc").innerHTML+="l"',4000)
         setTimeout('document.getElementById("qwezxc").innerHTML+="o"',5000)
         setTimeout('document.getElementById("qwezxc").innerHTML+=","',6000)
         setTimeout('document.getElementById("qwezxc").innerHTML+="W"',7000)
         setTimeout('document.getElementById("qwezxc").innerHTML+="o"',8000)
         setTimeout('document.getElementById("qwezxc").innerHTML+="r"',9000)
         setTimeout('document.getElementById("qwezxc").innerHTML+="l"',10000)
         setTimeout('document.getElementById("qwezxc").innerHTML+="d"',11000)
    }

    yasosiska, 26 Июня 2011

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

    +147

    1. 1
    dirname(__FILE__)

    peinguin, 25 Июня 2011

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

    +159

    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
    $this->addException(Mage::helper('dataflow')->__('Found %d rows.', $this->_countRows));
    $this->addException(Mage::helper('dataflow')->__('Starting %s :: %s', $adapterName, $adapterMethod));
    
    $batchModel->setParams($this->getVars())
        ->setAdapter($adapterName)
        ->save();
    
    // $adapter->$adapterMethod();
    
    return $this;
    
    $dom = new DOMDocument();
    // $dom->loadXML($this->getData());
    if (Mage::app()->getRequest()->getParam('files')) {
        $path = Mage::app()->getConfig()->getTempVarDir().'/import/';
        $file = $path.urldecode(Mage::app()->getRequest()->getParam('files'));
        if (file_exists($file)) {
            $dom->load($file);
        }
    } else {
    
        $this->validateDataString();
        $dom->loadXML($this->getData());
    }

    Magento 1.5 stable. после return'a идёт около 70 строк... Насладиться можно тут http://svn.magentocommerce.com/source/branches/1.5/app/code/core/Mage/Dataflow/Model/Convert/Parser/Xml/Excel.php

    message, 17 Июня 2011

    Комментарии (2)
  11. Куча / Говнокод #6804

    +131

    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
    /*здесь заданы значения листов x и y соответственно*/
    x: [...] $
    y: [...] $
    ...
    /*и понеслась*/
    xx: [-10] $
    for i in create_list(i,i, 2,length(h)) do
    	xx: append(xx, [i,i]) $
    xx: append(xx, [10]) $
    
    yy: [ first(x) ] $
    for i in create_list(i,i, 2,length(h)) do
    	yy: append(yy, [x[i-1],x[i]]) $
    yy: append(yy, [last(yy)]) $
    
    plot2d( [discrete, xx,yy] ) $

    maxima. рисуем кусочно-заданную функцию О_о

    ilardm, 31 Мая 2011

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