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

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

    +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
    Ckey::Ckey(const String& name, const String& suffix1, const String& suffix2, const String& suffix3)
    {
    	ASSERT(name.Size(), "Key with emty name are invalid!");
    
    	if (!name.Size())
    	{
    		return;
    	}
    	PushBack(name);
    
    	if (!suffix1.Size())
    	{
    		return;
    	}
    	PushBack(suffix1);
    
    	if (!suffix2.Size())
    	{
    		return;
    	}
    	PushBack(suffix2);
    
    	if (!suffix3.Size())
    	{
    		return;
    	}
    	PushBack(suffix3);
    }

    Ну просто замечательный конструктор класса.
    Собственно сам класс унаследован (public-ом, причем) от местной реализации класса vector, отсюда загадочные методы PushBack.
    А String - это не менее замечательная, местная, реализация строк.

    elenbert, 14 Апреля 2011

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

    +160

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    ­  //create a list of rules to block
      var blockRules = ["http://example.com/images/*",
                         "*://example.org/css/*"];
    
      // add them to the content blocker
      for (var rule in blockRules) {
        opera.extension.urlfilter.block.add(blockRules[rule])
      }

    Экзампле из официальной документации одного браузера, отчаянно пытающегося прекратить катиться в сраное говно и набрать популярность.
    Будет растащено хомячками на копипасту.

    И, striker, убери уже этот долбанный trim для leading spaces

    bugmenot, 13 Апреля 2011

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

    +132

    1. 1
    2. 2
    3. 3
    <A\n <BR / href="http://www.site.ru" >Некий текст</A>
    <P Иванов id=Значение_без_кавычек_кирилицей><P>Некий текст</P>
    <SPAN><SPAN Л.И. Некий текст</SPAN>

    Вот несколько кривых кусков HTML кода с одного государственного портала

    BlackMonolit, 13 Апреля 2011

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

    +74

    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
    public class BeanWrapperImpl extends AbstractPropertyAccessor implements BeanWrapper {
             @SuppressWarnings("unchecked")
             private void setPropertyValue(PropertyTokenHolder tokens, PropertyValue pv) throws BeansException {
    		String propertyName = tokens.canonicalName;
    		String actualName = tokens.actualName;
    
    		if (tokens.keys != null) {
    			// Apply indexes and map keys: fetch value for all keys but the last one.
    			PropertyTokenHolder getterTokens = new PropertyTokenHolder();
    			getterTokens.canonicalName = tokens.canonicalName;
    			getterTokens.actualName = tokens.actualName;
    			getterTokens.keys = new String[tokens.keys.length - 1];
    			System.arraycopy(tokens.keys, 0, getterTokens.keys, 0, tokens.keys.length - 1);
    			Object propValue;
    			try {
    				propValue = getPropertyValue(getterTokens);
    			}
    			catch (NotReadablePropertyException ex) {
    				throw new NotWritablePropertyException(getRootClass(), this.nestedPath + propertyName,
    						"Cannot access indexed value in property referenced " +
    						"in indexed property path '" + propertyName + "'", ex);
    			}
    			// Set value for last key.
    			String key = tokens.keys[tokens.keys.length - 1];
    			if (propValue == null) {
    				throw new NullValueInNestedPathException(getRootClass(), this.nestedPath + propertyName,
    						"Cannot access indexed value in property referenced " +
    						"in indexed property path '" + propertyName + "': returned null");
    			}
    			else if (propValue.getClass().isArray()) {
    				PropertyDescriptor pd = getCachedIntrospectionResults().getPropertyDescriptor(actualName);
    				Class requiredType = propValue.getClass().getComponentType();
    				int arrayIndex = Integer.parseInt(key);
    				Object oldValue = null;
    				try {
    					if (isExtractOldValueForEditor()) {
    						oldValue = Array.get(propValue, arrayIndex);
    					}
    					Object convertedValue = convertIfNecessary(propertyName, oldValue, pv.getValue(), requiredType,
    							new PropertyTypeDescriptor(pd, new MethodParameter(pd.getReadMethod(), -1), requiredType));
    					Array.set(propValue, arrayIndex, convertedValue);
    				}
    				catch (IndexOutOfBoundsException ex) {
    					throw new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName,
    							"Invalid array index in property path '" + propertyName + "'", ex);
    				}
    			}
    			else if (propValue instanceof List) {
    				PropertyDescriptor pd = getCachedIntrospectionResults().getPropertyDescriptor(actualName);
    				Class requiredType = GenericCollectionTypeResolver.getCollectionReturnType(
    						pd.getReadMethod(), tokens.keys.length);
    				List list = (List) propValue;
    				int index = Integer.parseInt(key);
    				Object oldValue = null;
    				if (isExtractOldValueForEditor() && index < list.size()) {
    					oldValue = list.get(index);
    				}
    				Object convertedValue = convertIfNecessary(propertyName, oldValue, pv.getValue(), requiredType,
    						new PropertyTypeDescriptor(pd, new MethodParameter(pd.getReadMethod(), -1), requiredType));
    				if (index < list.size()) {
    					list.set(index, convertedValue);
    				}
    				else if (index >= list.size()) {
    					for (int i = list.size(); i < index; i++) {
    						try {
    							list.add(null);
    						}
    						catch (NullPointerException ex) {
    							throw new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName,
    									"Cannot set element with index " + index + " in List of size " +
    									list.size() + ", accessed using property path '" + propertyName +
    									"': List does not support filling up gaps with null elements");
    						}
    					}
    					list.add(convertedValue);
    				}
    			}
    			else if (propValue instanceof Map) {
    			      //...
                             }
                      }
             }
    }

    Spring...

    nikelin, 12 Апреля 2011

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

    +162

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    function db_date_time($time = null) {
    	if (is_null($time)) {
    		$time = time();
    	}
    	$s = explode('.', date("d.m.Y.H.i.s", $time));
    	return $s[2] . '-' . $s[1] . '-' . $s[0] . ' ' . $s[3] . ':' . $s[4] . ':' . $s[5];
    }

    Silentium, 10 Апреля 2011

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

    −179

    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
    class Student(models.Model):
        fio = models.CharField(max_length=100)
        birthday = models.DateField()
        stud_tick = models.IntegerField()
        group = models.ForeignKey("Group")
        starosta = models.BooleanField()
     
        class Meta:
              unique_together = (("group", "starosta"),)
     
     
    class Group(models.Model):
        name = models.CharField(max_length=20)
     
    admin.site.register(Student)
    admin.site.register(Group)

    qbasic, 09 Апреля 2011

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

    +161

    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
    #include "header.hpp"
     
    int main(int argc, char** argv) {
       if ( argc != 4 ) {
          std::cout << "client ip port 0/1 - sleed disabled/enabled" << std::endl;
          return 0;
       }
       std::string ip = argv[1];
       boost::uint16_t port = boost::lexical_cast<boost::uint16_t>(argv[2]);
       bool wsleep = (argv[3][0] == '1');
       std::cout << "sleep " << (wsleep?"enabled":"disabled") << std::endl;
       
       FILE* in = fopen("client_in.log", "wb");
       FILE* out= fopen("client_out.log", "wb");
       if ( !out || !in ) {
          std::cout << "can`t open file!" << std::endl;
          return 1;
       }
     
       boost::asio::ip::tcp::endpoint endpoint(
          boost::asio::ip::address::from_string(ip), port
       );
     
       boost::asio::io_service ios;
       boost::shared_ptr<boost::asio::io_service::work> work(new boost::asio::io_service::work(ios));
     
       boost::thread thread(boost::bind(&boost::asio::io_service::run, &ios));
       
       boost::asio::ip::tcp::socket socket(ios);
       socket.connect(endpoint);
     
       boost::asio::socket_base::non_blocking_io non_blocking_io(true);
       socket.io_control(non_blocking_io);
     
       client_read(socket, in);
     
       for ( size_t idx = 0; idx < 100000000; ++idx ) {
          char* buf = new char[send_buffer_size];
          sprintf(buf, "cs:%8dn", idx);
          start_write(socket, buf, out);
          if ( wsleep ) {
             boost::this_thread::sleep(boost::posix_time::microseconds(1000));
          }
       }
     
       std::cout
       << "send data to server finished!" << std::endl
       << "waiting for all ask`s from server..." << std::endl;
     
       work.reset();
     
       while ( counter ) {
          boost::this_thread::sleep(boost::posix_time::microseconds(1000));
          std::cout << "." << std::flush;
       }
     
       std::cout << std::endl << std::endl
       << "all ask`s received." << std::endl
       << "terminate client..." << std::endl;
     
       socket.cancel();
       socket.close();
     
       thread.join();
       fclose(in);
       fclose(out);
    }

    qbasic, 08 Апреля 2011

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

    +70

    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
    public static void m()
        {
            cO = cO + "3659";
            RecordStore recordstore;
            if((recordstore = RecordStore.openRecordStore("saves", true)) != null)
            {
                if(recordstore.getNumRecords() == 20)
                    recordstore.closeRecordStore();
                for(; recordstore.getNumRecords() < 20; recordstore.addRecord(null, 0, 0));
                byte abyte0[] = recordstore.getRecord(6);
                recordstore.setRecord(20, abyte0, 0, abyte0 == null ? 0 : abyte0.length);
                recordstore.closeRecordStore();
            }
            return;
            JVM INSTR dup ;
            Exception exception;
            exception;
            printStackTrace();
            cQ.concat("fuck ur hax, nigers :) muahaha :D");
            cQ + "x";
            return;
        }

    Не поверите, но это было найдено в недрах java игрушки :)

    Govnocoder#0xFF, 07 Апреля 2011

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

    −369

    1. 1
    n=' '.join((n[::-1][n[::-1].find('_')+1:])[::-1].lower().replace('_',' ').split()).split()

    Нашел у себя в коде. Что делает уже не осилил вспомнить.

    spaceoflabview, 07 Апреля 2011

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

    +105

    1. 001
    2. 002
    3. 003
    4. 004
    5. 005
    6. 006
    7. 007
    8. 008
    9. 009
    10. 010
    11. 011
    12. 012
    13. 013
    14. 014
    15. 015
    16. 016
    17. 017
    18. 018
    19. 019
    20. 020
    21. 021
    22. 022
    23. 023
    24. 024
    25. 025
    26. 026
    27. 027
    28. 028
    29. 029
    30. 030
    31. 031
    32. 032
    33. 033
    34. 034
    35. 035
    36. 036
    37. 037
    38. 038
    39. 039
    40. 040
    41. 041
    42. 042
    43. 043
    44. 044
    45. 045
    46. 046
    47. 047
    48. 048
    49. 049
    50. 050
    51. 051
    52. 052
    53. 053
    54. 054
    55. 055
    56. 056
    57. 057
    58. 058
    59. 059
    60. 060
    61. 061
    62. 062
    63. 063
    64. 064
    65. 065
    66. 066
    67. 067
    68. 068
    69. 069
    70. 070
    71. 071
    72. 072
    73. 073
    74. 074
    75. 075
    76. 076
    77. 077
    78. 078
    79. 079
    80. 080
    81. 081
    82. 082
    83. 083
    84. 084
    85. 085
    86. 086
    87. 087
    88. 088
    89. 089
    90. 090
    91. 091
    92. 092
    93. 093
    94. 094
    95. 095
    96. 096
    97. 097
    98. 098
    99. 099
    100. 100
    function TForm1.CheckGameO: String;
    begin
     Result := '';
     If (A1.Tag = 2) and (A2.Tag = 2) then
      Begin
       Result := 'A3';
       If not CheckPos(Result) then Exit;
      End;
    
     If (A1.Tag = 2) and (A3.Tag = 2) then
      Begin
       Result := 'A2';
       If not CheckPos(Result) then Exit;
      End;
    
     If (A1.Tag = 2) and (C3.Tag = 2) then
      Begin
       Result := 'B2';
       If not CheckPos(Result) then Exit;
      End;
    
     If (A1.Tag = 2) and (B2.Tag = 2) then
      Begin
       Result := 'C3';
      If not CheckPos(Result) then Exit;
      End;
    
     If (A1.Tag = 2) and (B1.Tag = 2) then
      Begin
       Result := 'C1';
       If not CheckPos(Result) then Exit;
      End;
    
     If (A1.Tag = 2) and (C1.Tag = 2) then
      Begin
       Result := 'B1';
       If not CheckPos(Result) then Exit;
      End;
    
     If (B2.Tag = 2) and (C3.Tag = 2) then
      Begin
       Result := 'A1';
       If not CheckPos(Result) then Exit;
      End;
    
     If (B2.Tag = 2) and (A2.Tag = 2) then
      Begin
       Result := 'C2';
       If not CheckPos(Result) then Exit;
      End;
    
     If (B2.Tag = 2) and (C2.Tag = 2) then
      Begin
       Result := 'A2';
       If not CheckPos(Result) then Exit;
      End;
    
     If (B2.Tag = 2) and (C1.Tag = 2) then
      Begin
       Result := 'A3';
       If not CheckPos(Result) then Exit;
      End;
    
     If (B2.Tag = 2) and (A3.Tag = 2) then
      Begin
       Result := 'C1';
       If not CheckPos(Result) then Exit;
      End;
    
     If (B2.Tag = 2) and (B1.Tag = 2) then
      Begin
       Result := 'B3';
       If not CheckPos(Result) then Exit;
      End;
    
     If (B2.Tag = 2) and (B3.Tag = 2) then
      Begin
       Result := 'B1';
       If not CheckPos(Result) then Exit;
      End;
    
     If (C3.Tag = 2) and (A3.Tag = 2) then
      Begin
       Result := 'B3';
       If not CheckPos(Result) then Exit;
      End;
    
     If (C3.Tag = 2) and (B3.Tag = 2) then
      Begin
       Result := 'A3';
       If not CheckPos(Result) then Exit;
      End;
    
     If (C3.Tag = 2) and (C2.Tag = 2) then
      Begin
       Result := 'C1';
       If not CheckPos(Result) then Exit;
      End;
    
    ...

    Кто угадает для чего это предназначалось получит печенье.

    Govnocoder#0xFF, 06 Апреля 2011

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