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

    В номинации:
    За время:
  2. Куча / Говнокод #25284

    +1

    1. 1
    2. 2
    3. 3
    Знаете ли Вы, что ReadPrivateProfileString игнорирует закрывающую квадратную скобку в названии секции?
    
    [ThereAreValidSectionName

    Куд-куд-кудат-куд-куд!

    3oJloTou_neTyx, 05 Января 2019

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

    +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
    function preventSelection(element){
      var preventSelection = false;
    
      function addHandler(element, event, handler){
        if (element.attachEvent) 
          element.attachEvent('on' + event, handler);
        else 
          if (element.addEventListener) 
            element.addEventListener(event, handler, false);
      }
      function removeSelection(){
        if (window.getSelection) { window.getSelection().removeAllRanges(); }
        else if (document.selection && document.selection.clear)
          document.selection.clear();
      }
      function killCtrlA(event){
        var event = event || window.event;
        var sender = event.target || event.srcElement;
    
        if (sender.tagName.match(/INPUT|TEXTAREA/i))
          return;
    
        var key = event.keyCode || event.which;
        if (event.ctrlKey && key == 'A'.charCodeAt(0))  // 'A'.charCodeAt(0) можно заменить на 65
        {
          removeSelection();
    
          if (event.preventDefault) 
            event.preventDefault();
          else
            event.returnValue = false;
        }
      }
    
      // не даем выделять текст мышкой
      addHandler(element, 'mousemove', function(){
        if(preventSelection)
          removeSelection();
      });
      addHandler(element, 'mousedown', function(event){
        var event = event || window.event;
        var sender = event.target || event.srcElement;
        preventSelection = !sender.tagName.match(/INPUT|TEXTAREA/i);
      });
    
      // борем dblclick
      // если вешать функцию не на событие dblclick, можно избежать
      // временное выделение текста в некоторых браузерах
      addHandler(element, 'mouseup', function(){
        if (preventSelection)
          removeSelection();
        preventSelection = false;
      });
    
      // борем ctrl+A
      // скорей всего это и не надо, к тому же есть подозрение
      // что в случае все же такой необходимости функцию нужно 
      // вешать один раз и на document, а не на элемент
      addHandler(element, 'keydown', killCtrlA);
      addHandler(element, 'keyup', killCtrlA);
    }

    Долбоёбы борются с ветряными мельницами.

    gost, 05 Января 2019

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

    +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
    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
    #include <bits/stdc++.h>
    using namespace std;
    vector <pair<int,int> > vpp;
    long long vres = 0;
    int get_dist(pair<int,int> l, pair<int,int> r)
    {
        int ans1 = abs(l.first - r.first);
        int ans2 = abs(l.second - r.second);
        return ans1 + ans2;
    
    }
        pair<vector <pair<int,int> > , long long>  rec(const string &s, int id,long long len,pair<int,int> pos,vector <vector <pair<int,int> > > &cl, vector <pair<int,int> > p)
    {
        if(id == (int)s.size())
            return {p,len};
        int st = s[id] - 'a';
        pair<vector <pair<int,int> > , long long> ans,tmp;
    
        for(int j = 0; j < (int)cl[st].size(); ++j)
        {
            p.push_back({cl[st][j]});
            tmp = rec(s,id + 1, len + get_dist(pos, cl[st][j]), cl[st][j], cl,p);
            if(tmp.second >= ans.second)
            {
                ans = tmp;
            }
            p.pop_back();
        }
        return ans;
    }
    #define mag pair< pair< vector< pair<int,int> > , long long>  , pair< pair< int,int >,pair< int,int > > >
    mag raz(int l, int r,const string &s,vector <vector <pair<int,int> > > &cl)
    {
    
        mag v1,v2;
        vector <pair<int,int> > p;
        if(r - l >= 1)
        {
            int tm = (l + r) >> 1;
            v1 = raz(l,tm,s,cl);
            bool f = 1;
            if(tm + 1 > r)
            {
                v2 = v1;
                f = 0;
            }
            else
                v2 = raz(tm + 1,r,s,cl);
          //  int st1 = ar[v1.second.first.first][v1.second.first.second];
           // int st2 = ar[v2.second.first.first][v2.second.first.second];
            long long len = 0;
    
    ///merge
            int n = (int)v1.first.first.size();
            len += v1.first.second;
            for(int i = 0; i < n; ++i)
            {
                p.push_back(v1.first.first[i]);
            }
            if(f)
            {
                len += v2.first.second;
                int n = (int)v2.first.first.size();
                for(int i = 0; i < n; ++i)
                {
                    p.push_back(v2.first.first[i]);
                }
            }
            len += get_dist(v1.second.second, v2.second.first);
            return {{p,len}, {v1.second.second, v2.second.first}};
        }
    
        int st = s[l] - 'a';
        int x1 = rand() % (int)cl[st].size();
        p.push_back(cl[st][x1]);
       // cout << cl[st].size() << " " << l << " " << r <<'\n';
        return {{p,0},{cl[st][x1],cl[st][x1]}};
    }
    //pair<int,vector <pair<int,int> > > solve(ifstream &cin, ofstream &cout)
     void solve(ifstream &cin, ofstream &cout)
    {
        vector <int> used(26);
        vector <vector <pair<int,int> > > cl(26);
        int n, m ,l;
        cin >> n >> m >> l;
        vector <vector <char > > ar(n,vector <char> (m));
        for(int i = 0; i < n; ++i)
        {
            for(int j = 0; j < m; ++j)
            {
                cin >> ar[i][j];
            }
        }
        string s;
        cin >> s;
        for(int i = 0; i < n; ++i)
        {

    omnocoder, 04 Января 2019

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

    +1

    1. 1
    .

    С Новым Годом, программные инженеры!
    Желаю всем интересной работы, высоких заработков и крепкого здоровья!

    crestoblyad, 01 Января 2019

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

    +1

    1. 1
    <GlobalConverters:EnumOrStringToSolidColorBrushConverter x:Key="UpdaterProcessStatusConverter" Mapping="UpdaterSuccessProcess-=-#01579B;UpdaterErrorProcess-=-#E53935;UpdaterWarningProcess-=-#FBBE44"/>

    XAML из WPF

    Говногость, 31 Декабря 2018

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

    +1

    1. 1
    $today = new \DateTime('@'.strtotime(date("y-m-d", time())));

    Today

    makaka16, 27 Декабря 2018

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

    +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
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    
    #define SQARESZ 3
    
    
    void rotateclockwise(char *ptra, size_t sz)
    {
        char (*a_ar)[sz] = (void *)ptra;
        char b_ar[sz][sz];
        for (size_t y = 0; y < sz; y++)
        {
            for (size_t x = 0; x < sz; x++)
            {
                b_ar[y][x] = a_ar[sz-1-x][y];
            }
        }
        memcpy(a_ar, b_ar, sz*sz);
    }
    
    void print_ar(char *ptra, size_t sz)
    {
        char (*a_ar)[sz] = (void *)ptra;
        for (size_t y = 0; y < sz; y++)
        {
            for (size_t x = 0; x < sz; x++)
            {
                printf("%i ", a_ar[y][x]);
            }
            printf("\n");
        }
    }
    
    int main()
    {
        char a[SQARESZ][SQARESZ] =
        {
          {1,2,3},
          {4,5,6},
          {7,8,9}
        };
        
        print_ar((char *)a, SQARESZ);
        printf("\n");
        rotateclockwise((char *)a, SQARESZ);
        
        print_ar((char *)a, SQARESZ);
        printf("\n");
        rotateclockwise((char *)a, SQARESZ);
        
        print_ar((char *)a, SQARESZ);
        printf("\n");
        rotateclockwise((char *)a, SQARESZ);
        
        print_ar((char *)a, SQARESZ);
        printf("\n");
        rotateclockwise((char *)a, SQARESZ);
        
        print_ar((char *)a, SQARESZ);
        printf("\n");
    
        return 0;
    }

    https://habr.com/post/317300/ В C++17 до сих пор нет нормальных многомерных массивов, которые были в Fortran начиная с Fortran 90

    > UPD от 2016-12-10 14:03. Посмотрел на этот коммент от @selgjos, поэкспериментировал с компилятором и понял, что с помощью C99 VLA всё-таки можно добиться нужного мне эффекта.
    > В общем, окей, в C есть нужные мне массивы. Как и в Fortran. А в C++ их по-прежнему нет.

    j123123, 26 Декабря 2018

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

    +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
    template<class T, class U> bool convertStrToInt(const char* str, int base, T &res, T def, U (*strto)(const char *, char **, int ))
    {
        char *endptr = NULL;
        errno = 0;//man wants it
        if ( ! str || *str == '\0' )
        {
            res = def;
            return false;
        }
        U result =  strto(str, &endptr, base);
        if (errno == ERANGE || (*endptr != '\0') || ! *str) {
            std::stringstream errorStr;
            errorStr << "convertStrToInt failed ; string = '" << str << "' result ='" << result << "' endptr = '" << endptr << "' errno = '" << errno << "'";
            res = def;
            log_error("%s", errorStr.str().c_str());
            return false;
        }
        res = static_cast<T>(result);
        return true;
    }

    Преобразование строки в число

    patzantre, 26 Декабря 2018

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

    +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
    public static string GetTextFromExcel97To2003Format(string filePath)
    {
        FileStream fileStream = null;
        POIFSFileSystem fileSystem = null;
        ExcelExtractor excelExtractor = null;
     
        try
        {
            using (fileStream = new FileStream(filePath, FileMode.Open))
            {
                fileSystem = new POIFSFileSystem(fileStream);
                excelExtractor = new ExcelExtractor(fileSystem);
                excelExtractor.IncludeBlankCells = false; // optional
                excelExtractor.IncludeCellComments = false; // optional
                excelExtractor.IncludeHeaderFooter = false; // optional
                excelExtractor.IncludeSheetNames = false; // optional
     
                return excelExtractor.Text;
            }
        }
        catch
        {
            // handle the exception
        }
        finally
        {
            if (excelExtractor != null)
            {
                excelExtractor.Close();
                excelExtractor = null;
            }
     
            fileSystem = null;
     
            if (fileStream != null)
            {
                fileStream.Close();
                fileStream.Dispose();
                fileStream = null;
            }
        }
     
        return string.Empty;
    }

    это пиздец, товарищи: https://www.kunal-chowdhury.com/2017/07/npoi-excel-97-2003
    эта хуита, на серьезных щах задвигается как документация к либе: https://github.com/tonyqus/npoi/wiki/Getting-Started-with-NPOI
    как, блять, так можно? юзинги? та пошли вы нахуй, я вам не доверяю. и вообще, присвоение нуля тоже хуйня. нельзя доверять никому. НИКОМУ!!
    Я не навижу индусов. Это пиздец. Это уже не первый раз, я натыкаюсь на статейку, которую, вот так читаешь, и понимаешь, что какая-то откровенная поибота и с мыслью "наверное опять эти ебаные индусы" скролишь вниз? чтобы увидеть рожу или хотябы имя автора. и там, СУКА, ИНДУС!!! они говорят, будь толерантным, а я им говорю, пошли НА ХУЙ!!!

    Lorip1971, 24 Декабря 2018

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

    +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
    if($form_action=="register") {
       if($coo_coo=="tootoo") {
       if($myusername) {
          if($mypassword) {
             if($mypassword==$myrepeat) {
                $uLength = strlen($myusername);
                $pLength = strlen($mypassword);
                if($uLength >= 3 && $uLength <= 30) {
                   $return_error = "";
                } else {
                   $return_error = "Username must be between 3 and 30 characters.";
                }
                if($pLength >= 3 && $pLength <= 30) {
                   $return_error = "";
                } else {
                   $return_error = "Password must be between 3 and 30 characters.";
                }
                if($return_error == "") {
                   if($db_found) {
                      $mypassword = md5($mypassword);
                      $SQL = "SELECT * FROM users WHERE username='$myusername'";
                      $result = mysql_query($SQL);
                      $num_rows = mysql_num_rows($result);
                      if($num_rows==1) {
                         $return_error = "Username already taken.";
                      } else {
                         if(!mysql_query("INSERT INTO users (id,date,ip,username,password) VALUES ('','$date','$ip','$myusername','$mypassword')")){
                            $return_error = "System error.";
                         } else {
                            $return_error = "Logged in.";
                            $_SESSION['user_session'] = $myusername;
                            header ("Location: index.php");
                         }
                      }
                   }
                }
             } else {
                $return_error = "Passwords did not match";
             }
          } else {
             $return_error = "No password was entered.";
          }
       } else {
          $return_error = "No username was entered.";
       }
       } else {
          $return_error = "Registrations are disabled.";
       }
    }

    "Сам кусок регистрации"
    Ошибка начинается с первой строки...

    MouseZver, 21 Декабря 2018

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