1. PHP / Говнокод #8760

    +156

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    case "delete":
       $id=$_GET['id'];
              if(!isset($id)){
              // no id? GTFO   
             header('Location: index.php?go=manage_costumes&act=view'); 
             exit();
             }else{
            // id exists
    ...

    )))

    mimits89, 07 Декабря 2011

    Комментарии (7)
  2. PHP / Говнокод #8759

    +172

    1. 1
    2. 2
    3. 3
    <td class="td_caption" style="width: 40%"><label for="pohuy">Запомнить</label></td>
    
    		<td class="td_value"><input type="checkbox" name="pohuy" checked="checked" id="pohuy"/></td>

    "Я ХАЧУ ГАЛОЧКУ ЗАПОМНИТЬ ПОД ПАРОЛЕМ БИЛЯТЬ", - как скажешь начальник.

    *параметр "pohuy" как вы поняли нигде и никак не обрабатывается.

    jokz, 07 Декабря 2011

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

    +1001

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    bool f = true;
      short c0 = a0, c1 = a1, c2 = a2, c3 = a3;
      if (a0 < c1) { f = false; a0 = c1; a1 = c0 - c1; a2 = c1 - c2; a3 = c1 - c3; }
      if (a0 < c2) { f = false; a0 = c2; a1 = c2 - c1; a2 = c0 - c2; a3 = c2 - c3; }
      if (a0 < c3) { f = false; a0 = c3; a1 = c3 - c1; a2 = c3 - c2; a3 = c0 - c3; }
      if (f)                  { a0 = c0; a1 = c0 - c1; a2 = c0 - c2; a3 = c0 - c3; }

    Чувак не знает про else / else if. :(

    pewpew, 07 Декабря 2011

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

    +1001

    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
    // Функция регистрирующая ошибку
    VOID SetError(DWORD dwError)
    {
        CHAR szErr[256];
        sprintf(szErr, "%lu", dwError);
        SetEnvironmentVariable("0xdeadc0de", szErr);
    }
    
    // Шеллкод
    __declspec(dllexport)
    VOID WINAPI Shell(REMSTART *pCtx)
    {
        pCtx->pLoadLibraryA(pCtx->sz);
        
        CHAR szVar[] = {'0','x','d','e','a','d','c','0','d','e','\0'};
            
        CHAR szErr[256];
        
        if (!pCtx->pGetEnvironmentVariableA(szVar, szErr, sizeof(szErr)))
            pCtx->pExitThread(ERROR_LOAD_HOOK_DLL);
        
        DWORD dwError = 0;
    
        for (DWORD i = 0; szErr[i]; i++)
        {
            dwError *= 10;
            dwError += szErr[i] - '0';
        }
    
        pCtx->pExitThread(dwError);
    }

    Удивительнейший способ регистрации ошибок в функции DllMain при инжекте библиотеки шеллкодом из другого процесса (кто знает - тот поймет)... линк: http://www.wasm.ru/forum/viewtopic.php?id=43291

    ReL, 07 Декабря 2011

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

    +166

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    var numb = '0123456789';
    var lwr = 'abcdefghijklmnopqrstuvwxyz';
    var upr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
    
    function isValid(parm,val) {
    if (parm == "") return true;
    for (i=0; i<parm.length; i++) {
    if (val.indexOf(parm.charAt(i),0) == -1) return false;
    }
    return true;
    }

    http://javascript.about.com/library/blvalid02.htm

    Вырезка из шапки:
    Javascript does not contain functions that test specifically for alphabetic or numeric content but we can easily provide these functions for ourselves...

    denis90, 06 Декабря 2011

    Комментарии (13)
  6. Java / Говнокод #8755

    +76

    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
    @Retention(RetentionPolicy.RUNTIME)
    @Target({ ElementType.FIELD})
    public static @interface Property { String value(); }
    	
    public static class PropertyImpl implements Property {
        private final String value; 
        public PropertyImpl(String value) { this.value = value; }
        @Override public Class<? extends Annotation> annotationType() { return Property.class; }		
        @Override public String value() { return this.value; }
        @Override public int hashCode() { return (127 * "value".hashCode()) ^ value.hashCode();  }
        @Override public boolean equals(Object o) {
            if (!(o instanceof Property)) { return false; }
            Property other = (Property) o;
            return value.equals(other.value());
        }
    }

    отформатировал для компактности.
    Идеи для чего делать реализцию аннотации?

    tir, 06 Декабря 2011

    Комментарии (50)
  7. ActionScript / Говнокод #8754

    −119

    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
    public function checkDrop (pos: Array): Array
     {
     	checkItem ();
     	var res: Array = [];
     	var item: Array
     	var mc: MovieClip
     	for (var i: int = 0; i < pos.length; i++)
     	{
       item = pos[i];
       if (itemList[item[0]])mc = itemList[item[0]][item[1]] as MovieClip;
       if (mc)
       {
       	if (mc.blcd != 0 && ((item[2] == 2 && mc.blcd == 2) || (item[2] == 1 && mc.blcd == 2) || (item[2] == 2 && mc.blcd == 1))) res[i] = 1;
       }
     	}
     	return res;
     }

    Проверка проходимости сетки. И, да, эти мувики не в дисплейлисте, они просто хранят информацию.

    kyzi007, 06 Декабря 2011

    Комментарии (48)
  8. PHP / Говнокод #8753

    +163

    1. 1
    2. 2
    3. 3
    if ($linksCount == 0) $linksCount = -1; // for no error
    	$percent = round(($linksOkIndex/$linksCount)*100, 0);
    	if ($linksCount == -1) $linksCount = 0; // for no error

    Я так избегаю деления на ноль -)

    increazon, 06 Декабря 2011

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

    +71

    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
    setCookie(new String[] {username, Long.toString(expiryTime), signatureValue}, tokenLifetime, request, response);
    
    int tokenLifetime = calculateLoginLifetime(request, successfulAuthentication);
    
    protected int calculateLoginLifetime(HttpServletRequest request, Authentication authentication) {
            return getTokenValiditySeconds();
        }
    
    protected int getTokenValiditySeconds() {
            return tokenValiditySeconds;
        }
    
    private int tokenValiditySeconds = TWO_WEEKS_S;
    
    public static final int TWO_WEEKS_S = 1209600;

    Spring Security........
    Логирование по куки токену.....

    KaRRamBa, 06 Декабря 2011

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

    +997

    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
    class fileOutBuf : public streambuf
    {
    public:
        // ...
        typedef char        char_type;
        typedef int         int_type;
        typedef int         streamsize;
        // ...
        int printf( const char * fpFormat, ... );
    
        inline int vprintf( const char * fpFormat, va_list fvaList )
        {
            if ( NULL != dpFileDescriptor )
            {
                if ( true == sdVerboseFlag  && false == dSkipVerboseOutput)
                    vfprintf( dpVerboseFileDescriptor, fpFormat, fvaList );
    
                return vfprintf( dpFileDescriptor, fpFormat, fvaList );
            }
            else
            {
                if ( NULL != dpOutputFuncPtr )
                    return (*dpOutputFuncPtr)( fpFormat, fvaList );
            }
            return 0;
        }
        // ....
        virtual int_type overflow( int_type c = EOF );
        virtual streamsize xsputn( const char_type *s, streamsize n );
        // ....
    };
    
    int fileOutBuf::printf( const char * fpFormat, ... )
    {
        va_list lvaList;
        int lRet;
    
        va_start( lvaList, fpFormat );
    
        if ( NULL != dpFileDescriptor )
        {
            if ( true == sdVerboseFlag  && false == dSkipVerboseOutput)
                vfprintf( dpVerboseFileDescriptor, fpFormat, lvaList );
    
            lRet = vfprintf( dpFileDescriptor, fpFormat, lvaList );
        }
        else
        {
            if ( NULL != dpOutputFuncPtr )
                lRet = (*dpOutputFuncPtr)( fpFormat, lvaList );
        }
    
        va_end( lvaList );
    
        return lRet;
    }
    
    fileOutBuf::int_type fileOutBuf::overflow( int_type c )
    {
        if ( NULL != dpFileDescriptor )
        {
            if ( true == sdVerboseFlag  && false == dSkipVerboseOutput)
                fputc( c, dpVerboseFileDescriptor );
    
            return fputc( c, dpFileDescriptor );
        }
        else
            return fileOutBuf::printf( "%c", c );
    }
    
    fileOutBuf::streamsize fileOutBuf::xsputn( const fileOutBuf::char_type *s, fileOutBuf::streamsize n )
    {
        if ( NULL != dpFileDescriptor )
        {
            if ( true == sdVerboseFlag  && false == dSkipVerboseOutput)
                fwrite( s, sizeof( char_type ), n, dpVerboseFileDescriptor );
    
            return fwrite( s, sizeof( char_type ), n, dpFileDescriptor );
        }
        else
            return fileOutBuf::printf( "%*s", n, s );
    }

    нетривиальная капипаста или делаем из мухи слона.

    ЗЫ после удаления всей капипасты, от класа в целом осталось что-то около 50 строк.

    Dummy00001, 06 Декабря 2011

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