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

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

    +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
    // TEMPLATE FUNCTION rotate
    template<class _FI> inline
    	void rotate(_FI _F, _FI _M, _FI _L)
    	{if (_F != _M && _M != _L)
    		_Rotate(_F, _M, _L, _Iter_cat(_F)); }
    template<class _FI> inline
    	void _Rotate(_FI _F, _FI _M, _FI _L,
    		forward_iterator_tag)
    	{for (_FI _X = _M; ; )
    		{iter_swap(_F, _X);
    		if (++_F == _M)
    			if (++_X == _L)
    				break;
    			else
    				_M = _X;
    		else if (++_X == _L)
    			_X = _M; }}
    template<class _BI> inline
    	void _Rotate(_BI _F, _BI _M, _BI _L,
    		bidirectional_iterator_tag)
    	{reverse(_F, _M);
    	reverse(_M, _L);
    	reverse(_F, _L); }
    template<class _RI> inline
    	void _Rotate(_RI _F, _RI _M, _RI _L,
    			random_access_iterator_tag)
    	{_Rotate(_F, _M, _L, _Dist_type(_F), _Val_type(_F)); }
    template<class _RI, class _Pd, class _Ty> inline
    	void _Rotate(_RI _F, _RI _M, _RI _L, _Pd *, _Ty *)
    	{_Pd _D = _M - _F;
    	_Pd _N = _L - _F;
    	for (_Pd _I = _D; _I != 0; )
    		{_Pd _J = _N % _I;
    		_N = _I, _I = _J; }
    	if (_N < _L - _F)
    		for (; 0 < _N; --_N)
    			{_RI _X = _F + _N;
    			_RI _Y = _X;
    			_Ty _V = *_X;
    			_RI _Z = _Y + _D == _L ? _F : _Y + _D;
    			while (_Z != _X)
    				{*_Y = *_Z;
    				_Y = _Z;
    				_Z = _D < _L - _Z ? _Z + _D
    					: _F + (_D - (_L - _Z)); }
    			*_Y = _V; }}

    Header из Microshit Visual C++ 6.0.

    Говногость, 02 Февраля 2011

    Комментарии (23)
  3. PHP / Говнокод #5478

    +158

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    $f=file('[путь к файлу]'); 
    shuffle($f); 
    $f[0] - первая случайная строка 
    $f[1] - вторая случайная строка 
    $f[2] - третья случайная строка

    вот PHP еще. если например несколько строк надо. ну и оптимальнее чем предложено выше.
    http://megaobzor.com/forum-top-77608.html

    Наверху было классическое

    $quote=file('words.txt'); 
    echo $quote[rand(0,count($quote)-1)];

    Несомненно, оптимальнее. Особенно, если строчек эдак тыщ сто.

    Кстати, предлагаю начать очередной холивар по поводу того, как с самыми меньшими затратами вынуть из файла рандомную строчку :)

    7ion, 02 Февраля 2011

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

    +158

    1. 1
    2. 2
    lblSoundBar = new render::gui::BitmapLabel(strings::StaticString(L"Music"), GameFonts::instance().getGUIFont(), math::float2(380.0f, 225.0f), 0xFFFFFFFF, 1.0f, 0.0f);
    lblMusicBar = new render::gui::BitmapLabel(strings::StaticString(L"Sound"), GameFonts::instance().getGUIFont(), math::float2(380.0f, 315.0f), 0xFFFFFFFF, 1.0f, 0.0f);

    Kirinyale, 31 Января 2011

    Комментарии (9)
  5. PHP / Говнокод #5431

    +158

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    $userList = "";
    foreach ($this->currentUsers as $k => $v)
    { 
        $userList .= ($v->first_name . (empty($v->middle_name) ? "" : " " . $v->middle_name)  . " " . $v->last_name . ", ");
    }
    $userList = substr($userList, 0, -2);
    ?>
    <?= $userList ?>

    Индусы отдыхают.

    anycolor, 28 Января 2011

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

    +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
    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
    class Relay {
      protected $_data = array();
      protected $_devices;
      static protected $_db_fields = array();
    
      function getId() {
        return $this->_data['id'];
      }
      static function load($id) {
        if ($id) {
          $select = db_select('relay', 'r');
          $select->fields('r');
          $select->condition('r.id', $id);
          $relay = $select->execute()->fetchObject(__CLASS__);
          return $relay;
        }
      }
      function save() {
        foreach (array_diff(array_keys($this->_data), self::_getPureDbFields('relay')) as $field) {
          $this->_data['data'] = $this->_data[$field];
        }
    
        if ($this->getId()) {
          drupal_write_record('relay', $this->_data, array('id'));
        }
        else {
          drupal_write_record('relay', $this->_data);
        }
        $this->_saveDevices();
      }
      protected function _saveDevices() {
        if ($this->getId()) {
          $delete = db_delete('relay_devices');
          $delete->condition('relay_id', $this->getId());
          $delete->execute();
    
          foreach ((array)$this->_devices as $device) {
            $device = (array) $device;
            foreach (array_diff(array_keys($device), self::_getPureDbFields('relay_devices')) as $field) {
              $device['data'] = $device[$field];
            }
    
            drupal_write_record('relay_devices', $device);
          }
        }
      }
      function getDateFrom() {
        return $this->_data['date_from'];
      }
      function getDateDuration(){
        return $this->_data['date_duration'];
      }
      function getDateTo(){
        return $this->getDateFrom() + $this->getDateDuration();
      }
      function getDevices(){
        $this->_ensureDevicesLoaded();
        return $this->_devices;
      }
      protected function _ensureDevicesLoaded() {
        if (!is_array($this->_devices)) {
          $select = db_select('relay_devices', 'rd');
          $select->fields('rd');
          $select->condition('rd.relay_id', $this->getId());
          $query = $select->execute();
    
          $this->_devices = array_map('drupal_unpack', $query->fetchAll());
        }
        return is_array($this->_devices);
      }
      function __construct($data = NULL) {
        if (is_array($data)) {
          foreach ($data as $key => $value) {
            $this->_data[$key] = $value;
          }
        }
        elseif (is_string($this->_data['data']) && !empty($this->_data['data'])) {
          drupal_unpack($this);
        }
      }
      function __set($name, $value) {
        return $this->_data[$name] = $value;
      }
      function __get($name) {
        return $this->_data[$name];
      }
      static protected function _getPureDbFields($table) {
        if (!isset(self::$_db_fields[$table])) {
          $schema = drupal_get_schema($table);
          $fields = $schema['fields'];
          unset($fields['data']);
          self::$_db_fields[$table] = array_keys($fields);
        }
    
        return self::$_db_fields[$table];
      }
    }

    vectoroc, 26 Января 2011

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

    +158

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    template <typename T> struct Rect : public ICollidable<T>  {
                T top, left, width, height;
    ...
                Rect(T _top, T _left, T w, T h)
                : top(_top)
                , left(_left)
                , width(w)
                , height(h)
                {};
    ...
    };

    Не расслабляемся: естественный порядок аргументов - это для ламеров!

    Kirinyale, 25 Января 2011

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

    +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
    <?php
    define('ROOT', './');
    include ROOT.'func.php';
    include ROOT.'class.php';
    puthead();
    if(isset($_GET['e'])){
      echo 'Ошибка '.$_GET['e'];
    }
    $incpage='';
    for($i=0;$i<2;$i++){
      if(isset($_GET["i$i"]) && preg_match('/^[a-zA-Z0-9_]+$/', $_GET["i$i"])) $incpage=$_GET["i$i"];
    }
    if($incpage==''){
    if($is_web) include ROOT.'about.tchtml';
    else include ROOT.'index_page.tchtml';
    }
    else include ROOT.$incpage.'.tchtml';
    putfoot();
    ?>
    
    <?php
    define('ROOT', './');
    include ROOT.'func.php';
    puthead('Заголовок');
    ?>
    Пример создания страниц под двиг
    <?
    putfoot();
    ?>

    The CMS. (Да, это такое название.)
    Как ни странно, в состав входит полноценный форум, гостевая книга, модуль новостей и еще куча всякой херни.
    И все это даже работает.
    Но тут меня угораздило заглянуть в сорцы.
    index.php и пример создания страницы.

    7ion, 23 Января 2011

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

    +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
    (function(){ if(!window.adToken) { window.adToken = Math.floor(Math.random() * 999999999999999999); }
    		var d = new Date();
    		var url = (location.protocol=='https:'?'https://base.kiwi.kz/?':'http://base.kiwi.kz/?');
    		url += 'rnd=' + Math.floor(Math.random() * 99999999999);
    		url	+= '&slot_id=25';
    		url	+= '&type=js';
    		url	+= '&t=' + parseInt(((d.getTime() - (d.getTimezoneOffset() * 60)) / 1000));
    		url	+= '&token=' + window.adToken;
    		url	+= '&r=' + window.location;
    		var js	 = '<sc' + 'ript src="' + url + '"></sc' + 'ript>';
    		document.write(js);
    		}());

    sc' + 'ript ?

    govnozmey, 14 Января 2011

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

    +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
    if(($res = GetMysqlRes("SELECT id,name,price,anons2,colors,sizes,anons,content2,content,maker,title FROM {$oCfg->prefX}core WHERE top=".$pid." and act=1 ORDER BY date DESC LIMIT ".($pnum-1)*$eop.",".$eop."",array($pid),false)) != false)
    {
    while (($row = $db->fetch_row($res)) !== false)
    		{
    
    	...<script type='text/javascript'>
    		function chs".$row[0]."() {
    			document.getElementById(\"s_size".$row[0]."\").innerHTML = document.getElementById(\"sel_size".$row[0]."\").value;
    		}
    		function chc".$row[0]."() {
    			document.getElementById(\"s_color".$row[0]."\").innerHTML = document.getElementById(\"sel_color".$row[0]."\").value;
    		}
    	</script>...
    
    }
    }

    это находилось в цикле. К этому же потом обращались для добавления в корзину товара.

    Три точки значат что там есть еще код.

    P.S. Опять же привет мазе.

    De-Luxis, 12 Января 2011

    Комментарии (1)
  11. JavaScript / Говнокод #5203

    +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
    // create singelton object, see below 
    function singelton(classDesc) {
        return classDesc;
    }
    
    
    var LetterTypeAction = singelton(
        {
            selectLetterType : function(controlId, index) {
               letterTypeManager.selectLetterType(controlId, index);
            },
    
            addLetterType : function() {
                letterTypeManager.addLetterType();
            },
    
            saveLetterType : function() {
                var tempLetterType = new LetterTypeDef();
                tempLetterType.setId(currentLetterType.getId());
                tempLetterType.setAbbreviation(TextUtils.trim(ControlUtils.getValueById(letterTypeAbbrId)));
                tempLetterType.setDescription(TextUtils.trim(ControlUtils.getValueById(letterTypeDescrId)));            
    
                letterTypeManager.saveLetterType(tempLetterType);
            },
    
            changeLetterType : function() {
                letterTypeManager.changeLetterType();            
            },
    
            deleteLetterType : function() {
                letterTypeManager.deleteLetterType(currentLetterType);
            },
    
            cancelLetterType : function() {
                letterTypeManager.cancelLetterType();
            },
    
            sortLetterType : function(columnId) {
                letterTypeManager.sortLetterType(columnId);            
            }
        }
    );

    новый паттерн проектирования, добавляющий в код мусор

    tr00_gr1m_doomster, 10 Января 2011

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