1. 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)
  2. 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)
  3. 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)
  4. 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)
  5. 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)
  6. 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)
  7. 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)
  8. Куча / Говнокод #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)
  9. C# / Говнокод #8746

    +122

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    internal static class ExceptionHelper
    {
        public static void Throw()
        {
             Throw("Syntax error.");
        }
    
        public static void Throw(string msg)
        {
            new Exception(msg);
         }
    }

    Просто и красиво! Архитектурное решение - архитектор жжет!

    govnokoder_, 06 Декабря 2011

    Комментарии (15)
  10. ActionScript / Говнокод #8745

    −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
    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
    private function pathfindingOfHell(begin:Point, to:Point, delPoint:Point):Boolean
    		{
    			var aop:Vector.<GameFigure> = new Vector.<GameFigure>();
    			aop.push(arr[begin.x][begin.y]);
    			var i:uint = 0;
    			while (i != count * 2 - 1)
    			{
    				for (var x_:int = -1;x_ < 2;x_++)
    					for (var y_:int = -1;y_ < 2;y_++)
    					{
    						if (x_ != 0 && y_ != 0)
    						{
    							var tP:Point = new Point(aop[aop.length - 1].x_pos + x_, aop[aop.length - 1].y_pos + y_);
    							var target:GameFigure = arr[tP.x][tP.y];
    
    							if (!target.isFreedom && !searchInArray(aop, target) && delPoint != tP)
    							{
    								aop.push(target);
    								if (target == arr[to.x][to.y])
    								{
    									aop = null;
    									return true;
    								}
    							}
    						}
    					}
    				i++;
    			}
    			aop = null;
    			return false;
    		}

    KirAmp, 06 Декабря 2011

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