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

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

    0

    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
    internal void OnItemSaved(object sender, EventArgs args)
    {
    Sitecore.Diagnostics.Log.Error("OnItemSaved: Fired", new Exception());     
    var eventArgs = args as Sitecore.Events.SitecoreEventArgs;
    Sitecore.Diagnostics.Assert.IsNotNull(eventArgs, "eventArgs");
    
    if (eventArgs == null) return;
    
    var item = eventArgs.Parameters[0] as Sitecore.Data.Items.Item;
    var currItem = item;
    
    Sitecore.Diagnostics.Log.Error("OnItemSaved: " + item.Name, new Exception());     
    
    TaxonomyBaseItem i = item;
    
    if (currItem != null)
    {
        try
        {
            while (item != null && item.TemplateID.ToString() != TopicSectionFrontPageItem.TemplateId)
            {
                item = item.Parent;
            }
    
            if (item == null) return;
    
            Sitecore.Diagnostics.Log.Error("OnItemSaved: " + item.Name, new Exception());
            
            if (!i.TopicTaxonomy.ListItems.Contains(item))
            {
                Sitecore.Diagnostics.Log.Error("OnItemSaved: Doesn't contain it", new Exception());     
    
                Sitecore.Data.Fields.MultilistField mfield = currItem.Fields["Topic Taxonomy"];
                if (!mfield.Contains(item.ID.ToString()))
                {
                    using (new Sitecore.SecurityModel.SecurityDisabler())
                    {
                        currItem.Editing.BeginEdit();
                        if (currItem.Fields["Topic Taxonomy"].Value == string.Empty)
                        {
                            currItem.Fields["Topic Taxonomy"].Value += item.ID.ToString();
                        }
                        else
                        {
                            currItem.Fields["Topic Taxonomy"].Value += "|" + item.ID.ToString();
                        }
                        Sitecore.Diagnostics.Log.Error("OnItemSaved: " + currItem.Fields["Topic Taxonomy"].Value, new Exception());     
    
                        currItem.Editing.EndEdit();
                    }
                }
            }    
        }
        catch (Exception ex)
        {
            Sitecore.Diagnostics.Log.Error("OnItemSaved: " + ex.Message, new Exception());        
        }        
    }

    Когда ты хочешь чтобы твои логи были заметны: Sitecore.Diagnostics.Log.Error("OnItemSa ved: " + item.Name, new Exception());
    И когда никому не хочешь рассказывать об эксепшенах:
    catch (Exception ex)
    {
    Sitecore.Diagnostics.Log.Error("OnItemSa ved: " + ex.Message, new Exception());
    }

    VolAnder, 25 Сентября 2019

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

    0

    1. 1
    2. 2
    3. 3
    4. 4
    ButtonCustom {
        visible: !cyrcleProgress.visible ? true : false
        ...
    }

    FrontlineReporter, 02 Сентября 2019

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

    +1

    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
    namespace detail
    {
    template <typename Function, typename Tuple, std::size_t... i>
    void applyForEach(Function&& f, Tuple&& t, std::index_sequence<i...>)
    {
      (static_cast<void>(std::invoke(f, std::integral_constant<std::size_t, i>{}, std::get<i>(t))), ...);
    }
    } // namespace detail
    
    template <typename Function, typename Tuple>
    void applyForEach(Tuple&& tuple, Function&& function)
    {
      using Indexes = std::make_index_sequence<std::tuple_size_v<Tuple>>;
      detail::applyForEach(std::forward<Function>(function), std::forward<Tuple>(tuple), Indexes{});
    }

    Строка 6. Мы тут сделали синтаксис для fold expression, только вам его не дадим: у вас документов нет.

    Clang: https://wandbox.org/permlink/lNOFu1sOV9bA2LJF
    GCC: https://wandbox.org/permlink/yqeiYHTgZOz9NkkJ

    Elvenfighter, 07 Августа 2019

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

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    Note
    pytest by default escapes any non-ascii characters used in unicode strings for the parametrization because it has several downsides. If however you would like to use unicode strings in parametrization and see them in the terminal as is (non-escaped), use this option in your pytest.ini:
    
    [pytest]
    disable_test_id_escaping_and_forfeit_all_rights_to_community_support = True

    Прыщебляди не могут в юникод. Капча ujox согласна.

    syoma, 31 Июля 2019

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

    +1

    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
    <script>
        var myMap;
        var ymapsReady = function () {
            myMap = new ymaps.Map('<?= $options['containerId'] ?>', {
                center: [55.751574, 37.573856],
                zoom: 9,
                controls: []
            }, {
                searchControlProvider: 'yandex#search'
            });
    
            <?php
            if(isset($options['centerCoordinates'])){
            ?>
            myMap.setCenter(<?= $options['centerCoordinates'] ?>);
            <?php
            }elseif(isset($options['centerAddress'])){?>
            ymaps.geocode('<?= $options['centerAddress'] ?>', {
                results: 1
            }).then(function (res) {
                var firstGeoObject = res.geoObjects.get(0),
                    coords = firstGeoObject.geometry.getCoordinates();
                myMap.setCenter(coords);
            });
            <?php
            }
    
            if (!empty($options['salesOffices'])) {
                foreach( $options['salesOffices'] as $i => $salesOffice ) {
                $address = ArrayHelper::getValue($salesOffice, 'actual_address');
                ?>
                ymaps.geocode('<?= $address ?>', {
                    results: 1
                }).then(function (res) {
                    let firstGeoObject = res.geoObjects.get(0),
                        coords = firstGeoObject.geometry.getCoordinates();
    
                    ymaps.geocode(coords, {
                        kind: 'metro',
                        results: 2
                    }).then(function (res) {
                        res.geoObjects.each(function (geoObject) {
                            $('#placemark_<?= $i ?>').find('.metro').append("<div class='metro-item'>" + geoObject.getPremise().replace(/(^|\s)метро(\s|$)/g, '').replace(/(^|\s)станция(\s|$)/g, '') + '</div>');
                        });
                    });
    
                    let customIcon = ymaps.templateLayoutFactory.createClass('<div id="placemark_icon_<?= $i ?>" class="placemark-block"><div class="placemark"></div><div class="placemark-text"><?= ArrayHelper::getValue($salesOffice, 'name') ?></div></div>');
    
                    myPlacemark[<?= $i ?>] = new ymaps.Placemark(coords,
                        {
                            balloonContent: '<?= ArrayHelper::getValue($salesOffice, 'name') ?>',
                            iconCaption: customIcon,
    
                            iconLayout: 'default#imageWithContent',
                            iconContentLayout: customIcon
                        }, {
                            hintContent: '<?= ArrayHelper::getValue($salesOffice, 'name') ?>',
                            iconLayout: 'default#imageWithContent',
                            iconImageHref: '',
                            iconImageOffset: [-15, -27],
                            iconContentLayout: customIcon
                        });
    
                    myMap.geoObjects.add(myPlacemark[<?= $i ?>]);
                });
    
                <?php
                }
            }
            ?>
        };
    
        setTimeout(function () {
            ymaps.ready(ymapsReady);
        }, <?=( isset($options['isModal']) ? 500 : 0 )?>);
    </script>

    iErroRi, 25 Июня 2019

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

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    else {
            // на всякий случай возвращаем true в случае некоторых экзотических браузеров
            flashinstalled = true;
        }
    return flashinstalled;

    https://csdrop.org/
    main.js
    Просто из за комментария ☺

    GreatMASTERcpp, 04 Апреля 2019

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

    +2

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    Функция ПолучитьЗначениеПеременной(Имя) Экспорт	
    	ИмяПараметраВР = ВРег(Имя);	
    	НайденноеЗначение = Неопределено;	
    	Кэш = Неопределено;
    	ПоместитьВКэш = Ложь;	
    	НайденноеЗначение = Неопределено;	
    	Если НайденноеЗначение = Неопределено Тогда
            //... 
            КонецЕсли;

    Типовая УПП, общий модуль "РаботаСОбщимиПеренменными". Интересно, а бывает ситуация когда после двух присвоений переменной значения, она все таки не неопределено

    FesenkoA, 25 Марта 2019

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

    −4

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    static string ArrayToString(byte[] a) => return string.Join(",", a); // гуд
    
            static byte[] StringToArray(string a) // бэд
            {
                var parts = a.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                var partsLen = parts.Length;
                var b = new byte[partsLen];
                for (var i = 0; i < partsLen; i++)
                    b[i] = Convert.ToByte(parts[i]);
                return b;
            }

    GenkaFF, 24 Февраля 2019

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

    −1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    function plusD() {
    	var data_plus = new Date(1000 * 60 * 60 * 24),
    	us_Mill = data_plus.getTime();
    	return us_Mill;
    }

    unicorn, 10 Февраля 2019

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

    0

    1. 1
    2. 2
    $(document.getElementById("badgeEndDay")).add("background-badge");
    $("#badgeEndDay span").css("color", #f5f5f5");

    Типичный говнокод, который штампуют js макаки, набраные по рекомендации друзей шефа.

    Lorip1971, 02 Февраля 2019

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