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

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

    +170

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    $z = 1;
     do
     {
     $key = mt_rand( 100000000, 999999999 );
     if ( strlen( $key ) == 9 )
     {
     $z++;
     }
     } while ( $z < 1 );

    как вам это?

    rastoman, 05 Мая 2011

    Комментарии (17)
  3. Куча / Говнокод #6552

    +123

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    </tr>
    <?php endforeach;?>
    </tbody></table><br>
    
    <?php /*<ul style="margin-left:575px;" id="subnavlist">
        <li><a class="update" href="jobs-favorites.asp">update</a></li>
    </ul> */?>
    </form>

    коммент насящего php программиста

    peinguin, 05 Мая 2011

    Комментарии (17)
  4. Си / Говнокод #6540

    +102

    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
    if (nchan == 1)
      {
        fprintf(commands_ptr,(char *)"StaNoise sta=%s start_time=%14.3f chan_list=%s window_type=nutall4a sub_window_length=%5.1f main_window_length=%6.1f out_dir=%s plot=yes record=yes decon=%s\n",sta,gmttime,chan_list[0],sub_window_length,main_window_length,out_dir,decon_c);
      }
      if (nchan == 2)
      {
        fprintf(commands_ptr,(char *)"StaNoise sta=%s start_time=%14.3f chan_list=%s,%s window_type=nutall4a sub_window_length=%5.1f main_window_length=%6.1f out_dir=%s plot=yes record=yes decon=%s\n",sta,gmttime,chan_list[0],chan_list[1],sub_window_length,main_window_length,out_dir,decon_c);
      }
      if (nchan == 3)
      {
        fprintf(commands_ptr,(char *)"StaNoise sta=%s start_time=%14.3f chan_list=%s,%s,%s window_type=nutall4a sub_window_length=%5.1f main_window_length=%6.1f out_dir=%s plot=yes record=yes decon=%s\n",sta,gmttime,chan_list[0],chan_list[1],chan_list[2],sub_window_length,main_window_length,out_dir,decon_c);
      }
      if (nchan == 4)
      {
        fprintf(commands_ptr,(char *)"StaNoise sta=%s start_time=%14.3f chan_list=%s,%s,%s,%s window_type=nutall4a sub_window_length=%5.1f main_window_length=%6.1f out_dir=%s plot=yes record=yes decon=%s\n",sta,gmttime,chan_list[0],chan_list[1],chan_list[2],chan_list[3],sub_window_length,main_window_length,out_dir,decon_c);
      }
      if (nchan == 5)
      {
        fprintf(commands_ptr,(char *)"StaNoise sta=%s start_time=%14.3f chan_list=%s,%s,%s,%s,%s window_type=nutall4a sub_window_length=%5.1f main_window_length=%6.1f out_dir=%s plot=yes record=yes decon=%s\n",sta,gmttime,chan_list[0],chan_list[1],chan_list[2],chan_list[3],chan_list[4],sub_window_length,main_window_length,out_dir,decon_c);
      }
      if (nchan == 6)
      {
        fprintf(commands_ptr,(char *)"StaNoise sta=%s start_time=%14.3f chan_list=%s,%s,%s,%s,%s,%s window_type=nutall4a sub_window_length=%5.1f main_window_length=%6.1f out_dir=%s plot=yes record=yes decon=%s\n",sta,gmttime,chan_list[0],chan_list[1],chan_list[2],chan_list[3],chan_list[4],chan_list[5],sub_window_length,main_window_length,out_dir,decon_c);
      }
      if (nchan == 7)
      {
        fprintf(commands_ptr,(char *)"StaNoise sta=%s start_time=%14.3f chan_list=%s,%s,%s,%s,%s,%s,%s window_type=nutall4a sub_window_length=%5.1f main_window_length=%6.1f out_dir=%s plot=yes record=yes decon=%s\n",sta,gmttime,chan_list[0],chan_list[1],chan_list[2],chan_list[3],chan_list[4],chan_list[5],chan_list[6],sub_window_length,main_window_length,out_dir,decon_c);
      }
    ...
      }
      if (nchan >= 14)
      {
        fprintf(commands_ptr,(char *)"StaNoise sta=%s start_time=%14.3f chan_list=%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s window_type=nutall4a sub_window_length=%5.1f main_window_length=%6.1f out_dir=%s plot=yes record=yes decon=%s\n",sta,gmttime,chan_list[0],chan_list[1],chan_list[2],chan_list[3],chan_list[4],chan_list[5],chan_list[6],chan_list[7],chan_list[8],chan_list[9],chan_list[10],chan_list[11],chan_list[12],chan_list[13],sub_window_length,main_window_length,out_dir,decon_c);
      }

    Тяжело в сях работать со строками и переменным числом параметров...

    Eyeless, 04 Мая 2011

    Комментарии (17)
  5. C++ / Говнокод #6531

    +168

    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
    typedef union Variant
        {
        public:
            Variant() {}
    
            Variant(signed int val) :
                v_int(val)
            {}
            operator signed int &() { return const_cast<signed int&>(this->operator const signed int &()); }
            operator const signed int&() const { return v_int; }
    
            Variant(unsigned int val) :
                v_uint(val)
            {}
            operator unsigned int &() { return const_cast<unsigned int&>(this->operator const unsigned int &()); }
            operator const unsigned int &() const { return v_uint; }
    
            Variant(char val) :
                v_char(val)
            {}
            operator char &() { return const_cast<char&>(this->operator const char &()); }
            operator const char&() const { return v_char; }
    
            Variant(double val) :
                v_float(val)
            {}
            operator double &() { return const_cast<double&>(this->operator const double &()); }
            operator const double &() const { return v_float; }
    
            Variant(void *val) :
                v_ptr(val)
            {}
            operator void*& () { return const_cast<void*&>(this->operator void *&()); }
            operator const void* const& () const { return v_ptr; }
    
            static size_t getValueSize(const Type::OfType &type)
            {
                size_t result = 0;
                switch ( type )
                {
                case Type::Pointer:
                case Type::CharPtr:
                case Type::IntPtr:
                case Type::UIntPtr:
                case Type::RealPtr:
                case Type::String:
                    result = sizeof(v_ptr);
                    break;
                case Type::Char:
                    result = sizeof(v_char);
                    break;
                case Type::Int:
                    result = sizeof(v_int);
                    break;
                case Type::UInt:
                    result = sizeof(v_uint);
                    break;
                case Type::Real:
                    result = sizeof(v_float);
                    break;
                case Type::Void:
                    result = 0;
                    break;
                }
                return result;
            }
    
        private:
            void* v_ptr;
            char v_char;
            unsigned int v_uint;
            signed int v_int;
            double v_float;
        } Variant;

    Небольшая имплементация безтиповости ;-[

    Elvenfighter, 02 Мая 2011

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

    +158

    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
    <script type="text/javascript"> 
         jQuery('.container').cycle({
        fx:     'scrollHorz',
        prev:   '#prev2',
        next:   '#next2',
        timeout: 0});
        </script>
        <img id="prev2" src="<?=$this->getSkinUrl('images/leftarr.png')?>" alt="Left Arrow" /> 
    <?php     foreach ($_gallery as $_image)
            $__gallery[] = $_image;
    ?>    
        <ul class="container">
        <?php
    
        for($i = 0;$i < count($__gallery);$i++):
            $_image = $__gallery[($i) % count($__gallery)];
        ?>
            <li>
                <a href="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile()); ?>" onclick="slide('<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile()) ?>',<?php echo ($s = isset($s) ? ++$s : 0) ?>,'<?php echo $this->getGalleryUrl($_image) ?>'); return false;"><img src="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $_image->getFile())->resize(90); ?>" alt="<?php echo $this->htmlEscape($_image->getLabel()) ?>" title="<?php echo $this->htmlEscape($_image->getLabel()) ?>" /></a>
            </li>         
        <?php endfor; ?>
        </ul>
        <ul class="container">
        <?php
    
        for($i = 0;$i < count($__gallery);$i++):
            $_image = $__gallery[($i+1) % count($__gallery)];
        ?>
            <li>
                <a href="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile()); ?>" onclick="slide('<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile()) ?>',<?php echo ($s = isset($s) ? ++$s : 0) ?>,'<?php echo $this->getGalleryUrl($_image) ?>'); return false;"><img src="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $_image->getFile())->resize(90); ?>" alt="<?php echo $this->htmlEscape($_image->getLabel()) ?>" title="<?php echo $this->htmlEscape($_image->getLabel()) ?>" /></a>
            </li>         
        <?php endfor; ?>
        </ul>
            <ul class="container">
        <?php
    
        for($i = 0;$i < count($__gallery);$i++):
            $_image = $__gallery[($i+2) % count($__gallery)];
        ?>
            <li>
                <a href="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile()); ?>" onclick="slide('<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile()) ?>',<?php echo ($s = isset($s) ? ++$s : 0) ?>,'<?php echo $this->getGalleryUrl($_image) ?>'); return false;"><img src="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $_image->getFile())->resize(90); ?>" alt="<?php echo $this->htmlEscape($_image->getLabel()) ?>" title="<?php echo $this->htmlEscape($_image->getLabel()) ?>" /></a>
            </li>         
        <?php endfor; ?>
        </ul>
            <ul class="container">
        <?php
    
        for($i = 0;$i < count($__gallery);$i++):
            $_image = $__gallery[($i+3) % count($__gallery)];
        ?>
            <li>
                <a href="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile()); ?>" onclick="slide('<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile()) ?>',<?php echo ($s = isset($s) ? ++$s : 0) ?>,'<?php echo $this->getGalleryUrl($_image) ?>'); return false;"><img src="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $_image->getFile())->resize(90); ?>" alt="<?php echo $this->htmlEscape($_image->getLabel()) ?>" title="<?php echo $this->htmlEscape($_image->getLabel()) ?>" /></a>
            </li>         
        <?php endfor; ?>
        </ul>

    слайдер с прокруткой с помощью цайкла

    jjonghyo, 19 Апреля 2011

    Комментарии (17)
  7. Perl / Говнокод #6370

    −125

    1. 1
    2. 2
    3. 3
    'aaa' =~ /a(?=)aa/;
     'aaa' =~ /(?=)aaa/;
     'aaa' =~ /aaa(?=)/;

    в ActiveState Perl 5.10.0 build 1003 неожиданно обнаружил грубую ошибку в регулярных выражениях. Конструкция (?=), которая означает "с этого места имеется пустой фрагмент текста" вообще не работает! То же относится к аналогичной конструкции "заглядывания назад" (?<=). Например, не находится соответствие в операторах и т.д. Я пришёл в недоумение, ведь это работало правильно в ActiveState Perl 5.8.7 и в более ранних версиях, которые были установлены у меня прежде.

    BlackMonolit, 15 Апреля 2011

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

    +150

    1. 1
    2. 2
    nPosition = !bInvert ? data->pos_back
                                       : data->pos_front;

    Aleskey, 12 Апреля 2011

    Комментарии (17)
  9. JavaScript / Говнокод #6314

    +157

    1. 1
    var is_ie = !(navigator.appName.indexOf("Netscape") != -1);

    Из недр http://habrahabr.ru/blogs/internet/117202/

    ReallyBugMeNot, 12 Апреля 2011

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

    +161

    1. 1
    2. 2
    3. 3
    $Qstatus = $osC_Database->query('select max(cms_id) as cms_id from cms');
            $Qstatus->execute();
            $cms_id = $Qstatus->valueInt('cms_id') + 1;

    Код в OSCommerce использующийся для увеличения id на 1.

    Insane18, 07 Апреля 2011

    Комментарии (17)
  11. Си / Говнокод #6241

    +134

    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
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    97. 97
    98. 98
    99. 99
    int _Mbtowcx(wchar_t *pwc, const char *s, size_t nin, mbstate_t *pst, _Statab *pmbstate)
    	char state = (char)pst->_State;
    	unsigned char *su = (unsigned char *)s;
    	wchar_t wc = (wchar_t)pst->_Wchar;
    	static const mbstate_t initial = {0};
    
    	if (pmbstate->_Tab[0] == 0)	{	/* no table, convert from UTF8 */
    		if (s == 0)
    			{	/* set initial state */
    			*pst = initial;
    			return (0);
    			}
    
    		for (; ; ++su, --nin) {	/* consume an input byte */
    			if (nin == 0) {	/* report incomplete conversion */
    				pst->_Wchar = wc;
    				pst->_State = state;
    				return (-2);
    				}
    			else if (0 < state)	{	/* fold in a successor byte */
    				if ((*su & 0xc0) != 0x80) {	/* report invalid sequence */
    					errno = EILSEQ;
    					return (-1);
    					}
    				wc = (wchar_t)((wc << 6) | (*su & 0x3f));
    				--state;
    				}
    			else if ((*su & 0x80) == 0)
    				wc = *su;	/* consume a single byte */
    			else if ((*su & 0xe0) == 0xc0)	{	/* consume first of two bytes */
    				wc = (wchar_t)(*su & 0x1f);
    				state = 1;
    				}
    			else if ((*su & 0xf0) == 0xe0)	{	/* consume first of three bytes */
    				wc = (wchar_t)(*su & 0x0f);
    				state = 2;
    				}
    
    			else{	/* report invalid sequence */
    				errno = EILSEQ;
    				return (-1);
    				}
    			if (state == 0)	{	/* produce an output wchar */
    				if (pwc != 0)
    					*pwc = wc;
    				pst->_State = 0;
    				return (wc == 0 ? 0 : (const char *)++su - s);
    				}
    			}
    
    		}
    	else
    		{	/* run finite state machine */
    		int limit = 0;
    
    		if (s == 0)	{	/* set initial state */
    			*pst = initial;
    			return (pmbstate->_Tab[0][0] & _ST_STATE);
    			}
    
    		for (; ; )	{	/* perform a state transformation */
    			unsigned short code;
    			const unsigned short *stab;
    
    			if (nin == 0)
    				{	/* report incomplete conversion */
    				pst->_Wchar = wc;
    				pst->_State = state;
    				return (-2);
    				}
    			else if (_NSTATE <= state
    				|| (stab = pmbstate->_Tab[state]) == 0
    				|| (_NSTATE*UCHAR_MAX) <= ++limit
    				|| (code = stab[*su]) == 0)
    				{	/* report invalid sequence */
    				errno = EILSEQ;
    				return (-1);
    				}
    			state = (char)((code & _ST_STATE) >> _ST_STOFF);
    			if (code & _ST_FOLD)
    				wc = (wchar_t)(wc & ~UCHAR_MAX | code & _ST_CH);
    			if (code & _ST_ROTATE)
    				wc = (wchar_t)(wc << CHAR_BIT | UCHAR_MAX
    					& wc >> CHAR_BIT * (sizeof (wchar_t) - 1));
    			if (code & _ST_INPUT && *su != '\0')
    				++su, --nin, limit = 0;
    			if (code & _ST_OUTPUT)
    				{	/* produce an output wchar */
    				int nused = (const char *)su - s;
    
    				if (pwc)
    					*pwc = wc;
    				pst->_Wchar = wc;
    				pst->_State = state;
    				return (wc == 0 ? 0 : nused == 0 ? -3 : nused);
    				}
    			}
    		}
    	}

    Долго не мог понять почему не работает
    setlocale(...);
    _setmbcp(...);
    mbtowc(...);

    на C++ Builder. Пока не заглянул в исходники.

    sanchousf, 05 Апреля 2011

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