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

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

    +2

    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
    void KateQuickOpen::update () {
      // пропущено
      QModelIndex idxToSelect;
      int linecount = 0;
      QMapIterator<qint64, KTextEditor::View *> i2(sortedViews);
      while (i2.hasNext()) {
            i2.next();
    
            KTextEditor::Document *doc = i2.value()->document();
    
            if (alreadySeenDocs.contains(doc))
              continue;
    
            alreadySeenDocs.insert (doc);
    
            QStandardItem *itemName = new QStandardItem(doc->documentName());
    
            itemName->setData(qVariantFromValue(QPointer<KTextEditor::Document> (doc)), DocumentRole);
            itemName->setData(QString("%1: %2").arg(doc->documentName()).arg(doc->url().pathOrUrl()), SortFilterRole);
            itemName->setEditable(false);
            QFont font = itemName->font();
            font.setBold(true);
            itemName->setFont(font);
    
            QStandardItem *itemUrl = new QStandardItem(doc->url().pathOrUrl());
            itemUrl->setEditable(false);
            base_model->setItem(linecount, 0, itemName);
            base_model->setItem(linecount, 1, itemUrl);
            linecount++;
    
            if (!doc->url().isEmpty() && doc->url().isLocalFile())
              alreadySeenFiles.insert (doc->url().toLocalFile());
    
            // select second document, that is the last used (beside the active one)
            if (linecount == 2)
              idxToSelect = itemName->index();
        }
    
      // get all open documents
      QList<KTextEditor::Document*> docs = Kate::application()->documentManager()->documents();
        foreach(KTextEditor::Document *doc, docs) {
            // skip docs already open
            if (alreadySeenDocs.contains (doc))
              continue;
    
            QStandardItem *itemName = new QStandardItem(doc->documentName());
    
            itemName->setData(qVariantFromValue(QPointer<KTextEditor::Document> (doc)), DocumentRole);
            itemName->setData(QString("%1: %2").arg(doc->documentName()).arg(doc->url().pathOrUrl()), SortFilterRole);
            itemName->setEditable(false);
            QFont font = itemName->font();
            font.setBold(true);
            itemName->setFont(font);
    
            QStandardItem *itemUrl = new QStandardItem(doc->url().pathOrUrl());
            itemUrl->setEditable(false);
            base_model->setItem(linecount, 0, itemName);
            base_model->setItem(linecount, 1, itemUrl);
            linecount++;
    
            if (!doc->url().isEmpty() && doc->url().isLocalFile())
              alreadySeenFiles.insert (doc->url().toLocalFile());
        }
    
        // insert all project files, if any project around
        if (Kate::PluginView *projectView = m_mainWindow->mainWindow()->pluginView ("kateprojectplugin")) {
          QStringList projectFiles = projectView->property ("projectFiles").toStringList();
          foreach (const QString &file, projectFiles) {
            // skip files already open
            if (alreadySeenFiles.contains (file))
              continue;
    
            QFileInfo fi (file);
            QStandardItem *itemName = new QStandardItem(fi.fileName());
    
            itemName->setData(qVariantFromValue(KUrl::fromPath (file)), UrlRole);
            itemName->setData(QString("%1: %2").arg(fi.fileName()).arg(file), SortFilterRole);
            itemName->setEditable(false);
            QFont font = itemName->font();
            font.setBold(true);
            itemName->setFont(font);
    
            QStandardItem *itemUrl = new QStandardItem(file);
            itemUrl->setEditable(false);
            base_model->setItem(linecount, 0, itemName);
            base_model->setItem(linecount, 1, itemUrl);
            linecount++;
          }
        }
    
        // swap models and kill old one
        m_model->setSourceModel (base_model);
        delete m_base_model;
        m_base_model = base_model;
    
        // пропущено
    }

    Адская копипаста. У меня мозг сегфолтится при попытке ее формализировать.

    https://projects.kde.org/projects/kde/applications/kate/repository/revisions/master/entry/kate/app/katequickopen.cpp#L135

    Elvenfighter, 16 Февраля 2014

    Комментарии (63)
  3. C++ / Говнокод #13971

    +2

    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
    class pool_exeption: public std::exception
    {
        virtual  const char* what() const throw()
        {
            return "Pool out of bounds";
        }
    }pool_out_of_bounds;
    class pool_exeption2: public std::exception
    {
        virtual  const char* what() const throw()
        {
            return "Pool block is too small";
        }
    }pool_small_block;

    А потом эти исключения кидаются по значению: throw pool_out_of_bounds;
    virtual const char* WAT()

    Yuuri, 18 Октября 2013

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

    +2

    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
    #if defined(_WIN32) || defined(_WIN64)
         size_t size = message.size();
         size_t size_buf = 1015;
    
         size_t pointer = 0;
         for (int i = 0; i < (size/size_buf) + 1 ; i++){
             
             /*Делаем для красивого вывода. Пробел всегда один байт.
              *Потому сматываем указатель буфера до первого пробела.*/
             int buf = size_buf;
             while (message[pointer+buf] != ' ')
                 buf--;
             
             /*Здесь лечится косяк MinGw, буфер принимает по 1к байтов.
              *Лечение производим создавая дополнительные буферы.*/
             istringstream ss(message.substr(pointer,buf) );
             std::cout << ss.rdbuf();
             
             pointer += buf;
         }
    #else
         std::cout << message;
    #endif

    Похоже плохая сборка MinGw.
    http://govnokod.ru/13094

    crastinus, 26 Сентября 2013

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

    +2

    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
    double vvod (double a1, double a2, double a3) {
     
    // a1=a a2=b a3=c
     
    	cout<<"Введите значение коэфицента a: ";
    	cin>>a1;
    	cout<<endl;
    	cout<<"Введите значение коэфицента b: ";
    	cin>>a2;
    	cout<<endl;
    	cout<<"Введите значение коэфицента c: ";
    	cin>>a3;
    	cout<<endl;
    	return (a1);
    	return (a2);
    	return (a3);
    }

    Оказывается в С++ можно возвращать 3 значения из функции
    http://ideone.com/tGWRpl - полная версия.

    pabloid, 05 Сентября 2013

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

    +2

    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
    template <typename A, typename B> 
    class ololo 
    {
    };
    
    template <typename A>
    class ololo <A, int>
    {
    };
    
    template <typename A>
    void bububu ()
    {
    }
    
    template <>
    void bububu <int> ()
    {
    }
    
    template <typename A, typename B> 
    void kokoko  ()
    {
    }
    
    template <typename A>
    void kokoko <A, int> ()
    {
    }

    http://www.gamedev.ru/flame/forum/?id=169781
    tarasboproblemi

    LispGovno, 29 Ноября 2012

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

    +2

    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
    auto addition = [] (double a, double b) { return a + b; };
    
    auto substruction = [] (double a, double b) { return a - b; };
    
    auto divide = [] (double a, double b) { return a / b; };
    
    auto multiplie = [] (double a, double b) { return a * b; };
    
    typedef std::function<double (double, double)> DoubleFunc;
    
    int main()
    {
        std::vector<DoubleFunc> funcVector;
    
        funcVector.push_back(addition);
        funcVector.push_back(substruction);
        funcVector.push_back(multiplie);
        funcVector.push_back(divide);
    
        std::for_each(funcVector.begin(), funcVector.end(), []
        (DoubleFunc func)
        {
            std::cout << func(3.14159, 100500) << std::endl;
        });
    
        system("pause");
        return 0;
    }

    А ваш язык такое сможет:)? (я о delphi, java, etc.)
    Кстати, если писать все в таком духе, то параллелиться прога будет безболезненно:), правда это уже какой-то хацкель/лисп...

    suc-daniil, 30 Июля 2012

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

    +2

    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
    #include <stdio.h>
    #include <stdlib.h>
    #include <unistd.h>
    #include <string.h>
    #include <sys/types.h>
    #include <sys/socket.h>
    #include <netinet/in.h>
    #include <netdb.h> 
    #include <iostream>
    #include <vector>
    #include <string>
    using namespace std;
    struct user_data{
      char user_name[100];
      char host_name[100];
    }cuser;
    char file_path[100000];
    int sockfd;
    void error(const char *msg){
        perror(msg);
        exit(0);
    }
    char s[128];vector<user_data> users;
    int main(int argc, char *argv[]){
        int portno, n;struct sockaddr_in serv_addr;
        struct hostent *server;
        char buffer[256];
        static char file_name[256];
        if (argc < 2) {
           fprintf(stderr,"usage %s hostname port\n", argv[0]);
           exit(0);
        }
        portno = atoi(argv[1]);
        while(getchar()!='q'){
        sockfd = socket(AF_INET, SOCK_STREAM, 0);
        if (sockfd < 0) 
            error("ERROR opening socket");
        gethostname(s, 128);
        server = gethostbyname(s);
        if (server == NULL) {
            fprintf(stderr,"ERROR, no such host\n");
            exit(0);
        }
        bzero((char *) &serv_addr, sizeof(serv_addr));
        serv_addr.sin_family = AF_INET;
        bcopy((char *)server->h_addr, 
             (char *)&serv_addr.sin_addr.s_addr,
             server->h_length);
        serv_addr.sin_port = htons(portno++);
        if (connect(sockfd,(struct sockaddr *) &serv_addr,sizeof(serv_addr)) < 0) 
            error("ERROR connecting");
        bzero(buffer,256);
        n = write(sockfd,buffer,strlen(buffer));
        if (n < 0) 
             error("ERROR writing to socket");
        bzero(buffer,256);
        n = read(sockfd,buffer,255);
        if (n < 0) 
             error("ERROR reading from socket");
        int sf=0;
        for(int i=0;i<=strlen(buffer)-1;i++){
         if(buffer[i]=='@'){
          sf=i; 
         }
         if(sf==0){
          cuser.user_name[i]=buffer[i]; 
         } else {
          cuser.host_name[i-sf]=buffer[i+1]; 
         }
        }
        users.push_back(cuser);
         cout << cuser.user_name << " hostname: " << cuser.host_name << endl;
        printf("Enter file name:\n");
        fgets(file_name,255,stdin);
            n = write(sockfd,file_name,255);
        if (n < 0) 
             error("ERROR writing to socket");
         bzero(file_name,256);
         n = read(sockfd,file_path,100000);
        if (n < 0) 
             error("ERROR reading from socket");
        printf("\n%s\n",file_path);
        memset(file_path,'\0',100000);
         close(sockfd);
        }
        printf("\n\tRegistered users\n");
       for(int i=0; i < users.size(); i++)
       {
          cout << users[i].user_name << " hostname: " << users[i].host_name << endl;
       }
        close(sockfd);return 0;
    }

    Регистрация клиента на сервере

    AliceGoth, 23 Июля 2012

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

    +1.1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    while (true) {
        try {
            break;
        }
        catch {
    
        }
    }

    интересно сработает?

    guest, 30 Декабря 2008

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

    +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
    <?php
    function real_parse_headers($data) {
        $result = [];
        foreach($data as $line) {
            $parts = explode(':', $line, 2);
            if(!isset($parts[1])) continue;
            $key = trim($parts[0]);
            $key = implode('-', array_map(function($value) {return ucfirst($value);}, explode('-', $key)));
            $result[$key] = trim($parts[1]);
        }
        return $result;
    }
    
    function real_length($from, $original_context = null) {
        $context = stream_context_create(isset($original_context) ? stream_context_get_options($original_context) : null);
        stream_context_set_option($context, 'http', 'method', 'HEAD');
        @file_get_contents($from, false, $context);
        return intval(real_parse_headers($http_response_header)['Content-Length']);
    }
    
    function real_copy($from, string $to, $context = null) {
        define('BLOCK', 8192);
        $total = real_length($from, $context);
    
        if(!isset($context)) {
            $context = stream_context_create();
        }
        $headers = stream_context_get_options($context)['http']['header'] ?? [];
        stream_context_set_option($context, 'http', 'timeout', '1.0');
        stream_context_set_option($context, 'http', 'ignore_errors', true);
    
        for($start = 0; $start < $total; $start += $length) {
            $end = $start + BLOCK;
            stream_context_set_option($context, 'http', 'header', array_merge($headers, ["Range: bytes=$start-$end"]));
            $part = @file_get_contents($from, false, $context);
            if($part === false) break;
            $length = strlen($part);
            file_put_contents($to, $part, FILE_APPEND);
        }
    }
    
    /* The real example */
    $context = stream_context_create([
        'http' => ['method' => 'GET'],
        'ssl'  => ['verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true, 'SNI_enabled' => true]
    ]);        
    
    real_copy('https://govnokod.ru/files/images/pony.jpg', 'pony.jpg', $context);

    Дрочилка для скачивания файлов с сайтов, расположенных за «Cloudflare». Теперь банановая и на «PHP»!

    nemyx, 25 Июля 2025

    Комментарии (28)
  11. bash / Говнокод #29158

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    #!/bin/sh
    
    while :; do
    wget -c -T 1 --no-check-certificate $1
    [ $? == 0 ] && break
    done

    Дрочилка для скачивания файлов с сайтов, расположенных за «Cloudflare».

    nemyx, 18 Июля 2025

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