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

    В номинации:
    За время:
  2. Куча / Говнокод #11803

    +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
    <div style='margin-top: 8px; margin-left: 2px;'><span style='display: inline-block; width: 68px; height: 68px;'><a href='http://www.miss.ru/julii'><img src='fotki/2012-09-13-09-58-01-861mmm_tut.jpg' alt='Юлия Г' border='0' width='62' height='62'></a></span><script language='JavaScript'>
    if (document.getElementById("new_user_left_5921")) document.getElementById("new_user_left_5921").src="fotki/2012-09-13-09-58-01-861mmm_tut.jpg";
    </script><span style='display: inline-block; width: 68px; height: 68px;'><a href='http://www.miss.ru/anastasiyashirshakova'><img src='fotki/2012-04-08-15-24-10-633mmm_tut.jpg' alt='Анастасия Ширшакова' border='0' width='62' height='62'></a></span><script language='JavaScript'>
    if (document.getElementById("new_user_left_5094")) document.getElementById("new_user_left_5094").src="fotki/2012-04-08-15-24-10-633mmm_tut.jpg";
    </script><span style='display: inline-block; width: 68px; height: 68px;'><a href='http://www.miss.ru/zoloto'><img src='fotki/2011-09-20-18-16-59-630mmm_tut.jpg' alt='Анна Золотова' border='0' width='62' height='62'></a></span><script language='JavaScript'>
    if (document.getElementById("new_user_left_5095")) document.getElementById("new_user_left_5095").src="fotki/2011-09-20-18-16-59-630mmm_tut.jpg";
    </script><span style='display: inline-block; width: 62px; height: 68px;'><a href='http://www.miss.ru/angel_in_disguise'><img src='fotki/2011-10-12-13-47-56-383mmm_tut.jpg' alt='Анна Данилова' border='0' width='62' height='62'></a></span><script language='JavaScript'>
    if (document.getElementById("new_user_left_5096")) document.getElementById("new_user_left_5096").src="fotki/2011-10-12-13-47-56-383mmm_tut.jpg";
    </script><span style='display: inline-block; width: 68px; height: 68px;'><a href='http://www.miss.ru/alekc'><img src='fotki/2011-09-21-23-26-16-859mmm_tut.jpg' alt='Алекс Алекс' border='0' width='62' height='62'></a></span><script language='JavaScript'>
    if (document.getElementById("new_user_left_5098")) document.getElementById("new_user_left_5098").src="fotki/2011-09-21-23-26-16-859mmm_tut.jpg";
    </script><span style='display: inline-block; width: 68px; height: 68px;'><a href='http://www.miss.ru/milashka_t'><img src='fotki/2011-09-23-05-36-11-815mmm_tut.jpg' alt='Таня Сакович' border='0' width='62' height='62'></a></span><script language='JavaScript'>
    if (document.getElementById("new_user_left_5101")) document.getElementById("new_user_left_5101").src="fotki/2011-09-23-05-36-11-815mmm_tut.jpg";
    </script><span style='display: inline-block; width: 68px; height: 68px;'><a href='http://www.miss.ru/oksano4ka'><img src='fotki/2011-09-23-15-45-35-905mmm_tut.jpg' alt='Оксана Таштиева' border='0' width='62' height='62'></a></span><script language='JavaScript'>
    if (document.getElementById("new_user_left_5102")) document.getElementById("new_user_left_5102").src="fotki/2011-09-23-15-45-35-905mmm_tut.jpg";
    </script><span style='display: inline-block; width: 62px; height: 68px;'><a href='http://www.miss.ru/branez'><img src='fotki/2011-11-10-21-04-58-361mmm_tut.jpg' alt='Марина Бранец' border='0' width='62' height='62'></a></span><script language='JavaScript'>
    if (document.getElementById("new_user_left_5182")) document.getElementById("new_user_left_5182").src="fotki/2011-11-10-21-04-58-361mmm_tut.jpg";
    </script><span style='display: inline-block; width: 68px; height: 68px;'><a href='http://www.miss.ru/kratyulianka'><img src='fotki/2011-11-10-22-08-23-802mmm_tut.jpg' alt='Yulianka Krat' border='0' width='62' height='62'></a></span><script language='JavaScript'>
    if (document.getElementById("new_user_left_5183")) document.getElementById("new_user_left_5183").src="fotki/2011-11-10-22-08-23-802mmm_tut.jpg";
    </script><span style='display: inline-block; width: 68px; height: 68px;'><a href='http://www.miss.ru/romanova'><img src='fotki/2011-11-11-11-29-44-496mmm_tut.jpg' alt='Лилия Романова' border='0' width='62' height='62'></a></span><script language='JavaScript'>
    if (document.getElementById("new_user_left_5186")) document.getElementById("new_user_left_5186").src="fotki/2011-11-11-11-29-44-496mmm_tut.jpg";
    </script><span style='display: inline-block; width: 68px; height: 68px;'><a href='http://www.miss.ru/agafonova'><img src='fotki/2011-11-11-11-45-36-596mmm_tut.jpg' alt='Нина Агафонова' border='0' width='62' height='62'></a></span><script language='JavaScript'>
    if (document.getElementById("new_user_left_5187")) document.getElementById("new_user_left_5187").src="fotki/2011-11-11-11-45-36-596mmm_tut.jpg";
    </script><span style='display: inline-block; width: 62px; height: 68px;'><a href='http://www.miss.ru/demash'><img src='fotki/2011-11-11-11-49-50-483mmm_tut.jpg' alt='Анастасия Демаш' border='0' width='62' height='62'></a></span><script language='JavaScript'>
    if (document.getElementById("new_user_left_5188")) document.getElementById("new_user_left_5188").src="fotki/2011-11-11-11-49-50-483mmm_tut.jpg";
    </script></div>
    <br>

    Найдено в работах одного дорогого уфимского фрилансера...

    Stud, 20 Сентября 2012

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

    +22

    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
    static bool GetPathToExecutable( std::wstring & sPath )
    {
    #ifdef WIN32
        std::vector<wchar_t> TmpData;
    #else
        std::vector<char> TmpData;
    #endif
        static const size_t _nResize = 256;
        try
        {
            TmpData.resize( _nResize );
        }
        catch( ... )
        {
            sPath.clear();
            return false;
        }
        while( true )
        {
    #ifdef WIN32
            DWORD iSize = GetModuleFileNameW( NULL, &TmpData[0], (DWORD) TmpData.size() - 1 );
            if( GetLastError() == NO_ERROR )
            {
                sPath.assign( &TmpData[0], iSize );
                return true;
            }
            else if( GetLastError() != ERROR_INSUFFICIENT_BUFFER )
            {
                //
                // Unsupported error
                //
                break;
            }
    #else
            int iSize = readlink( "/proc/self/exe", &TmpData[0], (int) TmpData.size() - 1 );
            if( iSize < 0 )
            {
                //
                // Error is occurred
                //
                break;
            }
            if( iSize < TmpData.size() - 1 )
            {
                //
                // Store value
                //
                return LConv::ConvertCharToWstring( sPath, &TmpData[0] );
            }
    #endif
            try
            {
                TmpData.resize( iSize + _nResize );
            }
            catch(...)
            {
                break;
            }
        }
        sPath.clear();
        return false;
    }

    коллега инициализит строку

    Axrud, 19 Сентября 2012

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

    +38

    1. 1
    if (!file_exists($this->filePath)) fopen($this->filePath, 'r');

    норм чё

    dizballanze, 19 Сентября 2012

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

    +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
    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
    internal static double GetExtendedFromBytes(byte[] bytes)
            {
                /*
                    1   15      1   63
                    s   e       i 	f
    
                        The value v of the number is given by: 
                    if 0 <= e < 32767, then v = (-1)s * 2(e-16383) * (i.f) 
                    if e = 32767 and f = 0, then v = (-1)s * Inf 
                    if e = 32767 and f <> 0, then v is a NaN
                 */
                const int memSize = 10;
                if (bytes == null)
                    throw new ArgumentNullException("bytes");
                if (bytes.Length != memSize)
                    throw new ArgumentException("Must be " + memSize + " bytes", "bytes");
    
                int s = bytes[0] >> 7;
                int e = 0x7FFF & ((bytes[0] << 8) | bytes[1]);
                int i = bytes[2] >> 7;
                ulong f = (ulong)(0x7F & bytes[2]);
                for (int j = 3; j < memSize; j++)
                {
                    f <<= 8;
                    f |= bytes[j];
                }
    
                decimal df = (decimal)f / 10000000000000000000 /* 10^19 */; // число f в формате 0.f
                double v;
                if (0 <= e && e < 32767)
                {
                    int pow = e - 16383;
                    decimal c = (s == 0 ? 1 : -1) * (decimal)Math.Pow(2, pow);
                    decimal dv = c * (i + df); // значение, полученное по формуле для x86 Extended Precision Format
    
                    if (f != 0) // HACK при вычислении по формуле искомое значение не удается получить - исправляем
                    {
                        const decimal mn = 0.0776627963145224192m; // magic number, при значениях отличных от 2^x возникает разница кратная этому значению
    
                        decimal delta = Math.Abs(dv - c);
                        decimal add = 0;
                        if (pow >= 4)
                            add = Math.Round(delta * 1.0842021724855044340074528009m); // еще magic number
                        else if (pow >= 2)
                            add = Math.Ceiling(delta);
                        else if (pow >= 0)
                            add = Math.Ceiling(delta * 10) / 10m;
                        else
                        {
                            decimal m = 10m * (decimal)Math.Pow(2, Math.Abs(pow));
                            add = Math.Ceiling(delta * m) / m;
                        }
                        if (dv > 0)
                            dv += add * mn;
                        else
                            dv -= add * mn;
                    }
                    v = (double)dv;
                }
                else if (e == 32767)
                {
                    if (f == 0)
                        v = s == 0 ? double.PositiveInfinity : double.NegativeInfinity;
                    else
                        v = double.NaN;
                }
                else
                {
                    throw new ArgumentOutOfRangeException("bytes");
                }
    
                return v;
            }

    Местные индусы постарались. Перевод 80 bit floating point в double. Причём если прочитать спецификацию IEEE-754, то код займет 3-4 строчки с простыми битовыми операциями.

    NetDeveloper, 12 Сентября 2012

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

    +51

    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
    class happy
    {
    
    public $today = 0;
    public $text = null;
    public function __construct($text)
    {
    if (!$text){
    exit('ничего не пришло!:(');
    }
    if ($text)
    {
    $this->text = $text;
    }
    }
    public function today()
    {
    $date = date('z');
    $this->today = $date;
    return $this->today;
    }
    
    public function echotext()
    {
    if (!$this->text)
    {
    echo 'нет текста!';
    }
    if ($this->text)
    {
    echo $this->text;
    }
    }
    
    }
    if (date('z') == 256)
    {
    $obj = new happy('С днём программиста!');
    if ($obj->today == 0)
    {
    $obj->today();
    }
    if ($obj->today == 256)
    {
    $obj->echotext();
    }
    }

    С праздником!

    kuler, 12 Сентября 2012

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

    +53

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    public function __construct() {
    	$this->em = \Zend_Registry::get('em');
    	$this->_pid = mysql_connect(
    								$this->em->getConnection()->getHost(),
    								$this->em->getConnection()->getUsername(), 
    								$this->em->getConnection()->getPassword());
    	mysql_select_db( $this->em->getConnection()->getDatabase(), $this->_pid); 
    }

    shmaltorhbooks, 10 Сентября 2012

    Комментарии (10)
  8. Куча / Говнокод #11629

    +141

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    <select>
    	<option class="a2" value="0" selected="selected">любой возраст</option>
    	<option class="a2" value="1">0 мес - 6 мес</option>
    	<option class="a2" value="2">0 мес - 12 мес</option>
    </select>

    selected="selected" для элемента, выбираемого по дефолту - зачем?
    ps. Код - кусок статичного html.

    domaster, 22 Августа 2012

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

    +127

    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
    function name = monthName( m )
    
    switch m
        case 1
            name = 'Jan';
        case 2 
            name = 'Feb';
        case 3
            name = 'Mar';
        case 4
            name = 'Apr';
        case 5
            name = 'May';
        case 6
            name = 'Jun';
        case 7 
            name = 'Jul';
        case 8 
            name = 'Aug';
        case 9 
            name = 'Sep';
        case 10 
            name = 'Oct';
        case 11
            name = 'Nov';
        case 12 
            name = 'Dec';
    end

    MATLAB. Источник: http://berkeleyearth.org/results-summary/ - почитайте, что за проект. А ноги растут вот отсюда: http://www.sfgate.com/science/article/UC-climate-change-skeptic-changes-views-3748148.php

    Этот отрывок присутствует в двух файлах, я нашел его после беглого просмотра. Может быть, я ничего не понимаю в научных расчетах и совершенно незнаком с синтаксисом MATLAB, но есть у меня подозрения, что здесь что-то не так.

    Папки с тестами к коду я не нашел. Сижу вот, думаю...

    scriptin, 20 Августа 2012

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

    +106

    1. 1
    2. 2
    3. 3
    4. 4
    foreach (DataRow row in this.TestsTable.Select(query))
    {
        return true;
    }

    Все тот же крупный и дорогой проект :)

    minuzZ, 17 Августа 2012

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

    +137

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    private static Tag GetTopic(Guid tagId)
    {
     var tag = DataService.PerThread.TagSet.SingleOrDefault(x => x.Id == tagId);
     if (tag == null && tag.GroupId != null)
      return null;
    
     if (tag.TopicState != (byte)TopicState.GroupTopic)
      return null;
    
     return tag;
    }

    Arbium, 08 Августа 2012

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