1. 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)
  2. 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)
  3. 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)
  4. 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)
  5. 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)
  6. 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)
  7. Objective C / Говнокод #8750

    −84

    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
    -(void)shekinNow:(id)prev
    {
        float YI = rand() / (float)RAND_MAX;
        NSArray *subv = [imageV subviews];
        long index = (long)(rand()/(RAND_MAX/([subv count])));
        SlotUnit *unit = [subv objectAtIndex:index];
        if(unit == prev) {
            [self shekinNow:prev];//рекурисия епт
            return;
        }
        CGFloat gradus = ((YI*70/99)*100);
        CGFloat radian = (gradus * M_PI / 180);
        [unit setTag:0];
        [UIView beginAnimations:@"one" context:unit];
        [UIView setAnimationDidStopSelector:@selector(moveTuda:finished:context:)];
        [UIView setAnimationDuration:anidur];
        [UIView setAnimationDelegate:self];
        [unit sendRotating:radian];
        [UIView commitAnimations];
    }

    Вот так трансректально можно применять рекурсию.

    Psionic, 06 Декабря 2011

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

    +159

    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
    notify: function(evt) {
    	var state = this.prevFirst === null ? 'init' : (this.prevFirst < this.first ? 'next' : 'prev');
    
    	// Load items
    	this.callback('itemLoadCallback', evt, state);
    
    	if (this.prevFirst !== this.first) {
    		this.callback('itemFirstInCallback', evt, state, this.first);
    		this.callback('itemFirstOutCallback', evt, state, this.prevFirst);
    	}
    
    	if (this.prevLast !== this.last) {
    		this.callback('itemLastInCallback', evt, state, this.last);
    		this.callback('itemLastOutCallback', evt, state, this.prevLast);
    	}
    
    	this.callback('itemVisibleInCallback', evt, state, this.first, this.last, this.prevFirst, this.prevLast);
    	this.callback('itemVisibleOutCallback', evt, state, this.prevFirst, this.prevLast, this.first, this.last);
    },

    Популярный jQuery плагин - "jCarousel"
    http://sorgalla.com/projects/jcarousel/

    2 часа пытался реализовать инициализацию элементов "конвеера" до появления их на экране.
    Но не тут-то было. Все 7 событий, регулирующих смену позиции - вызываются в один момент времени (при занятии элементом итогового положения).
    • itemLoadCallback
    • itemFirstInCallback
    • itemFirstOutCallback
    • itemLastInCallback
    • itemLastOutCallback
    • itemVisibleInCallback
    • itemVisibleOutCallback

    *this.callback сводится до fn.call()

    Centry, 06 Декабря 2011

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

    +120

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    // LockDepth IS enum type!
    if(LockDepth == DepthType.Infinity)
    	_depthElement.InnerText = this.__lockDepth.ToString();
    else
    	_depthElement.InnerText = (string) System.Enum.Parse(LockDepth.GetType(), LockDepth.ToString(), true);

    I got exception on line 5. The LockDepth is enum :)

    bugotrep, 06 Декабря 2011

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

    +123

    1. 1
    Рабочий стол > Контент > Структура сайта > Файлы и папки > bitrix > templates > .default > components > bitrix > sale.personal.order > main > bitrix > bitrix > sale.personal.order.detail > .default > lang > ru > template.php

    Это чтобы в Битриксе поменять одну фитюльку.

    ling, 06 Декабря 2011

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