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

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

    +162

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    if(!$RISK && in_array($USER->GetID(), array("1", "14"))){
    	$RECCURING = true;
    }else{
    	$RECCURING = false;
    }

    Подписка на оплату. Магические числа 1 и 14.

    hdkeeper, 28 Января 2011

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

    +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
    function filetypecheck( $filename )
    {
    	$ext = substr(GetFileExt($filename), 1);
    	if($ext == 'rar'){ $dtype = 'Архив RAR'; }
    	if($ext == 'zip'){ $dtype = 'Архив ZIP'; }
    	if($ext == '7z') { $dtype = 'Архив 7zip'; }
    	if($ext == 'bz2'){ $dtype = 'BZ2'; }
    	if($ext == 'cab'){ $dtype = 'CAB'; }
    	if($ext == 'ace'){ $dtype = 'WinACE'; }
    	if($ext == 'arj'){ $dtype = '<a class=\"cont\" href=\"http://www.tsf.be/\" target=\"_blank\">ARJ</a>'; }
    	if($ext == 'jar'){ $dtype = '<a class=\"cont\" href=\"http://www.tsf.be/\" target=\"_blank\">JAR</a>'; }
    
    	if($ext == 'gzip'){ $dtype = 'GZIP'; }
    	if($ext == 'tar'){ $dtype = 'TAR'; }
    	if($ext == 'tgz'){ $dtype = 'TGZ'; }
    	if($ext == 'gz'){ $dtype = 'GZ'; }
    
    	if($ext == 'gif'){ $dtype = 'GIF'; }
    	if(preg_match('/jpeg|jpe|jpg/i', $ext)){ $dtype = 'JPEG/JPE/JPG'; }
    	if($ext == 'png'){ $dtype = 'PNG'; }
    	if($ext == 'bmp'){ $dtype = 'BMP'; }
    
    	if($ext == 'txt'){ $dtype = 'TXT'; }
    	if($ext == 'sql'){ $dtype = 'SQL'; }
    	if($ext == 'exe'){ $dtype = 'EXE'; }
    	if($ext == 'swf'){ $dtype = 'SWF'; }
    	if($ext == 'fla'){ $dtype = 'FLA'; }
    	if(preg_match('/flv|f4v|f4p|f4a|f4b/i', $ext)){ $dtype = 'Flash Video (FLV)'; }
    
    	if($ext == 'wav'){ $dtype = 'WAV'; }
    	if($ext == 'mp2'){ $dtype = 'MP2'; }
    	if($ext == 'mp3'){ $dtype = 'MP3'; }
    	if($ext == 'mp4'){ $dtype = 'MP4'; }
    	if(preg_match('/ogv|oga|ogx|ogg/i', $ext)){ $dtype = 'Ogg'; }
    	if($ext == 'mid'){ $dtype = 'MID'; }
    	if($ext == 'midi'){ $dtype = 'MIDI'; }
    	if($ext == 'mmf'){ $dtype = 'MMF'; }
    
    	if($ext == 'mpeg'){ $dtype = 'MPEG'; }
    	if($ext == 'mpe'){ $dtype = 'MPE'; }
    	if($ext == 'mpg'){ $dtype = 'MPG'; }
    	if($ext == 'mpa'){ $dtype = 'MPA'; }
    	if($ext == 'avi'){ $dtype = 'AVI'; }
    	if($ext == 'mpga'){ $dtype = 'MPGA'; }
    
    	if(preg_match('/pdf|pds/i', $ext)){ $dtype = 'Документ Adobe PDF'; }
    	if(preg_match('/xls|xl|xla|xlb|xlc|xld|xlk|xll|xlm|xlt|xlv|xlw/i', $ext)){ $dtype = 'Документ MS-Excel'; }
    	if(preg_match('/doc|dot|wiz|wzs|docx/i', $ext)){ $dtype = 'Документ MS-Word'; }
    	if($ext == 'odt'){ $dtype = 'Текстовый документ OpenDocument'; }
    	if($ext == 'odg'){ $dtype = 'Графический документ OpenDocument'; }
    	if($ext == 'odp'){ $dtype = 'Документ презентации OpenDocument'; }
    	if($ext == 'ods'){ $dtype = 'Электронная таблица OpenDocument'; }
    	if($ext == 'odc'){ $dtype = 'Документ диаграммы OpenDocument'; }
    	if($ext == 'odi'){ $dtype = 'Документ изображения OpenDocument'; }
    	if($ext == 'odf'){ $dtype = 'Документ формулы OpenDocument'; }
    	if($ext == 'odm'){ $dtype = 'Составной текстовый документ OpenDocument'; }
    	if(preg_match('/pot|ppa|pps|ppt|pwz/i', $ext)){ $dtype = 'Документ MS-Powerpoint'; }
    	if($ext == 'rtf'){ $dtype = 'RTF'; }
    	if(empty($dtype)) $dtype = '';
    
    	return $dtype;
    }

    Цикл "Из одной русской CMS". База описаний к расширениям файлов.

    Мартин, 27 Января 2011

    Комментарии (10)
  4. 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)
  5. PHP / Говнокод #5392

    +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
    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
    /**
         * Разбор результата в нужном формате
         *
         * @param  mysqli_result $result результат
         * @param  string        $fetch  формат
         * @return mixed
         */
        public function fetch($result, $fetch) {
            $fetch = strToLower($fetch);
            if ((!$fetch) || ($fetch == 'no')) {
                return $result;
            }
            if ($fetch == 'id') {
                return $this->insert_id;
            }
            if ($fetch == 'ar') {
                return $this->affected_rows;
            }
            $numRows = $result->num_rows;
            if ($fetch == 'num') {
                return $numRows;
            }
            if ($fetch == 'row') {
                $A = Array();
                for ($i = 0; $i < $numRows; $i++) {
                    $A[] = $result->fetch_row();
                }
                return $A;
            }
            if ($fetch == 'assoc') {
                $A = Array();
                for ($i = 0; $i < $numRows; $i++) {
                    $A[] = $result->fetch_assoc();
                }
                return $A;
            }
            if ($fetch == 'col') {
                $A = Array();
                for ($i = 0; $i < $numRows; $i++) {
                    $r = $result->fetch_row();
                    $A[] = $r[0];
                }
                return $A;
            }
            if ($fetch == 'object') {
            	$A = Array();
            	for ($i = 0; $i < $numRows; $i++) {
            		$A[] = $result->fetch_object();        		
            	}
            	return $A;
            }
            if ($fetch == 'vars') {
            	$A = Array();
            	for ($i = 0; $i < $numRows; $i++) {
            		$r = $result->fetch_row();
            		$A[$r[0]] = $r[1];
            	}
            	return $A;
            }
            if ($fetch == 'irow') {
                return new goDBResultRow($result);
            }
            if ($fetch == 'iassoc') {
                return new goDBResultAssoc($result);
            }
            if ($fetch == 'icol') {
                return new goDBResultCol($result);
            }
            if ($fetch == 'iobject') {
                return new goDBResultObject($result);
            }        
            if ($numRows == 0) {
                if (!in_array($fetch, array('rowrow', 'rowassoc', 'rowobject', 'el'))) {
                    throw new goDBExceptionFetch($fetch);
                }
                return false;
            }
            if ($fetch == 'rowrow') {
                return $result->fetch_row();
            }
            if ($fetch == 'rowassoc') {
                return $result->fetch_assoc();
            }
            if ($fetch == 'rowobject') {
                return $result->fetch_object();
            }        
            if ($fetch == 'el') {
                $r = $result->fetch_row();
                return $r[0];
            }
            throw new goDBExceptionFetch($fetch);
        }

    http://www.php.ru/forum/viewtopic.php?p=259972

    Devzirom, 25 Января 2011

    Комментарии (10)
  6. 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)
  7. C++ / Говнокод #5375

    +163

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    CTvoid cSG5Exception::Get (CTstatus& Status,
                               CTsymbol& Error,
                               CTsymbol& SubError,
                               string& Description)
    {
       if (Description.c_str() != NULL) {
           Description = m_description;
       }
       Status = m_status;
       Error = m_error;
       SubError = m_subError;
    }

    итолианский с++ панимаш, рагацци.
    что они хотели в строках 6-8 сказать кануло в лету.
    и вместо 4 человеческих геттеров один бесполезный заху*чили. (бесполезный тем что четыре переменные всегда надо под рукой иметь.)

    Dummy00001, 24 Января 2011

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

    +75

    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
    class AboutProgram extends Frame{
    	
    	AboutProgram(String s){
    		super(s);
    		setBounds(50,50,420,420);
    		setVisible(true);
    		setLayout(null);
    		addWindowListener(new WindowAdapter(){
    			public void windowClosing(WindowEvent ev){
    				dispose();
    			}
    		});
    	}
    	@Override
    	public void paint(Graphics g){
    		g.setFont(new Font("Times New Roman",Font.BOLD,30));
    		g.setColor(new Color(200,10,100));
    		g.drawString("Java-сапёр\n",150,50);
    		g.setColor(Color.blue);
    		g.setFont(new Font("Serif", Font.ITALIC | Font.BOLD, 15)); 
    		g.drawString("Автор \t  div#[email protected]\n",20,100);
    		g.drawString("Период написания demo version \t 29.10.2005 - 04.11.2005",20,120);
    		g.drawString("Правила игры \n ",20,140);
    		g.drawString("Вы должны пометить все мины флажками \n ",40,160);
    		g.drawString("Флажок ставится правой кнопкой мыши\n ",40,180);
    		g.drawString("Открыть отдельное поле можно левой кнопкой мыши\n ",40,200);
    		g.drawString("Если поле пустое, то открываются все\n ",40,220);
    		g.drawString("соседние поля, в которых нет мин\n ",40,240);
    		g.drawString("Цифра в отдельном поле означает, что\n ",40,260);
    		g.drawString("в соседних клетках соответствующее число мин\n ",40,280);
    		g.drawString("Игра заканчивается, если\n ",20,300);
    		g.drawString("1) Все мины помечены флажками\n ",40,320);
    		g.drawString("2) Вы наткнулись на мину!\n ",40,340);
    		g.setColor(Color.red);
    		g.drawString("Помните!\n ",20,360);
    		g.setColor(Color.blue);
    		g.drawString("Сапёр ошибается только один раз!\n ",40,380);
    	}  
    }

    Ну и о программе "избитого" сапера.

    dwinner, 18 Января 2011

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

    +120

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    public static string GetRedirectUrl(string userName, bool createPersistentCookie)
    {
        if (userName == null)
        {
            return null;
        }
        return GetReturnUrl(true);
    }

    из рефлектора, класс FormsAuthentication
    ахеренная роль у параметров userName и createPersistentCookie

    Semargl, 13 Января 2011

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

    +34

    1. 1
    2. 2
    foreach($keys as $key) 
         $settings[$type][$fieldname][$key] =  (isset($fl[$type] [$fieldname] ['widget'] [$key] ) ) ? $fl[$type] [$fieldname] ['widget'] [$key] : '';

    вобля

    brainstorm, 08 Января 2011

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

    +145

    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
    /********************************************************************************
    ** Form generated from reading UI file 'qrselector.ui'
    **
    ** Created: Thu 6. Jan 14:25:49 2011
    **      by: Qt User Interface Compiler version 4.7.0
    **
    ** WARNING! All changes made in this file will be lost when recompiling UI file!
    ********************************************************************************/
    
    #ifndef UI_QRSELECTOR_H
    #define UI_QRSELECTOR_H
    
    #include <QtCore/QVariant>
    #include <QtGui/QAction>
    #include <QtGui/QApplication>
    #include <QtGui/QButtonGroup>
    #include <QtGui/QHeaderView>
    #include <QtGui/QLabel>
    #include <QtGui/QWidget>
    
    QT_BEGIN_NAMESPACE
    
    class Ui_QRSelector
    {
    public:
        QLabel *label;
    
        void setupUi(QWidget *QRSelector)
        {
            if (QRSelector->objectName().isEmpty())
                QRSelector->setObjectName(QString::fromUtf8("QRSelector"));
            QRSelector->resize(400, 300);
            label = new QLabel(QRSelector);
            label->setObjectName(QString::fromUtf8("label"));
            label->setGeometry(QRect(10, 10, 371, 16));
    
            retranslateUi(QRSelector);
    
            QMetaObject::connectSlotsByName(QRSelector);
        } // setupUi
    
        void retranslateUi(QWidget *QRSelector)
        {
            QRSelector->setWindowTitle(QApplication::translate("QRSelector", "QRSelector", 0, QApplication::UnicodeUTF8));
            label->setText(QString());
        } // retranslateUi
    
    };
    
    namespace Ui {
        class QRSelector: public Ui_QRSelector {};
    } // namespace Ui
    
    QT_END_NAMESPACE
    
    #endif // UI_QRSELECTOR_H

    ui_qrselector.h

    Resager, 06 Января 2011

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