1. JavaScript / Говнокод #18983

    +3

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    $('.product-value').find('.form_select_body').find('.dropdown').find('a').on('click', function(){
            $('#ordering_popup').find('.popup-section_right').find('[checked=checked]').parents('.equipment-product-preview').find('.equipment-product-info').find('.value').text($(this).text());
            $('#ordering_popup').find('.popup-section_right').find('[checked=checked]').parents('.equipment-product-preview').find('.equipment-product-info').find('.value').attr('value',$(this).text());
            $('#ordering_popup').find('.popup-section_left').find('.equipment-product-preview:eq(0)').find('.equipment-product-info').find('.value').text($(this).text());
            $('#ordering_popup').find('.popup-section_left').find('.equipment-product-preview:eq(0)').find('.equipment-product-info').find('.value').attr('value',$(this).text());
        });

    user-dob, 07 Ноября 2015

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

    −2

    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
    unsigned strlen(const char *str)
    {
    	const char *ptr;
    	for (ptr = str; *ptr; ++ptr);
    	return ptr - str;
    }
    
    char *strcpy(char *dst, const char *src)
    {
    	while((*dst++ = *src++) != 0);
    	return dst;
    }
    namespace std
    {
    	class string
    	{
    	public:
    		string(const char *str = 0) : size(str ? strlen(str) : 0)
    		{
    			this->str = new char[size + 1];
    			if(str) strcpy(this->str, str);
    			else this->str[0]=0;
    		}
    		string(const string &str) : size(str.size)
    		{
    			this->str = new char[size +1];
    			strcpy(this->str, str.str);
    		}
    		~string()
    		{
    			delete[] str;
    		}
    		const char* c_str() const
    		{
    			return str;
    		}
    	private:
    		char *str;
    		unsigned size;
    	};
    
    	class Cout
    	{
    	public:
    		Cout &operator<< (const char *str)
    		{
    			unsigned len = strlen(str);
    			asm volatile (
    			"movl $0x04, %%eax\n" 
    			"movl $0x01, %%ebx\n"
    			"int $0x80\n"
    			:
    			: "c"(str), "d"(len));
    			return *this;
    		}
    		Cout &operator<< (const string &str)
    		{
    			operator<< (str.c_str());
    			return *this;
    		}
    	} cout;
    }
    
    int main()
    {
    	std::string str = "Hello World!";
    	std::cout << str << "\n";
    	return 0;
    }

    Ещё 1 хелловорлд для линуха x86 на С++

    Koncord, 07 Ноября 2015

    Комментарии (52)
  3. 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)
  4. C# / Говнокод #18979

    +14

    1. 1
    2. 2
    3. 3
    public static bool Convert(string fileName, string Namefile) {
    ...
    }

    нет, ну не дебил?

    Lokich, 06 Ноября 2015

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

    +3

    1. 1
    2. 2
    3. 3
    $disabled = $_SESSION['adminUser']->userlevel() < UserLevel::RESELLER_SUPPORT;
    $enabled = $_SESSION['adminUser']->userlevel() > UserLevel::RESELLER_SUPPORT;
    Form::datePicker('valid_to', 'valid_to', $value, !$enabled);

    limitium, 06 Ноября 2015

    Комментарии (0)
  6. JavaScript / Говнокод #18977

    +2

    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
    (function ($) {
        Drupal.behaviors.kdating = {
            attach: function (context, setting) {
    
                var links = $('#field-slideshow-1-pager').find('a');
                links.colorbox({ rel: 'gal' });
    
                $.each(links, function (index, value) {
                    var val = $(value);
                    var href = val.find('img').attr('src');
                    var path = href.split('/'),
                        newPath = path[0] + '//'
                            + path[2] + '/'
                            + path[3] + '/'
                            + path[4] + '/'
                            + path[5] + '/'
                            + path[9];
    
                    val.attr('href', newPath);
                });
    
            }
        };
    })(jQuery);

    Парсим ссылки вместе

    kdating, 06 Ноября 2015

    Комментарии (0)
  7. 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)
  8. PHP / Говнокод #18974

    +2

    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
    if ($this->getShowTemplateHints()) {
        echo <<<HTML
    <div style="position:relative; border:1px dotted red; margin:6px 2px; padding:18px 2px 2px 2px; zoom:1;">
    <div style="position:absolute; left:0; top:0; padding:2px 5px; background:red; color:white; font:normal 11px Arial;
    text-align:left !important; z-index:998;" onmouseover="this.style.zIndex='999'"
    onmouseout="this.style.zIndex='998'" title="{$fileName}">{$fileName}</div>
    HTML;
        if (self::$_showTemplateHintsBlocks) {
            $thisClass = get_class($this);
            echo <<<HTML
    <div style="position:absolute; right:0; top:0; padding:2px 5px; background:red; color:blue; font:normal 11px Arial;
    text-align:left !important; z-index:998;" onmouseover="this.style.zIndex='999'" onmouseout="this.style.zIndex='998'"
    title="{$thisClass}">{$thisClass}</div>
    HTML;
        }
    }

    Правильная реализация hover эффекта. Яркости для картины добавляет то, что это все написано в блоке MVC модели и понятное дело, на живом проекте.

    bayanets, 05 Ноября 2015

    Комментарии (16)
  9. PHP / Говнокод #18973

    +2

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    if (count($not_enough_rights) == 1 and !empty($not_enough_rights['user_extra'])) {
    					// если нужен доступ только к user_extra, то дополнительного доступа не надо, но скрываем сами права user_extra
    
    				} else {
    
    					if (count(array_merge($user_rights, $EDIT_ADMIN_GROUPS)) != count($EDIT_ADMIN_GROUPS)) {
    						$GLOBALS['VALID_GROUPS'] = array('root');
    					} else {
    						$GLOBALS['VALID_GROUPS'] = array('superadmin');
    					}
    
    				}

    Если $user_rights не пустой, то ты просто админ, если пустой, то суперадмин. Не проставил в БД права - суперадмин!

    dimka3210, 05 Ноября 2015

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