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

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

    +160

    1. 1
    std::cout << (valid_flag + prior ? 1 : 0) << " " << valid_flag+1-1 << std::endl;

    Говнокод - загадка. Какой тип у valid_flag?

    seregakabancheg, 05 Апреля 2011

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

    −116

    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
    -(BOOL) checkIsDeleted:(Transactions*)target
    {
        if (target.transactionType == TransactionTypeTransfer)
        {
            if (target.cashFlow && target.cashFlow.isDeleted && target.secondCashFlow && target.secondCashFlow.isDeleted)
                return YES;
            return NO;
        }
        else
            if (target.cashFlow && target.cashFlow.isDeleted)
                return YES;
        return NO;
    }

    Классика )))

    Tika-Z, 05 Апреля 2011

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

    +125

    1. 1
    2. 2
    3. 3
    4. 4
    if (NewsId == 0)
        categoriesList.Get();
    else
        categoriesList.Get();

    Встретил при модернизации одного веб ресурса с посещаемостью около 10 тыс.пользователей в сутки

    lexx-pnz, 31 Марта 2011

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

    +164

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    $('.button').bind('click', function(){
    	t = $(this);
    	$('.vote-vk').attr('title', t.attr('title')).attr('summary', t.attr('summary')).attr('url', t.attr('url')).attr('image', t.attr('image'));
    	$('.vote-twitter').attr('title', t.attr('title')).attr('summary', t.attr('summary')).attr('url', t.attr('url')).attr('image', t.attr('image'));
    	$('.vote-fb').attr('title', t.attr('title')).attr('summary', t.attr('summary')).attr('url', t.attr('url')).attr('image', t.attr('image'));
    });

    http://memecombat.ru/

    sapegin, 31 Марта 2011

    Комментарии (9)
  6. Си / Говнокод #6156

    +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
    char *toScan;
        unsigned int IP1, IP2, IP3, IP4, IPMask;
        if(argc > 1) {
            toScan = argv[1];
    
            if(sscanf(toScan, "%u.%u.%u.%u/%u", &IP1, &IP2, &IP3, &IP4, &IPMask) != 5) {
                puts("Error parsing arguments.");
                return -1;
            } else {
                if(IP1 > 255 || IP2 > 255 || IP3 > 255 || IP4 > 255 || IPMask > 32) {
                    puts("Incorrect values specified.");
                    return -2;
                } else {
                    baseIP |= IP1 & 0xFF;
                    baseIP |= ((IP2 << 8) & 0xFF00);
                    baseIP |= ((IP3 << 16) & 0xFF0000);
                    baseIP |= ((IP4 << 24) & 0xFF000000);
    
                    baseIP = ntohl(baseIP);
    
                    intCountIP = (unsigned long) pow(2, 32-IPMask);
                    //printf("Total IP's: %u\n", countIP());
                }
            }
        } else {
            return -1;
        }

    Парсинг аргументов из одного сетевого сканера. Программа выявляет выключенные хосты в указанной подсети.
    Несмотря на *это*, сканер работает весьма резво (350 IP в секунду)

    danilissimus, 31 Марта 2011

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

    +170

    1. 1
    var obj=getObjById($(this).attr("id"));

    Вот такое хорошое применение jquery =)
    http://javascript.ru/forum/misc/16224-pokritikujjte-podkhod-pozhalujjsta.html

    vulkan, 30 Марта 2011

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

    +165

    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
    <script>
    
    var IllegalChars=new Array("select", "drop", ";", "--", "insert", "delete", "xp_", "update", "/", ":", "char(", "?", "`", "|", "declare", "convert", "cast(", "@@", "varchar", "2D2D", "4040", "00400040", "[", "]");
    var IllegalFound=new Array();
    var IllegalCharsCount=0;
    
    function ResetCharsCount()
    {
     IllegalCharsCount=0;
    }
    
    function wordFilter(form,fields)
    {
    	ResetCharsCount();
    	var CheckTextInput;
    	var fieldErrArr=new Array();
    	var fieldErrIndex=0;
    	for(var i=0; i<fields.length; i++)
    	{
    		CheckTextInput = document.forms[form].elements[fields[i]].value;
    		for(var j=0; j<IllegalChars.length; j++)
    		{
    			for(var k=0; k<(CheckTextInput.length); k++)
    			{
    				if(IllegalChars[j]==CheckTextInput.substring(k,(k+IllegalChars[j].length)).toLowerCase())
    				{
    					IllegalFound[IllegalCharsCount]=CheckTextInput.substring(k,(k+IllegalChars[j].length));
    					IllegalCharsCount++;
    					fieldErrArr[fieldErrIndex]=i;
    					fieldErrIndex++;
    				}
    			}
    		}
    	}
    	var alert_text="";
    	for(var k=1; k<=IllegalCharsCount; k++)
    	{
    		alert_text+="\n" + "(" + k + ")  " + IllegalFound[k-1];
    		eval('CheckTextInput=document.' + form + '.' + fields[fieldErrArr[0]] + '.select();');
    	}
    	if(IllegalCharsCount>0)
    	{
    		alert("The form cannot be submitted.\nThe following errors were found:\n_______________________________\n" + alert_text + "\n_______________________________\n");
    		return false;
    	}
    	else
    	{
    		return true;
    		document.forms[form].submit();
    	}
    }
    </script>
    
    ...
    
    <FORM NAME="FormHome" ACTION="search.asp" METHOD="post" onSubmit="return wordFilter('FormHome',['criteria']);">

    http://www.cadw.wales.gov.uk/

    Инъекция не пройдет.

    pingw33n, 29 Марта 2011

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

    +173

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    if ($mail->send($mailTo)) { 
    			$aSuccMess[] = "Спасибо. Ваш сообщение отправлено. Администрация сайта рассмотрит его в ближайшее время.";
    			$fname = $fmail = $ftext = "";
    		} else { 
    			$fname = $fmail = $ftext = "";
    			$aSuccMess[] = "Спасибо. Ваш сообщение отправлено. Администрация сайта рассмотрит его в ближайшее время.";
    		}

    Взято с сайта, сделанным моим коллегой)

    sleeper, 24 Марта 2011

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

    +116

    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
    // Method that returns anonymous type as object
    object ReturnAnonymous() {
      return new { City="Prague", Name="Tomas" };
    }
    
    void Main() {
      // Get instance of anonymous type with 'City' and 'Name' properties
      object o = ReturnAnonymous();
    
      // This call to 'Cast' method converts first parameter (object) to the
      // same type as the type of second parameter - which is in this case 
      // anonymous type with 'City' and 'Name' properties
      var typed = Cast(o, new { City="", Name="" });
      Console.WriteLine("{0}, {1}", typed.City, typed.Name)
    }
    
    // Cast method - thanks to type inference when calling methods it 
    // is possible to cast object to type without knowing the type name
    T Cast<T>(object obj, T type) {
      return (T)obj;
    }

    via http://social.msdn.microsoft.com/forums/en-US/linqprojectgeneral/thread/c1c179bb-ea88-4633-970a-947f0dd1e71f/

    Jopa123, 18 Марта 2011

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

    +169

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    $pattern = "/\w{0,5}[хx]([хx\s\!@#\$%\^&*+-\|\/]{0,6})[уy]([уy\s\!@#\$%\^&*+-\|\/]{0,6})
    [ёiлeеюийя]\w{0,7}|\w{0,6}[пp]([пp\s\!@#\$%\^&*+-\|\/]{0,6})[iие]([iие\s\!@#\$%\^&*+-\|\/]{0,6})
    [3зс]([3зс\s\!@#\$%\^&*+-\|\/]{0,6})[дd]\w{0,10}|[сcs][уy]([уy\!@#\$%\^&*+-\|\/]{0,6})[4чkк]\w{1,3}
    |\w{0,4}[bб]([bб\s\!@#\$%\^&*+-\|\/]{0,6})[lл]([lл\s\!@#\$%\^&*+-\|\/]{0,6})[yя]\w{0,10}|\w{0,8}[её][bб]
    [лске@eыиаa][наи@йвл]\w{0,8}|\w{0,4}[еe]([еe\s\!@#\$%\^&*+-\|\/]{0,6})[бb]([бb\s\!@#\$%\^&*+-\|\/]{0,6})[uу]
    ([uу\s\!@#\$%\^&*+-\|\/]{0,6})[н4ч]\w{0,4}|\w{0,4}[еeё]([еeё\s\!@#\$%\^&*+-\|\/]{0,6})[бb]([бb\s\!@#\$%\^&*+-\|\/]{0,6})
    [нn]([нn\s\!@#\$%\^&*+-\|\/]{0,6})[уy]\w{0,4}|\w{0,4}[еe]([еe\s\!@#\$%\^&*+-\|\/]{0,6})[бb]([бb\s\!@#\$%\^&*+-\|\/]{0,6})
    [оoаa@]([оoаa@\s\!@#\$%\^&*+-\|\/]{0,6})[тnнt]\w{0,4}|\w{0,10}[ё]([ё\!@#\$%\^&*+-\|\/]{0,6})[б]\w{0,6}|\w{0,4}[pп]
    ([pп\s\!@#\$%\^&*+-\|\/]{0,6})[иeеi]([иeеi\s\!@#\$%\^&*+-\|\/]{0,6})[дd]([дd\s\!@#\$%\^&*+-\|\/]{0,6})
    [oоаa@еeиi]([oоаa@еeиi\s\!@#\$%\^&*+-\|\/]{0,6})[рr]\w{0,12}/i";

    Думал навсегда потерял, а вчера случайно нашел в мемориз на одном из сайтов. Кусок этот встретил лет семь назад.

    Rpsl, 17 Марта 2011

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