1. JavaScript / Говнокод #15999

    +160

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    var fixGetMoreOrders = function(data){
        var i = 0;
        $.each(data.resultObject, function(k,v){
            i++;
        });
        if(i>=10){
            $('.btnGetOrders').css('display', 'block');
        }
        if(i<10){
            $('.btnGetOrders').css('display', 'none');
        }
    };

    Предыдущему разработчику нужно было посчитать количество ордеров, при том, что поле data['count'] вертается с сервера =)

    makzimko, 16 Мая 2014

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

    +152

    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
    foreach ($line as $cell) { 
        if ($first) {
    	echo "<td id='csv_head' class='td_csv_head" . $i . "'>" 
    	. htmlspecialchars($cell) 
    	. '</br><select class="td_csv_modules' . $i . '" onchange="get_submodules($(\'.td_csv_modules' . $i . '\').val(), ' . $i . ')">' 
    	. $blank_select // </select>
    	. '</br><select class="td_csv_fields' . $i . '"><option value=""></option>'
    	. "</td>";
        } else {
    	echo "<td class='td_csv'>" . htmlspecialchars($cell) . "</td>";
        };
        $i++;
    }

    Нашел в коде коллеги. Кода было много, выкладываю самый вкусный. Момент с id и class у select-ов не опечатка. Подобное всречается абсолютно везде.

    ivanstroilov, 16 Мая 2014

    Комментарии (1)
  3. Objective C / Говнокод #15997

    −397

    1. 1
    NSString *CellIdentifier = [NSString stringWithFormat:@"BFTumblrPostCell%i%i",indexPath.section,indexPath.row];

    nickynick, 16 Мая 2014

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

    +12

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    // Decompress section data
    if (ERR_SUCCESS != LzmaDecompress(data, dataSize, decompressed)) {
        // Intel modified LZMA workaround
        EFI_COMMON_SECTION_HEADER* shittySectionHeader;
        UINT32 shittySectionSize;
        // Shitty compressed section with a section header between COMPRESSED_SECTION_HEADER and LZMA_HEADER
        // We must determine section header size by checking it's type before we can unpack that non-standard compressed section
        shittySectionHeader = (EFI_COMMON_SECTION_HEADER*) data;
        shittySectionSize = sizeOfSectionHeaderOfType(shittySectionHeader->Type);
        // ...

    Oh shit!

    spb-yuriy, 16 Мая 2014

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

    +153

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    <?php foreach ($category_1['children'] as $category_2) { ?>
            <?php if ($category_2['category_id'] == $category_id) { ?>
            <option value="<?php echo $category_2['category_id']; ?>" selected="selected">      <?php echo $category_2['name']; ?></option>
            <?php } else { ?>
            <option value="<?php echo $category_2['category_id']; ?>">      <?php echo $category_2['name']; ?></option>
            <?php } ?>
            <?php foreach ($category_2['children'] as $category_3) { ?>
            <?php if ($category_3['category_id'] == $category_id) { ?>
            <option value="<?php echo $category_3['category_id']; ?>" selected="selected">            <?php echo $category_3['name']; ?></option>
            <?php } else { ?>
            <option value="<?php echo $category_3['category_id']; ?>">            <?php echo $category_3['name']; ?></option>
            <?php } ?>

    Код вида поиска из известной модификации CMS Opencart - Maxystore.

    bestaimer, 15 Мая 2014

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

    +155

    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
    {php}
        $this->_tpl_vars['image_set'] = array();
        $this->_tpl_vars['json_string'] = "";
    {/php}
    
    {if $pcollection}
        {foreach name=pcollection key=picture_id item=picture from=$pcollection}
            {php}
                array_push($this->_tpl_vars['image_set'], "{$this->_tpl_vars['urlprefix']}/thumb.php?file=" . str_replace("thumbs","original","media/pictures/{$this->_tpl_vars['album']->getPath()}/{$this->_tpl_vars['picture']->getPath()}")."&size=245x143");
            {/php}
        {/foreach}
    {/if}
    
    {php}
        $this->_tpl_vars['json_string'] = json_encode($this->_tpl_vars['image_set']);
    {/php}
    {$json_string}

    получение объекта в smarty, потом пара фокусов, и вуаля, выплевываем json строку

    expert, 15 Мая 2014

    Комментарии (2)
  7. Java / Говнокод #15990

    +69

    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
    package com.javarush.test.level06.lesson11.bonus02;
     
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
     
    /* Нужно добавить в программу новую функциональность
    Задача: У каждой кошки есть имя и кошка-мама. Создать класс, который бы описывал данную ситуацию. Создать два объекта: кошку-дочь и кошку-маму. Вывести их на экран.
    Новая задача: У каждой кошки есть имя, кошка-папа и кошка-мама. Изменить класс Cat так, чтобы он мог описать данную ситуацию.
    Создать 6 объектов: маму, папу, сына, дочь, бабушку(мамина мама) и дедушку(папин папа).
    Вывести их всех на экран в порядке: дедушка, бабушка, папа, мама, сын, дочь.
     
    Пример ввода:
    дедушка Вася
    бабушка Мурка
    папа Котофей
    мама Василиса
    сын Мурчик
    дочь Пушинка
     
    Пример вывода:
    Cat name is дедушка Вася, no mother, no father
    Cat name is бабушка Мурка, no mother, no father
    Cat name is папа Котофей, no mother, father is дедушка Вася
    Cat name is мама Василиса, mother is бабушка Мурка, no father
    Cat name is сын Мурчик, mother is мама Василиса, father is папа Котофей
    Cat name is дочь Пушинка, mother is мама Василиса, father is папа Котофей
    */
     
    public class Solution
    {
        public static void main(String[] args) throws IOException
        {
            BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
     
            String grfatherName = reader.readLine();
            Cat catGrfather = new Cat(grfatherName);
     
            String grmotherName = reader.readLine();
            Cat catGrmother = new Cat(grmotherName);
     
            String fatherName = reader.readLine();
            Cat catFather = new Cat(fatherName, catGrfather, null);
     
            String motherName = reader.readLine();
            Cat catMother = new Cat(motherName, null, catGrmother);
     
            String sonName = reader.readLine();
            Cat catSon = new Cat(sonName, catFather, catMother);
     
            String daughterName = reader.readLine();
            Cat catDaughter = new Cat(daughterName, catFather, catMother);
     
            System.out.println(catGrfather);
            System.out.println(catGrmother);
            System.out.println(catFather);
            System.out.println(catMother);
            System.out.println(catSon);
            System.out.println(catDaughter);
     
        }
     
        public static class Cat
        {
            private String name;
            private Cat father;
            private Cat mother;
     
     
            Cat(String name)
            {
                this.name = name;
            }
     
            Cat (String name, Cat father, Cat mother){
                this.name = name;
                this.mother = mother;
                this.father = father;
     
            }
     
            @Override
            public String toString()
            {
                if ((mother == null) && (father == null))
                    return "Cat name is " + name + ", no mother, no father ";
                else if (father == null)
                    return "Cat name is " + name + ", mother is " + mother.name + " , no father";
                else if (mother == null)
                    return  "Cat name is " + name + ", no mather " + ", father is " + father.name;
                else
                    return "Cat name is " + name + ", mother is " + mother.name + ", father is " + father.name;
            }
        }
    }

    Да лаба, точнее задание. Но меня так умиляет решение задачи :) Просто немного хардкода :)

    kostoprav, 15 Мая 2014

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

    +156

    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
    if ($.browser.msie && $.browser.version < 8) {
            $("div.banneritem:gt(0)").remove();
                    $("#viewnow").remove();
                    $("#morerealestates").css("margin-top", "-26px");
                    $("img[align=right]").css("float", "right");
       }
       else {
            setTimeout(function(){
                    slider();
            }, 0);
       }
           
            var got = $("div.banneritem:eq(0)").find("#preview").find("a").attr("href");;
            var timer = 7500;
            var anim = 750;
            function slider()
            {
                    setTimeout(function(){
                            do_slide(0);
                            setTimeout(function(){
                                    do_slide(1);
                                    setTimeout(function(){
                                            do_slide(2);
                                            setTimeout(function(){
                                                    do_slide(2, true);
                                                    setTimeout(function(){
                                                            do_slide(1, true);
                                                            setTimeout(function(){
                                                                    do_slide(0, true);
                                                                    slider();
                                                            }, timer);
                                                    }, timer);
                                            }, timer);
                                    }, timer);
                            }, timer);
                    }, timer);
            }
     
            function do_slide(v,rev)
            {
                    x = "div.banneritem:eq(" + v + ")";
                    if(rev==null)
                    {
                            $(x).slideUp(anim);
                            foo = $("div.banneritem:eq(" + (v+1) + ")").find("#preview").find("a").attr("href");
                    }else
                    {
                            $(x).slideDown(anim);
                            foo = $("div.banneritem:eq(" + (v-1) + ")").find("#preview").find("a").attr("href");
                    }
                   
                    if(foo!=null) got = foo;
                   
            }
           
            $("#viewnow").click(function(){
                    window.location=got;
            });

    Классика, слайдер на 3 елемента, с возавтом ;)

    expert, 15 Мая 2014

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

    +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
    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
    if($('.article-775-gallery')){
            $('.article-775-gallery').each(function(){
                get_images_by_building_gallery_id($(this).attr('id').replace(/gallery-/g,''));
            });
        }
    
        /* ************************************************************************************************************** */
    
        function get_building_details_by_property_id(id, size){
            $.get(urlprefix + "/ajax/nanar/" + id, function(data){
                var desc = jQuery.parseJSON(data);
                console.log(desc);
                if(desc.street && desc.zip && desc.town){
                    $('div[id="new-property-entry-id-' + id + '"] .house-item-head').html(desc.street + " <strong>" + desc.zip + " " + desc.town + " </strong>");
                    $('div[id="new-property-entry-id-' + id + '"] .house__item-descr').text(desc.description);
                    $('div[id="new-property-entry-id-' + id + '"] img').attr('src', desc.preview + size);
                    $('div[id="new-property-entry-id-' + id + '"] .verd').text(desc.verd);
                    $('div[id="new-property-entry-id-' + id + '"] .stard').text(desc.stard);
                    $('div[id="new-property-entry-id-' + id + '"] .tegund').text(desc.tegund);
                    $('div[id="new-property-entry-id-' + id + '"] .rooms').text(desc.rooms);
                    $('div[id="new-property-entry-id-' + id + '"]').slideDown();
                }
            });
        }
    
        if($('div[id^="new-property-entry-id-"]')){
            setTimeout(function(){
                $($('div[id^="new-property-entry-id-"]')).each(function(){
                    var size;
                    if($('div[id^="new-property-entry-id-"] div').hasClass('big-image')){
                        size = "180x140";
                        $('.new-property-entry-description').css('width','476px');
                        $('.time').css('display','block');
                    }else{size = "322x157";}
                    get_building_details_by_property_id($(this).attr('id').replace(/new-property-entry-id-/g,''), size);
                });
            },500);
        }

    код творит чудеса :), я его побоялся трогать.... знаю что функция на 9 строчке, это некое подобие шаблонизатора

    expert, 15 Мая 2014

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

    +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
    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
    $('.order-form-popup form').on('submit', function (e) {
    			e.preventDefault();
    			var data = $(this).serializeArray(),
    				mainProfilesList = '',
    				fillingsList = '';
    
    			$('.field-name-field-eo-main-profiles .field-item').each(function () {
    				mainProfilesList += ('<li>' + ($(this).text()) + '</li>');
    			});
    
    			$('.field-name-field-eo-fillings .field-item').each(function () {
    				fillingsList += ('<li>' + ($(this).text()) + '</li>');
    			});
    
    			data.push({
    				name: 'profiles',
    				value: '<ul>' + mainProfilesList + '</ul>'
    			});
    
    			data.push({
    				name: 'fillings',
    				value: '<ul>' + fillingsList + '</ul>'
    			});
    
    			data.push({
    				name: 'number',
    				value: $('.field-name-field-eo-product-number .field-item').text()
    			});
    
    			data.push({
    				name: 'qty',
    				value: $('#qty-input').val()
    			});
    
    			data.push({
    				name: 'area',
    				value: $('.field-name-field-eo-area .field-item').text()
    			});
    
    			data.push({
    				name: 'price',
    				value: $('.field-name-field-eo-price-without-discount .field-item').text()
    			});
    
    			$.ajax({
    				url: location.protocol + '//' + location.hostname + '/send-message.php',
    				type: 'POST',
    				data: data,
    				success: function (data, textStatus) {
    					var msg = '<h3 id="order-form-popup-msg" style="text-align: center; margin-top: 50%;">Заявка успешно отправлена.<br /> Спасибо!</h3>'
    					$('.order-form-popup form, .order-form-popup-title').hide();
    					$('.order-form-popup').append(msg);
    					window.setTimeout(function () {
    						$('.order-form-popup, .order-form-overlay').fadeOut(500);
    						$('#order-form-popup-msg').remove();
    						$('.order-form-popup form, .order-form-popup-title').show();
    					}, 3500);
    				},
    				error: function (jqXHR, textStatus, errorThrown) {
    					//for debugging
    				}
    			});
    		});

    Сериализация данных из полей, находящихся вне формы.

    DrDre, 15 Мая 2014

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