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

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

    +163

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    function utf_decode($str) {
        /*static $table = array("\xD0\x81" => "\xA8", "\xD1\x91" => "\xB8",);
        return preg_replace('#([\xD0-\xD1])([\x80-\xBF])#se', 'isset($table["$0"]) ? $table["$0"] : chr(ord("$2")+("$1" == "\xD0" ? 0x30 : 0x70))', $str);*/
    	return $str;
    }

    Зря закоментил такая панацея была что вы, что вы...

    nethak, 12 Июля 2011

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

    +966

    1. 1
    z = (lines[i].Substring(n.Length + 2, lines[i].Length - (n.Length + 2))).Substring(0, (lines[i].Substring(n.Length + 2, lines[i].Length - (n.Length + 2))).IndexOf("/"));

    Забавный способ вырезания домена из ссылки вида: http://www.govnokod.ru/....

    0LOL, 11 Июля 2011

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

    +165

    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
    function f_includes(&$text){
    
    		//REPLACE FILE INCLUDES LINKS
     		$regex = '/{(ФАЙЛ=)\s*(.*?)}/i';
    		$matches = array();
    		preg_match_all( $regex, $text, $matches, PREG_SET_ORDER );		
    		foreach ($matches as $elm) {	
    			$elm[0] = str_replace('{', '', $elm[0]);
    			$elm[0] = str_replace('}', '', $elm[0]);			
    			parse_str( $elm[0], $args );
    			$file=@$args['ФАЙЛ'];	
    			if ($file){		
    				$output = getLink($file);			
    			} else { $output = ''; }
    			$text = str_replace('{ФАЙЛ='.$file.'}', $output, $text );	
    		}
    
    		return true;
    }

    Что за п##дец. InstantCMS.

    invision70, 07 Июля 2011

    Комментарии (2)
  5. 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)
  6. 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)
  7. JavaScript / Говнокод #7135

    +151

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

    фу ;(

    substr, 02 Июля 2011

    Комментарии (2)
  8. 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)
  9. 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)
  10. 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)
  11. 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)