1. Java / Говнокод #5636

    +80

    1. 1
    boolean isTrue = false;

    kuku, 11 Февраля 2011

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

    +154

    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
    // Parse strings looking for color tuples [255,255,255]
    function getRGB(color) {
      var result;
      if (color && isArray(color) && color.length == 3)
        return color;
      if (result = /rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(color))
        return [parseInt(result[1]), parseInt(result[2]), parseInt(result[3])];
      if (result = /rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(color))
        return [parseFloat(result[1])*2.55, parseFloat(result[2])*2.55, parseFloat(result[3])*2.55];
      if (result = /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(color))
        return [parseInt(result[1],16), parseInt(result[2],16), parseInt(result[3],16)];
      if (result = /#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(color))
        return [parseInt(result[1]+result[1],16), parseInt(result[2]+result[2],16), parseInt(result[3]+result[3],16)];
    }

    InstantI, 11 Февраля 2011

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

    +157

    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
    function getAvailablePrivileges(Workset_Model_Object_Interface $resource, $where = null, $order = null, $limit = null, $offset = null, $offsetByPage = false) {
    
            if (true == $offsetByPage) {
                $offset = $this->getPageOffset($limit, $offset);
            }
    
    	$table = $this->_getTable();
    	$select = $table->prepareSelect($where, $order, $limit, $offset);
    
            $iselect = $this->_getTable()->select();
    
            $iselect->from(
                array('m' => $this->_getTable()->info(Zend_Db_Table_Abstract::NAME)),
                array('id')
            )
           ->join(
                array('i' => $this->_getTable($this->_linkedObjectTableClass)->info(Zend_Db_Table_Abstract::NAME)),
                "i.privilege_id = m.id",
                array()
            )
            ->where(
                'i.resource_id = ?', $resource->getId()
            );
    
            $select->where("id not in(?)", new Zend_Db_Expr($iselect->assemble()));
    
            $rowset = $table->fetchAll($select);
    
            return $this->getIterator($rowset, array(
                'countRows' => $this->_countAllRecords,
                'filter' => $select
            ));
    
        }

    Из проекта на Zend

    govnomes, 11 Февраля 2011

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

    +71

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    class CellEditor {
    
       protected CellEditor(Composite parent, int style) {
    	this.style = style;
    	create(parent);
       }
    
       public void create(Composite parent) { ... }
    
    }

    А вот это уже JFace...
    5 строка подарил много положительных эмоций, при попытке сконструировать кастомный CellEditor

    tir, 11 Февраля 2011

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

    +87

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    class PartStack {
        ...
        if (children[i] instanceof EditorSashContainer && !(this instanceof EditorStack)) {
            ...
        }
        ...
    }
    
    class EditorStack extends PartStack { ... }

    интересно смотрится сторка номер 3

    исходники Eclipse

    tir, 11 Февраля 2011

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

    +165

    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
    enum TextAlignment
    {
    	ALIGN_LEFT = 0,
    	ALIGN_RIGHT,
    	ALIGN_CENTER
    };
    
    ...
    
    if(m_textAlignment > 0 && maxLineWidth < m_desiredLength)
    {
    	float offsetx = (m_desiredLength - maxLineWidth) / m_textAlignment;
    	...
    }

    Выравниваем текст. Универсальненько.
    Что будет, если значения в энумке поменяются или добавится, к примеру, justify, никого не волнует.

    Kirinyale, 11 Февраля 2011

    Комментарии (54)
  7. PHP / Говнокод #5630

    +157

    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
    if($amount > 0) :
    	if (is_dir($directory)) {
    		if ($open_dir = opendir($directory)) {
    			$a = 0; $b = 0;
    			while (false !== ($file = readdir($open_dir))) {
    				if ($file != "." && $file != ".." && !is_dir($directory."/".$file)) {
    					$a++;
    					if($a > $min) {
    						$b++;
    						echo "<tr id=\"am-list-input\" valign=\"center\" height: 20px;><td align=\"left\" width=\"10%\">";
    						echo " <a href=\"index.php?am=mod[uploader]&delete=$file\"><img src=\"../images/mini_icons/del.png\" /></a> ";
    						if(in_array(strtolower(getExtension($file)), $gud_types)) echo "<span OnClick=\"CaricaFoto('".$directory."/".$file."')\" OnMouseOver=\"Tip('<img style="max-width: 400px" src="".$directory."/".$file."" >')\"><img style=\"cursor: help\" src=\"../images/mini_icons/display.png\" /></span>";
    						if(in_array(strtolower(getExtension($file)), explode(',', strtolower("mp3,wma,waw,amr,ape,bin,flac,m4a,mdi,ram")))) echo "<img src=\"modules/mod[uploader]/assets/type/sound.png\" />";
    						if(in_array(strtolower(getExtension($file)), explode(',', strtolower("3gp,avi,dat,flv,ifo,m4v,mkv,mov,mp4,rm,vob,wmv")))) echo "<img src=\"modules/mod[uploader]/assets/type/video.png\" />";
    						if(!in_array(strtolower(getExtension($file)), explode(',', strtolower("3gp,avi,dat,flv,ifo,m4v,mkv,mov,mp4,rm,vob,wmv,mp3,wma,waw,amr,ape,bin,flac,m4a,mdi,ram,jpg,jpeg,png,gif")))) echo "<img src=\"modules/mod[uploader]/assets/type/all.png\" />";
    						echo "</td><td width=\"70%\"><span style=\"display: block; cursor: pointer; color: #446eb8; font-weight: bold; line-height: 16px;\" onClick=\"document.getElementById('onclick').value='".str_replace("..", $conf_global["base_url"], $directory)."/".$file."'\" />".substr($file, 0, 100)."</span></td><td width=\"20%\">".formatsize(filesize($directory.DS.$file))."</td></tr>";
    						if($b == $max) : break; endif;
    					}
    				}
    			}
    		closedir($open_dir);
    		}
    	}
    endif;

    Грех не посмеятся над своими старыми проектами =)))

    nethak, 11 Февраля 2011

    Комментарии (28)
  8. Pascal / Говнокод #5629

    +102

    1. 1
    while dlg_SmplSpk.ShowModal = mrOk do ;

    Узрел такое! Срочно к себе в рецепты прогрессивного программирования!
    Сделано это для того, чтобы окно не закрывалось при подтверждении всех сделанных действий.
    Закрываться должно только при нажатии кнопочки "Закрыть".
    Отсюда непонятен ход мыслей автора сия творения.

    Grizzly, 11 Февраля 2011

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

    −364

    1. 1
    Если (ДатаГод(ДатаДок) < 2010) ИЛИ (ДатаГод(ДатаДок) < 2010 ) Тогда

    Строка кода из типовой конфигурации 1С: Бухгалтерия 7.7, релиз 522
    No comments ...

    manan, 10 Февраля 2011

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

    +124

    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
    ;;;; -*- Mode: lisp; indent-tabs-mode: nil -*-
    
    ;;; Copyright (C) 2011, Dmitry Ignatiev <[email protected]>
    
    ;;; Permission is hereby granted, free of charge, to any person
    ;;; obtaining a copy of this software and associated documentation
    ;;; files (the "Software"), to deal in the Software without
    ;;; restriction, including without limitation the rights to use, copy,
    ;;; modify, merge, publish, distribute, sublicense, and/or sell copies
    ;;; of the Software, and to permit persons to whom the Software is
    ;;; furnished to do so, subject to the following conditions:
    
    ;;; The above copyright notice and this permission notice shall be
    ;;; included in all copies or substantial portions of the Software.
    
    ;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    ;;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    ;;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
    ;;; NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
    ;;; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
    ;;; WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    ;;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
    ;;; DEALINGS IN THE SOFTWARE
    
    (in-package #:neural-flow)
    
    ;; Stolen from `trivial-garbage'
    
    #+openmcl
    (defvar *weak-pointers* (cl:make-hash-table :test 'eq :weak :value))
    
    #+(or allegro openmcl lispworks)
    (defstruct (weak-pointer (:constructor %make-weak-pointer))
      #-openmcl pointer)
    
    (declaim (inline make-weak-pointer))
    (defun make-weak-pointer (object)
      #+sbcl (sb-ext:make-weak-pointer object)
      #+(or cmu scl) (ext:make-weak-pointer object)
      #+clisp (ext:make-weak-pointer object)
      #+ecl (ext:make-weak-pointer object)
      #+allegro
      (let ((wv (excl:weak-vector 1)))
        (setf (svref wv 0) object)
        (%make-weak-pointer :pointer wv))
      #+openmcl
      (let ((wp (%make-weak-pointer)))
        (setf (gethash wp *weak-pointers*) object)
        wp)
      #+corman (ccl:make-weak-pointer object)
      #+lispworks
      (let ((array (make-array 1)))
        (hcl:set-array-weak array t)
        (setf (svref array 0) object)
        (%make-weak-pointer :pointer array)))
    
    (declaim (inline weak-pointer-value))
    (defun weak-pointer-value (weak-pointer)
      "If WEAK-POINTER is valid, returns its value. Otherwise, returns NIL."
      #+sbcl (values (sb-ext:weak-pointer-value weak-pointer))
      #+(or cmu scl) (values (ext:weak-pointer-value weak-pointer))
      #+clisp (values (ext:weak-pointer-value weak-pointer))
      #+ecl (values (ext:weak-pointer-value weak-pointer))
      #+allegro (svref (weak-pointer-pointer weak-pointer) 0)
      #+openmcl (values (gethash weak-pointer *weak-pointers*))
      #+corman (ccl:weak-pointer-obj weak-pointer)
      #+lispworks (svref (weak-pointer-pointer weak-pointer) 0))
    
    ;;Red-black tree
    
    (declaim (inline %node %nleft %nright %nparent %nred %ndata %ncode
                     (setf %nleft) (setf %nright) (setf %nparent)
                     (setf %nred) (setf %ndata) (setf %ncode)))
    (defstruct (%node (:constructor %node (data code parent red))
                      (:conc-name %n))
      (left nil :type (or null %node))
      (right nil :type (or null %node))
      (parent nil :type (or null %node))
      (red nil)
      data
      (code 0 :type (integer 0 #.most-positive-fixnum)))
    
    (declaim (inline %tree %tree-root (setf %tree-root)))
    (defstruct (%tree (:constructor %tree ())
                      (:copier %copy-tree))
      (root nil :type (or null %node)))
    
    (declaim (inline rotate-left))
    (defun %rotate-left (tree node)
      (declare (type %tree tree) (type %node node)
               (optimize (speed 3) (safety 0)))
      (let ((right (%nright node)))
        (when (setf (%nright node) (%nleft right))
          (setf (%nparent (%nleft right)) node))
        (if (setf (%nparent right) (%nparent node))
          (if (eq node (%nleft (%nparent node)))
            (setf (%nleft (%nparent node)) right)
            (setf (%nright (%nparent node)) right))
          (setf (%tree-root tree) right))

    Вылезли глаза! Как на этом можно писать?

    vertexua, 10 Февраля 2011

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