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

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

    +1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    string str3 = Strings.Trim(ID);
     do
     {
         num2 = (short) Strings.InStr(str3, " ", CompareMethod.Binary);
         if (num2 > 0)
         {
                str3 = str3.Substring(0, num2 - 1) + Strings.Mid(str3, num2 + 1);
         }
    }
    while (num2 > 0);

    А зачем нам str3.Replace(" ", string.Empty) ?

    inickvel, 25 Ноября 2015

    Комментарии (1)
  3. Куча / Говнокод #19078

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    section.static > div[style="display:block; border: solid 1px #cfcfcf; padding : 10px"]{
        border: none !important;
        padding: 0 !important;
    }

    css-костыль!)

    Stefan_Hitskov, 24 Ноября 2015

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

    +1

    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
    function getQuarter(month) {
                            if (0 <= month && month <= 2) return "Q1 ";
                            if (3 <= month && month <= 5) return "Q2 ";
                            if (6 <= month && month <= 8) return "Q3 ";
                            return "Q4 ";
                        };
    
                        function getDate(lastActionDate) {
                            var dateString = lastActionDate.split(/\-|\s/);
                            var date = new Date(dateString.slice(0, 2));
                            var month = date.getMonth();
                            var year = date.getFullYear();
                            var quarter = getQuarter(month);
                            return "<span>Last Action Plan: <br> " + quarter + year + "</span>";
                        }

    на проекте активно используется momentjs

    zxxc, 24 Ноября 2015

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

    +1

    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
    <?php
            $gudir = opendir("../text/$book");
            $guarray = Array();
            while(false != ($gufile = readdir($gudir)))
            {
                    if(strstr($gufile, "gu@"))
                    {
                            $guarray[count($guarray)] = $gufile;
                    }
            }
            closedir($gudir);
            if(count($guarray))
            {
                    rsort($guarray);
                    foreach($guarray as $gucomment)
                    {
                            /*Здесь движок отображения комментариев*/
                            include "../text/$book/$gucomment";
                    }
            }
    ?>

    Я не знаю, что делает этот код. Никаких файлов с символами gu@ в каталогах не осталось. Лет 8 назад с другом книгу писали, решили замутить сайт. Ту книгу мы потом посчитали фигней и забросили. Про БД я тогда и не подозревал. Все хранилось в таких файлах:

    chapter#prae#prae#Предисловие#previous#0 #0#next#1#1
    chapter#1#1#Глава 1.1#previous#prae#prae#next#1#2
    chapter#1#2#Глава 1.2#previous#1#1#next#0#0

    kgm-rj, 23 Ноября 2015

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

    +1

    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
    $dbh = new PDO("mysql:host=$this->dbHost;dbname=$this->dbName", $this->dbUser, $this->dbPassword);
            $dbh->exec("set names utf8");
    
            $street = $streetPart.'%';
            if (isset($arChooseCity[$cityIndex])) {
                $condition =
                    "(city_az LIKE '$city'"
                    ." OR city_az LIKE '$arChooseCity[$cityIndex]'"
                    ." OR city_ru LIKE '$arChooseCity[$cityIndex]'"
                    ." OR city_en LIKE '$arChooseCity[$cityIndex]'"
                    ." OR city_ru LIKE '$city'"
                    ." OR city_en LIKE '$city')"
                    ." AND (geo_az LIKE '$street'"
                    ." OR geo_ru LIKE '$street'"
                    ." OR geo_en LIKE '$street'"
                    ." OR geo_az LIKE '% $street'"
                    ." OR geo_en LIKE '% $street'"
                    ." OR geo_ru LIKE '% $street')"
                ;
            }
            else {
                $condition =
                    "(city_az LIKE '$city'"
                    ." OR city_ru LIKE '$city'"
                    ." OR city_en LIKE '$city')"
                    ." AND (geo_az LIKE '$street'"
                    ." OR geo_ru LIKE '$street'"
                    ." OR geo_en LIKE '$street'"
                    ." OR geo_az LIKE '% $street'"
                    ." OR geo_en LIKE '% $street'"
                    ." OR geo_ru LIKE '% $street')"
                ;
            }
            $condition_type = " AND type = 'geo_object'";
            $condition_street = " AND type = 'street'";
    
            $query_street = $dbh->prepare("SELECT * from `addresses_new_new` WHERE $condition $condition_street GROUP BY street_{$lang}, city_{$lang} ORDER BY weight DESC LIMIT 0, {$maxLimit}");
            $query_type = $dbh->prepare("SELECT * from `addresses_new_new` WHERE $condition $condition_type LIMIT 0, {$maxLimit}");
    
            $query_street->execute();
            $query_type->execute();

    match - against никому не нужен! пользуйся только like.

    akanit, 18 Ноября 2015

    Комментарии (15)
  7. JavaScript / Говнокод #18980

    +1

    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
    $(".lucky-card-divforCheck").hover( 
    function () { 
    if (document.getElementById('lucky-card-p-mail').getElementsByTagName('input')[0].value=="" && 
    document.getElementById('lucky-card-p-phone').getElementsByTagName('input')[0].value=="" 
    ) { 
    $(document.getElementById("lucky-card-butt1")).hide(); 
    $(document.getElementById("lucky-card-butt2")).show(); 
    /*document.getElementById('lucky-card-err_fio').innerHTML='Не работает элс';*/ 
    } else { 
    /*document.getElementById('lucky-card-err_fio').innerHTML='Работает элс';*/ 
    }; 
    } 
    , 
    function () { 
    $(document.getElementById("lucky-card-butt2")).hide(); 
    $(document.getElementById("lucky-card-butt1")).show(); 
    } 
    ); 
    $('#lucky-card-empty-butt').click(function(){ 
    document.getElementById('lucky-card-err_fio').innerHTML='Напишите хотя бы почту или телефон'; 
    });

    изящная валидация

    Sheo, 06 Ноября 2015

    Комментарии (4)
  8. C++ / Говнокод #18975

    +1

    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 CBaseEntity {
    
            // ...
    
    	void (CBaseEntity ::*m_pfnThink)(void);
    
    	virtual void Think( void ) { if (m_pfnThink) (this->*m_pfnThink)(); };
    
            // ...
    
    	// Ugly code to lookup all functions to make sure they are exported when set.
    
    #ifdef _DEBUG
    	void FunctionCheck( void *pFunction, char *name ) 
    	{ 
    		if (pFunction && !NAME_FOR_FUNCTION((uint32)pFunction) )
    			ALERT( at_error, "No EXPORT: %s:%s (%08lx)\n", STRING(pev->classname), name, (uint32)pFunction );
    	}
    
    	BASEPTR ThinkSet( BASEPTR func, char *name ) 
    	{ 
    		m_pfnThink = func; 
    		FunctionCheck( (void *)*((int *)((char *)this + ( offsetof(CBaseEntity,m_pfnThink)))), name ); 
    		return func;
    	}
    
            // ...
    
    };
    
    // Ugly technique to override base member functions
    // Normally it's illegal to cast a pointer to a member function of a derived class to a pointer to a 
    // member function of a base class.  static_cast is a sleezy way around that problem.
    
    #ifdef _DEBUG
    
    #define SetThink( a ) ThinkSet( static_cast <void (CBaseEntity::*)(void)> (a), #a )
    
    // ...
    
    #else
    
    #define SetThink( a ) m_pfnThink = static_cast <void (CBaseEntity::*)(void)> (a)
    
    // ...
    
    #endif

    https://github.com/ValveSoftware/halflife/blob/5d761709a31ce1e71488f2668321de05f791b405/dlls/cbase.h

    > it's illegal
    В крестах всё легально, главное - попросить прощения в комментах...

    bormand, 05 Ноября 2015

    Комментарии (50)
  9. C# / Говнокод #18972

    +1

    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
    private readonly Dictionary<BuildType, string> mProductBuildPrefix = new Dictionary<BuildType, string>
        {
            { BuildType.iOS, "appstore" },
            { BuildType.iOSHD, "appstore" },
            { BuildType.iOS_INT, "appstore" },
            { BuildType.iOS_INT_HD, "appstore" },
            { BuildType.Alpha, "appstore" },
            { BuildType.Develop, "appstore" },
            { BuildType.Android, "appstore" },
            { BuildType.Android_INT, "appstore" },
            { BuildType.Web, "appstore" },
            { BuildType.Amazon, "appstore" }
        };

    > не понимаю смысловой нагрузки в этом...

    strax, 05 Ноября 2015

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

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    <?
    //Выводим картинку производителя и его описание в каталоге при условии выбора одного производителя из списка
    
        if(isset($_GET['mids'])) {  if(isset($_GET['mids'][1]) {} else{ //Если один производитель

    !isset? count? - не, неслышал

    sveta, 05 Ноября 2015

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

    +1

    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
    public void CreateTable(ref string text) 
            {
                List<S> list = new List<S>();
                list.Add(new S('о', 9.28));
                list.Add(new S('а', 8.66));
                list.Add(new S('е', 8.10));
                list.Add(new S('и', 7.45));
                list.Add(new S('н', 6.35));
                list.Add(new S('т', 6.30));
                list.Add(new S('р', 5.53));
                list.Add(new S('с', 5.45));
                list.Add(new S('л', 4.32));
                list.Add(new S('в', 4.19));
                list.Add(new S('к', 3.47));
                list.Add(new S('п', 3.35));
                list.Add(new S('м', 3.29));
                list.Add(new S('у', 2.90));
                list.Add(new S('д', 2.56));
                list.Add(new S('я', 2.22));
                list.Add(new S('ы', 2.11));
                list.Add(new S('ь', 1.90));
                list.Add(new S('з', 1.81));
                list.Add(new S('б', 1.51));
                list.Add(new S('г', 1.41));
                list.Add(new S('й', 1.31));
                list.Add(new S('ч', 1.27));
                list.Add(new S('ю', 1.03));
                list.Add(new S('х', 0.92));
                list.Add(new S('ж', 0.78));
                list.Add(new S('ш', 0.77));
                list.Add(new S('ц', 0.52));
                list.Add(new S('щ', 0.49));
                list.Add(new S('ф', 0.40));
                list.Add(new S('э', 0.17));
                list.Add(new S('ъ', 0.04));
    }

    И как от этого отойти?

    jekastiy, 04 Ноября 2015

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