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

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

    +144

    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
    function order_to() {
        jQuery.ajax({
            type: "POST",
            url: url+'/saveMethod/',
            data: {
                "method": "guest"
            },
            success: function(success) {
                console.log(success);
                jQuery.ajax({
                    type: "POST",
                    url: url+'/saveBilling/',
                    data: {
                        "billing[address_id]": "",
                        "billing[firstname]": "Test",
                        "billing[lastname]": "Query",
                        "billing[company]": "",
                        "billing[email]": "[email protected]",
                        "billing[street][]": "Street",
                        "billing[city]": "City",
                        "billing[region_id]": "",
                        "billing[region]": "",
                        "billing[postcode]": "50",
                        "billing[country_id]": "UA",
                        "billing[telephone]": "+100500",
                        "billing[fax]": "",
                        "billing[customer_password]": "",
                        "billing[confirm_password]": "",
                        "billing[save_in_address_book]": "1",
                        "billing[use_for_shipping]": "1"
                    },
                    success: function(success) {
                        console.log(success);
                        jQuery.ajax({
                            type: "POST",
                            url: url+'/saveShippingMethod/',
                            data: {
                                "shipping_method": "flatrate_flatrate"
                            },
                            success: function(success) {
                                console.log(success);
                                jQuery.ajax({
                                    type: "POST",
                                    url: url+'/savePayment/',
                                    data: {
                                        "payment[method]": "checkmo"
                                    },
                                    success: function(success) {
                                        console.log(success);
                                        var reg = /\/form_key\/(.*?)\/\'\)/;
                                        var raw = jQuery('button.button.btn-cart').attr('onclick');
                                        if (raw == undefined) {
                                            key_form = jQuery('form input[name=form_key]').val();
                                        } else {
                                            var key_form = reg.exec(raw)[1];
                                        };
                                        console.log(key_form);
    
                                        jQuery.ajax({
                                            type: "POST",
                                            url: url+'/saveOrder/form_key/' + key_form + '/',
                                            data: {
                                                "payment[method]": "checkmo"
                                            },
                                            success: function(success) {
                                                console.log(success);
                                            }
                                        });
                                    }
                                });
                            }
                        });
                    }
                });
            }
        });
    }
    order_to();
    order_to();

    Каскадный запрос на jQuery на подтверждение заказа в Magento загнан в функцию и вызывается два раза, потому что с первого не проходит. А еще в одном блоке токен получается из артибута узла через регулярку...

    stail, 16 Мая 2015

    Комментарии (19)
  3. Java / Говнокод #18175

    +144

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    private static class NoNullListMap<KEY, VALUES> extends HashMap<KEY, List<VALUES>> {
            @Override
            public List<VALUES> get(Object key) {
                List<VALUES> res = super.get(key);
                if (res == null) {
                    res = new ArrayList();
                    super.put((KEY) key, res);
                }
                return res;
            }
        }

    мапа, возвращающая пустые списки вместо null

    olegsemeniuk, 15 Мая 2015

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

    +144

    1. 1
    $orig_id = isset($_POST["orig_id"]) ? (int) $_POST["orig_id"] : (int) $_GET["orig_id"];

    https://github.com/uisky/notabenoid/blob/6edfee9f33b8466be9164cd3ba6be90b8f3a5770/protected/controllers/MyCommentsController.php#L123

    Stallman, 14 Мая 2015

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

    +144

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    catch (Exception ex)
                {
                    status = ex.Message;
                    throw ex;
                }

    zhilinskyegor, 07 Мая 2015

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

    +144

    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
    public string[] razborstroki(string str)
            {
                string[] array = new string[100];
                int j = 0;
                for (int i = 0; i < str.Length; i++)
                {
                    if (str[i] != ';')
                        array[j] += str[i];
                    else
                        j++;
                }
                return array;
            }

    Обнаружил недавно в одном из переданных нам проектов. Правильно, у нас будет свой split с маджонгом и гейшами!!!!

    flea3m, 05 Мая 2015

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

    +144

    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
    <?php
    
    $startNumber = 0;
    
    function LittlePart($BigPart, $startNumber) {
      $i = -3;
      $number = $startNumber * M_PI + ($i - 1);
      do {
        $number += M_PI;
        echo $BigPart . ' + (' . $i . ') = ' . number_format($number, 2, ',', ' ') . PHP_EOL;
        $i++;
      } while ($i <= 3);
    }
    
    
    function MidPart($BigPart, $startNumber) {
      $i = -3;
      $number = $startNumber * M_PI + ($i - 1);
      do {
        $number += M_PI;
        LittlePart ($BigPart . ' + (' . $i . ')·π', $number);
        $i++;
      } while ($i <= 3);
    }
    
    
    function QuadradPart($BigPart, $startNumber) {
      $i = -3;
      $number = $startNumber * M_PI + ($i - 1);
      do {
        $number += M_PI;
        MidPart ($BigPart . ' + (' . $i . ')·π²', $number);
        $i++;
      } while ($i <= 3);
    }
    
    function CubePart($BigPart, $startNumber) {
      $i = -3;
      $number = $startNumber * M_PI + ($i - 1);
      do {
        $number += M_PI;
        QuadradPart ($BigPart . '(' . $i . ')·π³', $number);
        $i++;
      } while ($i <= 3);
    }
    
    
    CubePart('', 0);

    Система счисления по основанию π. Пока с целыми числами.

    http://ideone.com/EUYEKA

    inkanus-gray, 03 Мая 2015

    Комментарии (24)
  8. JavaScript / Говнокод #18105

    +144

    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
    class Select
      constructor: ->
        Select = this
    
    
    ###
    
    var Select;
    
    Select = (function() {
      function Select() {
        Select = this;
      }
    
      return Select;
    
    })();

    код на coffeescript. до сих пор годаю - зачем?

    frozfox, 01 Мая 2015

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

    +144

    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
    function Calculation(a, b, op){
        if (typeof a == "number" && typeof (b) == "number"){
            var result;
            +a; +b;
            if (op == "+")  { result = a+b; alert(result);
            } else if (op == "-") { result = a-b; alert(result);
            } else if (op == "*"){ result = a*b; alert(result);
            } else if (op == "/"){
                if (b!=0){ 
                    result = a/b; alert(result);
                } else {
                    alert("Can`t divide on zero!");
                }
            }
        } else if (a instanceof Array && b instanceof Array) {
            var result = [];
            if ( a.length >= b.length ){
                length = a.length;
                for (var i=0; i < length; i++){
                    a[i] = parseFloat(a[i]);
                    b[i] = parseFloat(b[i]);
                    if (i < b.length-1){
                        if (op == "+"){ result[i] = a[i]+b[i];
                        } else if (op == "-"){ result[i] = a[i]-b[i];
                        } else if (op == "*"){ result[i] = a[i]*b[i];
                        } else if (op == "/"){
                            if (b[i]!=0){
                                result[i] = a[i]/b[i];
                            } else {
                                alert("Can`t divide on zero!");
                            }
                        }
                    } else {
                        result[i] = a[i];
                    }
                } 
                alert(result.join("  |  "));
            } else {
                length = b.length;
                for (var i=0; i < length; i++){
                    +a[i]; +b[i];
                    if (i < a.length-1){
                        switch (op){
                            case "+":
                                result[i] = a[i]+b[i];
                                break;
                            case "-":
                                result[i] = a[i]+b[i];
                                break;
                            case "*":
                                result[i] = a[i]+b[i];
                                break;
                            case "/":
                                if (b[i]!=0){
                                    result[i] = a[i]/b[i];
                                } else {
                                    alert("Can`t divide on zero!");
                                }
                                break;
                        }
                    } else {
                        result[i] = a[i];
                    }
                } 
                alert(result.join("  |  "));
            }
        } else if (a instanceof Object && b instanceof Object) {
            var tempObject = {};
                switch (op){
                    case "+":
                        tempObject.resultA = a.a+b.a;
                        tempObject.resultB = a.b+b.b;
                        break;
                    case "-":
                        tempObject.resultA = a.a+b.a;
                        tempObject.resultB = a.b+b.b;
                        break;
                    case "*":
                        tempObject.resultA = a.a+b.a;
                        tempObject.resultB = a.b+b.b;
                        break;
                    case "/":
                        if (b.b !=0 || b.a != 0){
                            tempObject.resultA = a.a+b.a;
                            tempObject.resultB = a.b+b.b;
                        } else {
                            alert("Can`t divide on zero!");
                        }
                        break;
                }
                
                alert(tempObject.resultA + " " + tempObject.resultB);
        }
    }

    Вот такой вот калькулятор!

    alexhelkar, 30 Апреля 2015

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

    +144

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    if(!$this->_login()){
                
                sleep(mt_rand(60, 90));
                $this->_reLogin();
                return;
    }

    Такое чудо мне передали от другой команды разработчиков

    Granes, 30 Апреля 2015

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

    +144

    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
    cs_zagl.Edit;
          cs_zagl.fieldbyname('count_z').asinteger:=cs_tab.RecordCount;
          cs_zagl.Post;
    
    cs_mk.Edit;
    cs_mk.FieldByName('med_kart_id').Asinteger:=select_row_Form.ClientDataSet1.FieldByName('id_kart').asinteger;
    cs_mk.FieldByName('id_kart_public').Asinteger:=select_row_Form.ClientDataSet1.FieldByName('id_kart_public').asinteger;
    cs_mk.FieldByName('id_pac').Asinteger:=select_row_Form.ClientDataSet1.FieldByName('id_pac').asinteger;
    cs_mk.FieldByName('type_kart').asinteger:=select_row_Form.ClientDataSet1.FieldByName('type_kart').asinteger;
    cs_mk.post;
    
    
          IF (cs_mk.FieldByName('med_kart_id').Value=0) or (cs_mk.FieldByName('type_kart').asinteger<>27) then begin
          cmd := VarArrayCreate([0,20],varVariant);
          cmd[1] := 6832;
          cmd[2] := 17;
          cmd[5] := 1;
          cmd[6] := 0;
          ProvOptions := [grMetadata, grReset];
          cmd[7] := dsp_mk.GetRecords(-1, RecsOut, Byte(ProvOptions));
    
    
      try
    
        rez := MainFormInterface.EXT_call_server('spr_read', cmd);
        cs_tab.Edit;
        cs_tab.FieldByName('med_kart_id').Asinteger:=rez[3];
        cs_tab.Post;
    
    
    
        if rez[1] < 0 then begin
          debug_sql('Ошибка: ' + varastype(rez[1], varstring), 2);
          MessageDlg('Ошибка: '+ #10 + #13 +
                     varastype(rez[1],varstring),mtError,[mbok],0);
          Exit;
        end;
    
    
       except
        on e:exception do
        begin
          MessageDlg(ERROR_MESS_5 + 'Исключение:' + E.ClassName + 'Mess:' + E.Message, mterror, [mbok], 0);
          debug_sql('Ошибка записи документа!', 2);
          debug_all('Err при записи документа тип=' + varastype(cmd[1], varstring)+
                   ' id=' + inttostr(id_doc) + 'Исключение:' + E.ClassName + 'Mess:' + E.Message,2);
    
        end;
      end;
    
    
    
    
    
          end;
          end else begin
    
          
    
    
          end;
          end
          else exit;
    
    
       end else
         begin
        id_pac:=rez[3];
        id_med_kart:=rez[2];
        Application.MessageBox(pchar('Ошибка: '+#10+#13+
               'Даный пациент не найден!!!'),pchar(application_title_short),MB_OK+MB_ICONERROR);
        exit;
        end;
    
    end;

    Это называется стиль

    tucvbif, 29 Апреля 2015

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