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

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

    +3

    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
    do {           
                $entries = $xpath->query("//div[@class='identity']/img");
                if(isset($entries[0])) break;
                $entries = $xpath->query("//h1[@class='avatared']/a/img");
                if(isset($entries[0])) break;
                $entries = $xpath->query("//div[@class='avatared']/a/img");
                if(isset($entries[0])) break;
                $entries = $xpath->query("//div[@itemtype='http://schema.org/Person']/a/img");
            } while(false);
            if(!isset($entries[0])) continue;
    
            $src = $entries[0]->getAttribute('src');
            if(!preg_match('#[/=]([0-9a-f]{32})[\?&]#', $src, $matches)) continue;
            $hash = $matches[1];
    
    // спустя несколько строк
    
            do {           
                $entries = $xpath->query("//div[@class='email']/script");
                if(isset($entries[0])) break;
                $entries = $xpath->query("//dl/dd[@class='email']/script");
            } while(false);
            if(isset($entries[0])) {
                $rawcode = $entries[0]->textContent;
                if(!preg_match("#eval\(decodeURIComponent\('(.*)'\)\)#", $rawcode, $matches)) continue;
                $rawcode2 = urldecode($matches[1]);
                if(!preg_match('#href=\\\\?"mailto:([^"\\\\]*)\\\\?"#', $rawcode2, $matches)) continue;
                $email = $matches[1];
                unset($entries);
            } else do {
                $entries = $xpath->query("//div[@class='avatared']/div[@class='details']/dl/dd/a[@data-email]");
                if(isset($entries[0])) break;
                $entries = $xpath->query("//ul[@class='vcard-details']/li[@class='vcard-detail']/a[@data-email]");
            } while(false);
            if(isset($entries[0])) {
                $email = urldecode($entries[0]->getAttribute('data-email'));
            }

    Прототип программы, вытягивающей хэш аватарки и е-мейл из архивной копии профиля в «Гитхабе».

    Nyancat, 21 Июля 2021

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

    0

    1. 1
    С Днём Победы!

    rJlaBHblu_nemyx

    BoeHHblu_nemyx, 09 Мая 2021

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

    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
    template<typename T>
    struct method_traits;
    
    template<typename T, typename RetT, typename... Args>
    struct method_traits<RetT(T::*)(Args...)> {
        using this_type = T;
        using ret_type = RetT;
    
        template<size_t ArgIdx>
        using arg_type = typename std::tuple_element<ArgIdx, std::tuple<Args...>>::type;
    
        static constexpr size_t args_count = sizeof...(Args);
        static constexpr bool is_const = false;
        static constexpr bool is_lvalue = false;
        static constexpr bool is_rvalue = false;
    };
    
    template<typename T, typename RetT, typename... Args>
    struct method_traits<RetT(T::*)(Args...) const> : public method_traits<RetT(T::*)(Args...)> {
        static constexpr bool is_const = true;
    };
    
    template<typename T, typename RetT, typename... Args>
    struct method_traits<RetT(T::*)(Args...) &> : public method_traits<RetT(T::*)(Args...)> {
        static constexpr bool is_lvalue = true;
    };
    
    template<typename T, typename RetT, typename... Args>
    struct method_traits<RetT(T::*)(Args...) &&> : public method_traits<RetT(T::*)(Args...)> {
        static constexpr bool is_rvalue = true;
    };
    
    template<typename T, typename RetT, typename... Args>
    struct method_traits<RetT(T::*)(Args...) const &> : public method_traits<RetT(T::*)(Args...)> {
        static constexpr bool is_const = true;
        static constexpr bool is_lvalue = true;
    };
    
    template<typename T, typename RetT, typename... Args>
    struct method_traits<RetT(T::*)(Args...) const &&> : public method_traits<RetT(T::*)(Args...)> {
        static constexpr bool is_const = true;
        static constexpr bool is_rvalue = true;
    };

    А вдруг в новом стандарте ещё модификаторов в тип завезут? Страшня стало...

    PolinaAksenova, 07 Мая 2021

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

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    # PowerShell
    
    switch ($true)
    {
        ($firstNumber -gt $secondNumber) {Write-Output ("{0} > {1}" -F $firstNumber, $secondNumber)}
        ($firstNumber -eq $secondNumber) {Write-Output ("{0} == {1}" -F $firstNumber, $secondNumber)}
        ($firstNumber -lt $secondNumber) {Write-Output ("{0} < {1}" -F $firstNumber, $secondNumber)}
    }

    Интересный такой свитч-кейс (https://stackoverflow.com/questions/57063932/powershell-overriding-assignment-and-comparison-operators)

    groser, 24 Марта 2021

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

    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
    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
    $(".reg_button").on("click", function(){
        console.log("hello world jquery");
        $(".main").css("display", "none");
        $(".register-main").css("display", "block");
        $(`input[type="text"]`).css("width", "14vw");
        $(`input[type="password"]`).css("width", "14vw");
        $(`input[type="email"]`).css("width", "14vw");
         // Обработка нажатия на кнопку регистрации
    });
    const recovery = {
      login: "",
      email: "",
    }
    const regExp = {
      login: /^[a-z0-9_-]{5,20}$/,
      pass: /^[A-Za-z0-9_-]{6,16}$/,
      email: /^[A-Z0-9._%+-]+@[A-Z0-9-]+.+.[A-Z]{2,4}$/i,
    }
    const state = {
      reg: {
        login: "",
        pass: "",
        email: "",
        agreement: ""
      },
      auth: {
        login: "",
        pass: "",
        agreement: false
      }
      }
    $(".back").on("click", function() {
        $(".register-main").css("display", "none");
        $(".main").css("display", "flex");
        $(`input[type="text"]`).css("width", "21.5vw");
        $(`input[type="password"]`).css("width", "21.5vw");
        // Обработка нажатия на кнопку "Назад"
    });
    $(".auth_forgotPassword").on("click", function() {
      console.log("Система восстановления пароля в разработке.")
     /* $(".main").css("display", "none");
      $(".recovery").css("display", "block");
      $(".recovery-step-one").css("display", "block");
      $(`input[type="text"]`).css("width", "14vw");
      $(`input[type="password"]`).css("width", "14vw"); */
    })
    $(".recovery-back").on("click", function() {
      $(".recovery").css("display", "none");
      $(".recovery-step-one").css("display", "none");  
      $(".main").css("display", "flex");                 // кнопка назад, в восстановления пароля.
      $(`input[type="text"]`).css("width", "21.5vw");
      $(`input[type="password"]`).css("width", "21.5vw");
    })
    $(".recovery-back2").on("click", function() {
      $(".recovery-step-two").css("display", "none");
      $(".recovery").css("display", "block");     
      $(".recovery-step-one").css("display", "block");                  // кнопка назад, в восстановления пароля.
      $(`input[type="text"]`).css("width", "14vw");
      $(`input[type="password"]`).css("width", "14vw");
    })
    // $(".recovery-button").on("click", function() {
      /*recovery.login = $(".step_login").val()
      recovery.email = $(".step_email").val()
      alt.emit("click:recovery")
      if(recovery.login == "" || recovery.email == "" )
      {
        console.log("Необходимые поля пустые!")
      }
      else {
      alt.on("recovery-step-two", (args) => {
      if(args == true) {
        $(".recovery-step-one").css("display", "none");
        $(".recovery-step-two").css("display", "block");
      }
      else {
        console.log("Введены неверные данные или аккаунта с такой почтой не существует.")
      }
      })
      }
      */
    // })
    $(".recovery_button2").on("click", function() {
      $(".recovery-step-two").css("display", "none");
      $(".recovery-step-three").css("display", "block");
    })
    $('.button-wrap').on("click", function(){
      $(this).toggleClass('button-active');
      if ($(this).hasClass('button-active')) {
        localStorage.checkbox = 1
        
      } else {
        localStorage.checkbox = 0
      }
      console.log(localStorage.checkbox)
    });
    $(".confirm-back2").on("click", () => {
      $(".authentication").css("display", "none");

    Логика работы меню авторизации :)
    Собственно первая моя верстка была, как и использование jquery)

    Seagate, 22 Марта 2021

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

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    var object = {a: 123, b:"abc"};
    var newObject = ko.observableProps(object);
    newObject.a(345);
    newObject.b("def");
    
    newObject.a(); => 345
    newObject.b(); => "def"

    Ко-ко-ко-ко-ко-обсервабле

    3_dar, 27 Февраля 2021

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

    −1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    void setAreaPreScale(double scale)
    {
      if(scale == 1)
        setFrameSize(initialFrameSize.first, initialFrameSize.second);
      else
      {
        double widthPart = (1 - initialFrameSize.first) * (1 - scale);
        double heightPart = (1 - initialFrameSize.second) * (1 - scale);
        setFrameSize(initialFrameSize.first + widthPart, initialFrameSize.second + heightPart);
      }
    }

    требуется сделать отложенное масштабирование картинки, сначала рисуется (и скейлится методом setAreaPreScale) рамка с областью, в которую будет замасштабировано, затем отдельной кнопкой будет масштабироваться. в методе происходит рассчёт размера в пикселях рамки прескейла по параметру scale (отношение будущего масштаба к текущему). initialFrameSize на самом деле maxFrameSize, но авторский код сохранён

    gladijos, 11 Февраля 2021

    Комментарии (5)
  9. SQL / Говнокод #27238

    −1

    1. 1
    2. 2
    3. 3
    Falcon Space - это платформа для создания веб-решений с управлением через SQL. 
    Все создается и управляется на SQL. 
    Телеграм бот управляется полностью 1 хранимой процедурой на SQL!

    https://falcon.web-automation.ru/docs/telegram-boty-i-otpravka-soobshcheniy-v-telegram

    Fike, 06 Февраля 2021

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

    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
    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
    var адрес = localStorage.getItem("пуск");
                if (!адрес)
                {
                    адрес = "https://bitbucket.org/gitjs/0000/raw/master/0000.js";
                }
    
                var gitjs = {};
    
                gitjs.uuid = function()
                {
                    // https://stackoverflow.com/a/2117523
                    return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(
                        /[xy]/g,
                        function(c)
                        {
                            var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
                            return v.toString(16);
                        }
                    );
                };
    
                function запуститьGitJSЛокально(пуск)
                {
                    eval(пуск);
                    запуститьGitJS();
                }
    
                function запуститьGitJSПоСети(адрес)
                {
                    function загрузилиПуск(пуск)
                    {
                        localStorage.setItem("0000", пуск);
                        eval(пуск);
                        запуститьGitJS();
                    }
                    function неУдалосьЗагрузитьПуск(ошибка)
                    {
                        var сообщение = `ОШИБКА ⚬ 错误 ⚬ ERROR: '${ошибка}'`
                        console.error(сообщение);
                        document.body.append(сообщение);
                    }
    
                    var запрос = new XMLHttpRequest();
                    запрос.onreadystatechange = function()
                    {
                        if (this.readyState == 4)
                        {
                            if (this.status == 200)
                            {
                                загрузилиПуск(this.responseText);
                            }
                            else
                            {
                                неУдалосьЗагрузитьПуск(this.status);
                            }
                        }
                    }
                    запрос.open("GET", адрес + "?" + gitjs.uuid());
                    запрос.send();
    
                    console.debug("Загрузка пускового скрипта по сети  Loading startup script over network");
                    console.debug(адрес);
                }
    
                function версияАктуальна(содержимое)
                {
                    var ожидаемаяВерсия = "1.2.1";
                    var перваяСтрока = содержимое.split(/\n/)[0];
                    var ч = перваяСтрока.split(/"/);
                    return ч.length == 5 && ч[0] == "gitjs[" && ч[1] == "ijlj" && ч[3] == ожидаемаяВерсия;
                }
    
                var пуск = localStorage.getItem("0000");
    
                if (пуск && версияАктуальна(пуск))
                {
                    запуститьGitJSЛокально(пуск);
                }
                else
                {
                    запуститьGitJSПоСети(адрес);
                }

    афтар: https://gitlab.com/gitjs/gitjs.gitlab.io/-/blob/master/index.html

    kapu, 01 Февраля 2021

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

    +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
    // https://quuxplusone.github.io/blog/2021/01/13/conversion-operator-lookup/
    
    struct A {
        using T = T1;
        using U = U1;
        operator U1 T1::*();
        operator U1 T2::*();
        operator U2 T1::*();
        operator U2 T2::*();
    };
    
    inline auto which(U1 T1::*) { return "gcc"; }
    inline auto which(U1 T2::*) { return "icc"; }
    inline auto which(U2 T1::*) { return "msvc"; }
    inline auto which(U2 T2::*) { return "clang"; }
    
    int main() {
        A a;
        using T = T2;
        using U = U2;
        puts(which(a.operator U T::*()));
    }

    > As of this writing (but perhaps not for very much longer!) the four mainstream compilers on Godbolt Compiler Explorer give four different answers for this simple C++ program:

    > According to the current draft standard, it sounds like the conforming answer is “they should both be looked up in the scope of A”; i.e., GCC’s answer is correct and the others are wrong in three different ways.

    Какой багор )))

    j123123, 21 Января 2021

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