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

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

    +157

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    {{sectionelse}}
                        <script language="javascript">
                          window.location = '/megasection/megapage.html?step='+{{if $step eq '2'}}'3'{{else}}'1'{{/if}};
                        </script>
    {{/section}}

    PHP, Smarty, редиректы уже не в моде

    govno, 18 Апреля 2011

    Комментарии (10)
  3. 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)
  4. 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)
  5. Куча / Говнокод #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)
  6. 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)
  7. 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)
  8. 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)
  9. C++ / Говнокод #6277

    +165

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    ID3DBlob* pErrorBlob;
        hr = D3DX11CompileFromFile( szFileName, NULL, NULL, szEntryPoint, szShaderModel, 
            dwShaderFlags, 0, NULL, ppBlobOut, &pErrorBlob, NULL );
        if( FAILED(hr) )
        {
            if( pErrorBlob != NULL )
                OutputDebugStringA( (char*)pErrorBlob->GetBufferPointer() );
            if( pErrorBlob ) pErrorBlob->Release();
            return hr;
        }
        if( pErrorBlob ) pErrorBlob->Release();

    Текст примера из MS DXSDK. Проверка - а вдруг pErrorBlob самоуничтожается после прочтения?

    CHayT, 07 Апреля 2011

    Комментарии (10)
  10. 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)
  11. Python / Говнокод #6267

    −369

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

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

    spaceoflabview, 07 Апреля 2011

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