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

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

    +157

    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
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>домо окошко</title>
    <link rel="stylesheet" href="tools/style.css" type="text/css" />
    <script type="text/javascript">
    function fMask(){
    	var h = document.getElementById('bodyblock').offsetHeight;
    	document.getElementById('mask').style.height = h + "px";
    	var hmodal = document.getElementById('modalBlock').offsetHeight -6;
    	document.getElementById('modalLeft').style.height = hmodal + "px";
    	document.getElementById('modalRight').style.height = hmodal + "px";
    }
    </script>
    <script type="text/javascript" src="tools/jquery.js"></script>
    <script type="text/javascript" src="tools/select.js"></script>
    <script type="text/javascript">$(document).ready(function(){$('.selectBlock').sSelect();});</script>
    </head>
    <body id="bodyblock" onload="fMask();">
    <div id="mask"></div>
    
    <div id="modal">

    лалала жужужужу я програмлю как могу... из серии не заставляйте верстальщиков применять JS

    nur, 02 Июля 2010

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

    +157

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    for ($i = 0; $i < $count; $i++) {
     if ($links_array['is'][$i]) {
      $link_text .= '[url='.$links_array['href'][$i].']'.$links_array['new_name'][$i].'c ('.link_domain($links_array['href'][$i]).')[/url]';
      if ($links_array['mirror'][$i] != '') {
       $link_text .= "\n".'[url='.$links_array['mirror'][$i].']'.$links_array['new_name'][$i].'c ('.link_domain($links_array['mirror'][$i]).')[/url]'
      }
      $link_text .= ($i + 1 != $count ? "\n" : '');
     }
    }

    dmOx, 01 Июля 2010

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

    +157

    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
    if($_POST["gaap_month"])
    {
            $d_f = mktime(0,0,0,1,1,$_POST['f_year']);
            $w_start = intval(date("W", $d_f));
            $w_day = (intval(date("w", $d_f)) == 0) ? 6 : intval(date("w", $d_f)) - 1;
            $d_f = ($w_start == 1) ? $d_f - $w_day*24*60*60 : $d_f + (7-$w_day)*24*60*60;
            $d_f += (4*($_POST['gaap_month']-1) + intval(($_POST['gaap_month']-1)/3)) * 7*24*60*60;
            $d_t = ($_POST['gaap_month'] % 3 == 0) ? $d_f + 5*7*24*60*60 : $d_f + 4*7*24*60*60;
            $_POST["df"] = date("d.m.Y", $d_f);
            $_POST["dt"] = date("d.m.Y", $d_t);
    }
    
    $date_from = mktime(0,0,0,substr($_POST["df"],3,2),substr($_POST["df"],0,2),substr($_POST["df"],6,4));
    $date_to = mktime(23,59,59,substr($_POST["dt"],3,2),substr($_POST["dt"],0,2),substr($_POST["dt"],6,4));
    
      // if time period more than 20 days
    if ($date_to-$date_from > 61*24*60*60)
            $_POST["df"] = date("d.m.Y", $date_to - 61*24*60*60);
    
    if ($_GET['office'] && ($USER->isAdmin() || in_array("15", $USER->GetUserGroupArray())))
            $_POST['t_office'] = $_GET['office'];

    вопрос - что употребляет автор ?

    atarix12, 28 Июня 2010

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

    +157

    1. 1
    2. 2
    3. 3
    4. 4
    //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    #               define False (0)//!!!!!!!!!!!!!!
    #               define True (!(False))//!!!!!!!!
    #               define Default (~(False))//!!!!

    printf("%s\n", typeid(False).name());
    printf("%s\n", typeid(True).name());
    True и False имеют разные типы.

    Говногость, 21 Июня 2010

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

    +157

    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
    TForm1 *Form1;
    //----------------------------------------------------------------------------------
    __fastcall TForm1::TForm1(TComponent* Owner)
            : TForm(Owner)
    {
    }
    //- Буква А ---------------------------------------------------------------------
    void __fastcall TForm1::Label1Click(TObject *Sender)
    {
      Image1->Picture->LoadFromFile("PICTURE/1.bmp");
     PlaySound("SOUND/1.wav",0,SND_ASYNC);
    }
    //--Буква Б-----------------------------------------------------------------------
    void __fastcall TForm1::Label2Click(TObject *Sender)
    {
      Image1->Picture->LoadFromFile("PICTURE/2.bmp");
     PlaySound("SOUND/2.wav",0,SND_ASYNC);
    }
    //--Буква В-------------------------------------------------------------------------
    void __fastcall TForm1::Label3Click(TObject *Sender)
    {
     Image1->Picture->LoadFromFile("PICTURE/3.bmp");
     PlaySound("SOUND/3.wav",0,SND_ASYNC);
    }
    ....
    
    и т.д.
    
    
    //--Буква Я-------------------------------------------------------------------------
    void __fastcall TForm1::Label33Click(TObject *Sender)
    {
     Image1->Picture->LoadFromFile("PICTURE/33.bmp");
     PlaySound("SOUND/33.wav",0,SND_ASYNC);
    }
    //---------------------------------------------------------------------------

    Пример из обучающей статьи по с++, где от а до я выресовываются буквы.

    pyshpysh, 16 Июня 2010

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

    +157

    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
    function month_to_number(a) {
    	if (a == 'Jan') {
    		a = '01';
    	}
    	if (a == 'Feb') {
    		a = '02';
    	}
    	if (a == 'Mar') {
    		a = '03';
    	}
    	if (a == 'Apr') {
    		a = '04';
    	}
    	if (a == 'May') {
    		a = '05';
    	}
    	if (a == 'Jun') {
    		a = '06';
    	}
    	if (a == 'Jul') {
    		a = '07';
    	}
    	if (a == 'Aug') {
    		a = '08';
    	}
    	if (a == 'Sep') {
    		a = '09';
    	}
    	if (a == 'Oct') {
    		a = '10';
    	}
    	if (a == 'Nov') {
    		a = '11';
    	}
    	if (a == 'Dec') {
    		a = '12';
    	}
    	return a;
    };

    eval, 10 Июня 2010

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

    +157

    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
    void foo()
    {
     if (!wxFile::Exists(defDir + resourcePath)) return false;
     HBITMAP *bmp = new HBITMAP;
     wxString path = defDir + resourcePath;
     (*bmp) = (HBITMAP)LoadImage(0, path.c_str(), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION);
     if (bmp != NULL) (*pMap)[resourceName] = bmp; else return false;
     return true;
    }
    
    bool SXXXXBitmapStorage::releaseItem(wxString resourceName)
    {
     ScrollBitmapHash::iterator iterator = pMap->find(resourceName);
     if (iterator == pMap->end()) return false;
     if (iterator->second != NULL) delete (HBITMAP*)iterator->second;
     pMap->erase(resourceName);
     return true;
    }
    
    HDC* SXXXXBitmapStorage::adjustToDC(wxString resourceName)//we must delete this object
    {
     HBITMAP *bmp = this->getItem(resourceName);
     if (bmp == NULL) return NULL;
     HDC *pDC = new HDC();
     (*pDC) = CreateCompatibleDC(0);
     SelectObject(*pDC, *bmp);
     return pDC;
    }

    И вы не поверите, этот код работал! Правда, конечно же, была утечка ресурсов

    Hsilgos, 07 Июня 2010

    Комментарии (14)
  9. JavaScript / Говнокод #3404

    +157

    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
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    // ==UserScript==
    // @name           govnokod.ru.user.js
    // @description    highlight for new comments
    // @author         [email protected]
    // @include        http://govnokod.ru/*
    // ==/UserScript==
    
    if(!jQuery.cookie)
    jQuery.cookie = function(name, value, options) {
        if (typeof value != 'undefined') { // name and value given, set cookie
            options = options || {};
            if (value === null) {
                value = '';
                options.expires = -1;
            }
            var expires = '';
            if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
                var date;
                if (typeof options.expires == 'number') {
                    date = new Date();
                    date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
                } else {
                    date = options.expires;
                }
                expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
            }
            var path = options.path ? '; path=' + (options.path) : '';
            var domain = options.domain ? '; domain=' + (options.domain) : '';
            var secure = options.secure ? '; secure' : '';
            document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
        } else { // only name given, get cookie
            var cookieValue = null;
            if (document.cookie && document.cookie != '') {
                var cookies = document.cookie.split(';');
                for (var i = 0; i < cookies.length; i++) {
                    var cookie = jQuery.trim(cookies[i]);
                    // Does this cookie string begin with the name we want?
                    if (cookie.substring(0, name.length + 1) == (name + '=')) {
                        cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                        break;
                    }
                }
            }
            return cookieValue;
        }
    };
    
    var there_href = document.location.href.match(/govnokod\.ru\/(\d+)/);
    if ( there_href ) // in topic
    	$(document).ready(function() {
    		var govnokod_n = there_href[1];
    		var cookiename = 'gk'+govnokod_n
    		var lastvisit = new Date(parseInt($.cookie(cookiename)));
    		var now = new Date();
    		var comments = $(".hcomment abbr").filter(function(index,elem) {
    			var date=new Date(elem.title.replace("T"," ").replace(/\+(\d\d):(\d\d)$/," GMT+$1$2"));
    			return date>lastvisit;
    		});
    		for (var i=0;i<comments.length;i++)
    		{
    			var elem = comments[i];
    			var header = elem.parentElement;
    			var block = elem.parentElement.parentElement;
    			block.style.background = '#FACE8D';
    			var anchor = document.createElement("a");
    			anchor.setAttribute('name','new_'+i);
    			block.insertBefore(anchor,block.firstChild);
    			
    			var prevlink = document.createElement("a");
    			if (i!=0)
    				prevlink.setAttribute('href','#new_'+(i-1));
    			prevlink.appendChild(document.createTextNode('⟵'));
    			header.insertBefore(prevlink,elem.nextSibiling);
    			
    			header.insertBefore(document.createTextNode(' '),elem.nextSibiling);
    			
    			var nextlink = document.createElement("a");
    			if (i!=comments.length-1)
    				nextlink.setAttribute('href','#new_'+(i+1));
    			nextlink.appendChild(document.createTextNode('⟶'));
    			header.insertBefore(nextlink,elem.nextSibiling);
    
    		}
    		
    		var new_comments_count = document.createElement("a");
    		if (comments.length)
    			new_comments_count.setAttribute('href','#new_0');
    		new_comments_count.appendChild(document.createTextNode(''+comments.length+' новых'));
    		var comments_count = $(".enrty-comments-count");
    		comments_count.text(comments_count.text().replace(/\)$/,', '));
    		comments_count.append(new_comments_count);
    		comments_count.append(')');
    		$.cookie(cookiename, now.valueOf(), { 'expires': 3 }); //помним, что имеется ограничение на размер куков.
    	});

    Наговнокодил подсвечивалку новых комментариев для говногод.ру. Смесь из обычного DOM и тутошнего jQuery. Сохранить как govnokod.ru.user.js. Тестировал только в опере.

    legolegs, 06 Июня 2010

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

    +157

    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
    //sort rr
        unsigned int i = 0;
        unsigned int random = time(NULL);
        unsigned int nummx = rr->size();
        while (nummx > 0){
            unsigned long numsame=1;
            i = 0;
            for (unsigned int j = 1;j < nummx;++j)
                if ((*rr)[j].m_pref > (*rr)[i].m_pref){
                    i = j;
                    numsame = 1;
                }else if ((*rr)[j].m_pref == (*rr)[i].m_pref){
                    ++numsame;
                    random = random * 69069 + 1;
                    if ((random / 2) < (2147483647 / numsame))
                        i = j;
                }
            swap((*rr)[i],(*rr)[--nummx]);
        }

    Что делает код - достоверно неизвестно. Скорее всего, что-то сортирует и одновременно перемешивает.

    gpr, 05 Июня 2010

    Комментарии (94)
  11. PHP / Говнокод #3363

    +157

    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
    if ($var == e_UC_MAINADMIN && getperms('0'))
    		{
            	return TRUE;
    		}
    
    		if ($var == e_UC_MEMBER && USER == TRUE)
    		{
    			return TRUE;
    		}
    
    		if ($var == e_UC_GUEST && USER == FALSE) {
    			return TRUE;
    		}
    
    		if ($var == e_UC_PUBLIC) {
    			return TRUE;
    		}
    
    		if ($var == e_UC_NOBODY) {
    			return FALSE;
    		}
    
    		if ($var == e_UC_ADMIN && ADMIN) {
    			return TRUE;
    		}
    		if ($var == e_UC_READONLY) {
    			return TRUE;
    		}

    По ходу, стек мозга автора не вмещает более одного оператора && подряд.
    CMS e107, /class2.php

    telnet, 31 Мая 2010

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