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

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

    +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
    public function getProductAttributes($product_id) {
    	$product_attribute_data = array();
    
    	$product_attribute_query = $this->db->query("SELECT attribute_id FROM " . DB_PREFIX . "product_attribute WHERE product_id = '" . (int)$product_id . "' GROUP BY attribute_id");
    
    	foreach ($product_attribute_query->rows as $product_attribute) {
    		$product_attribute_description_data = array();
    
    		$product_attribute_description_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_attribute WHERE product_id = '" . (int)$product_id . "' AND attribute_id = '" . (int)$product_attribute['attribute_id'] . "'");
    
    		foreach ($product_attribute_description_query->rows as $product_attribute_description) {
    			$product_attribute_description_data[$product_attribute_description['language_id']] = array('text' => $product_attribute_description['text']);
    		}
    
    		$product_attribute_data[] = array(
    			'attribute_id'                  => $product_attribute['attribute_id'],
    			'product_attribute_description' => $product_attribute_description_data
    		);
    	}
    
    	return $product_attribute_data;
    }

    Opencart -> ModelCatalogProduct -> getProductAttributes
    Первым запросом в БД они берут IDы атрибутов, перебирают их циклом, в котором другим запросом берут всё, в том числе и те же IDы, из той же таблицы и снова перебирают строки циклом.

    technobulka, 25 Марта 2015

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

    +127

    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
    INDEX.HTML
    
        {% extends "style_body.html" %}
        {% block head %}
        <meta charset="UTF-8">
        {% endblock %}
    {% block body %}
    <h1 align="center">Звіт по витратах</h1>
    
    <table align="center">';
    {% for item in payments['list'] %}
        <tr><td>{{ item['data']}}</td>
            <td>{{item['summa']}}</td>
            <td>{{item['id']}}</td>
            <td><button  onclick="window.location.href='index.php?id={{item['id']}}&go=delete'"><img src="del.gif" alt="Del"style="vertical-align: middle">  </button></td></tr>
    {% endfor %}
    
    </table>
    </br></br></br>
    <table align="center"><tr><td><button   onclick="window.location.href='index.php?go=addData'">
        <img src="add.png" alt="Add" style="vertical-align: middle">Додати новий запис </button></td></tr></table>
    {% endblock %}
    
    
    FORM.HTML
    {% extends "style_body.html" %}
    
        {% block title %}
    
        {% endblock %}
        {% block head %}
    
        {% endblock %}
    
    {% block body %}
    <form name="test" method="post" action="index.php">
    
       <p align="center"><b>Введіть дату в форматі гггг-мм-дд:</b></br>
           <input type="hidden" name="go" value="add" >
           <input type="text" size="40" name="data" align="center" ></br>
    
           <b align="center">Введіть витрачену сумму:</b></br>
           <input type="text" size="40" name="summa" align="center"></br>
           </p>
    
       <p align="center"><input type="submit" value="Додати запис">
          <input type="reset" value="Очистити"></p>';
       </form>';
    {% endblock %}
    
    STYLE_BODY.HTML
    <!DOCTYPE html>
    <html>
    <head >
        {% block head %}
    
        <title>{% block title %}{% endblock %} - My Webpage</title>
        {% endblock %}
    </head>
    <body background="money.jpg">
    {% block body %}{% endblock %}
    </div>
    </body>
    </html>

    vityapro, 24 Марта 2015

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

    +159

    1. 1
    $this->vars['cookie_domain'] = $this->vars['cookie_domain'] == "" ? ""  : $this->vars['cookie_domain'];

    Из IPB от 2007 года, по следам индусского неизвестного классика.

    Если cookie_domain = "", то пусть будет "", а если нет, то и хуй с ним, пусть остается как есть.

    adoconnection, 21 Марта 2015

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

    +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
    eps=0.001;
    
    s1=new Source(1000,0.17);
    mx=new Mixer(1000);
    mb=new Mem(0.15,0.95);
    sp=new Splitter(0.80);
    s2=new Sink();
    s3=new Sink();
    
    mx.in1=s1.out1;
    mx.in2=sp.out2;
    mb.in1=mx.out1;
    sp.in1=mb.out2;
    s3.in1=sp.out1;
    s2.in1=mb.out1;
    
    for (i=0;i<50;i++){
        mx.calc();
        mb.calc();
        sp.calc();
    }
    
    function Stream(v,c){
        this.v=v||null;
        this.c=c||null;
        this.selfCheck=false;
        this.Show=function(){//how to add default values?
            return "volume="+this.v+",conc="+this.c+",selfCheck:"+this.selfCheck+"; ";
        }
    }
    
    function Source(v,c){
        this.out1=new Stream(v,c);
        this.calc=function(){};
    }
    function Sink(){
        this.in1=null;
        this.calc=function(){};
    }
    
    function Mixer(fixedV){
        this.fv=fixedV;
        this.in1=null;
        this.in2=null;
        this.out1=new Stream();
        this.calc=function(){
            this.out1.v=this.fv;//||this.in1.v+this.in2.v;
            this.in2.v=this.in2.v||0;
            this.in2.c=this.in2.c||0;
            this.in1.v=this.out1.v-this.in2.v;
            this.out1.c =(this.in1.v*this.in1.c+this.in2.v*this.in2.c)/this.out1.v;
            this.out1.selfCheck=Math.abs
            ((this.in1.v*this.in1.c+this.in2.v*this.in2.c)-(this.out1.v*this.out1.c))<eps;
        }
    }
    
    function Splitter(kS){
        this.in1=null;
        this.ks=kS||0.05;
        this.out1=new Stream();
        this.out2=new Stream();
        this.calc=function(){
            this.out1.v=this.in1.v*(1-this.ks);
            this.out2.v=this.in1.v*(this.ks);
            this.out1.c=this.in1.c;
            this.out2.c=this.in1.c;
        }
    
    }
    
    function Mem(kV,kC) {
        this.kv = kV||0.15;
        this.kc = kC||0.95;
        this.in1 = null;
        this.out1 = new Stream();
        this.out2 = new Stream();
        this.calc = function () {
            this.out1.v = this.in1.v * this.kv;
            this.out1.c = this.in1.c * (1 - this.kc);
            this.out2.v = this.in1.v * (1 - this.kv);
            this.out2.c = (this.in1.v * this.in1.c - this.out1.v * this.out1.c) / this.out2.v;
            this.out1.selfCheck = this.out2.selfCheck = Math.abs
            (this.in1.v * this.in1.c - (this.out1.v * this.out1.c + this.out2.v * this.out2.c)) < eps;
    
        }
    }

    xtfkpi, 16 Марта 2015

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

    +156

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    for ($i=1;$i<=10;$i++) { 
    		  if(isset(${"imagenum".$i})) {
                         ....
                     }
    }

    И такое бывало

    sikamikanico, 15 Марта 2015

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

    +120

    1. 1
    http://www.businessinsider.com/the-russian-internet-thinks-putin-is-dead-2015-3

    политота

    LispGovno, 13 Марта 2015

    Комментарии (3)
  8. Python / Говнокод #17763

    −109

    1. 1
    result['first'] = False if page != 1 else True

    Неплохое такое выражение

    python_ninja, 11 Марта 2015

    Комментарии (3)
  9. Си / Говнокод #17754

    +135

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    int overflow(const char *str)
    {
        char buf[9000];
        int res = atoi(buf);
        itoa(res, buf, 10);
        return strcmp(buf, str);
    }

    По мотивам #17745.

    gost, 09 Марта 2015

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

    +157

    1. 1
    2. 2
    var DayOfWeekToday = (new Date(item.datapoint[0])).getDay();
    var DayOfWeekTomorrow = new Date(((new Date(item.datapoint[0])).getDate()) + 1).getDay();

    var DayOfWeekToday = (new Date(item.datapoint[0])).getDay();
    var DayOfWeekTomorrow = (DayOfWeekToday + 1 ) % 7;

    trapeznikov-ap, 25 Февраля 2015

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

    +51

    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
    while (w.pollEvent(event)) {
        if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Period)) {
            ip += ".";
        }
        if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Num0)) {
            ip += "0";
        }
        if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Num1)) {
            ip += "1";
        }
        if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Num2)) {
            ip += "2";
        }
        if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Num3)) {
            ip += "3";
        }
        if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Num4)) {
            ip += "4";
        }
        if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Num5)) {
            ip += "5";
        }
        if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Num6)) {
            ip += "6";
        }
        if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Num7)) {
            ip += "7";
        }
        if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Num8)) {
            ip += "8";
        }
        if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Num9)) {
            ip += "9";
        }
        if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::BackSpace) && ip.length() > 0) {
            ip.erase(ip.end() - 1, ip.end());
        }
        if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Return)) {
            if (validateIp(ip)) {
                Text c("Connection...", f);
                c.setColor(Color::Black);
                c.setPosition(100, 20);
                w.draw(c);
                w.display();
                return ip;
            } else {
                ip.erase(ip.begin(), ip.end());
                wrongAnswer = true;
            }
        }
        if (event.type == Event::Closed) {
            w.close();
            return 0;
        }
    }

    Ввод IP-адреса в интерфейсе игры

    lukaville, 17 Февраля 2015

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