1. C++ / Говнокод #9681

    +1002

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    template<class _CharType>
    bool check_arith(const _CharType* str)
    {
       for(; *str ; ++str)
          for(unsigned long long j = 0x6165696F7579ull; j; j >>= 8)
            if(((j & 0xFF) | 0x20) == (*str | 0x20))
               return true;
       return false; 
    }

    Функция, которая проверяет, есть ли в слове гласные буквы латинского алфавита с учетом регистра.

    gooseim, 15 Марта 2012

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

    +149

    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
    #include <iostream>
    #define caseop(op, code) case op: code; break;
    #define clamp(a, lo, hi) (a < lo) ? (a = lo) : (a > hi) ? (a = hi) : a;
    void main(int argc, char* args[]) {
    	FILE *srcfile = fopen(argc > 1 ? args[1] : "", "r");
    	(!srcfile) ? exit(0) : fseek(srcfile, 0, SEEK_END);
    	unsigned char bytes[1024], *byte = bytes;
    	int x = ftell(srcfile), bs = sizeof(bytes);
    	rewind(srcfile);
    	char *source = new char[x + 1], *token = source, *ret = token;
    	fread(source, sizeof(char), x, srcfile);
    	memset(&bytes, source[x] = (char)fclose(srcfile), bs--);
    	do { 
    		switch(*token) {
    			caseop('+', ++(*byte));
    			caseop('-', --(*byte));
    			caseop('.', std::cout << *byte);
    			caseop(':', std::cout << (int)*byte);
    			caseop(',', std::cin >> *byte);
    			caseop('>', clamp(++byte, bytes, &bytes[bs]));
    			caseop('<', clamp(--byte, bytes, &bytes[bs]));
    			caseop('[', if (*byte == (x = 1) - 1) while ((*token++) && (x += *token == '[' ? 1 : *token == ']' ? -1 : 0)); else ret = token);
    			caseop(']', if (*byte) token = ret);
    		}
    	} while(*token++);
    	delete source;
    }

    Интерпретатор брэинфака

    hexman, 14 Марта 2012

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

    +159

    1. 1
    const TWindow window(TWindowKindController::TWindowID WindowName, bool& isMainWindow=*(bool*)NULL)

    Крупный проЭкт.
    Мне кажется или с isMainWindow что-то не чисто?

    Говногость, 14 Марта 2012

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

    +988

    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
    #include <iostream>
    #include <windows.h>
    using namespace std;
    
    unsigned long calculateTime( int, int );
    void turnOff();
    
    int main()
    {
        // вводим кол-во часов и минут, которые надо ждать
        int hours, minutes;
        cin >> hours >> minutes;
        
        // ждем нужное время
        unsigned long timer = calculateTime( hours, minutes );
        Sleep( timer );
        
        
        turnOff();          // выключаем компьютер
        return 0;
    }
    
    // подсчет кол-во миллисекунд в указанном времени
    unsigned long calculateTime( int hours, int minutes )
    {
        unsigned long timer = 0;
        
        timer += hours * 3600000;
        timer += minutes * 60000;
        
        return timer;
    }
    
    // выключение компьютера
    void turnOff()
    {
        WinExec( "shutdown -s -t 0", SW_HIDE );
    }

    Я сделал. Что-то вроде автовыключалки для компьютера.
    Разъясните, пожалуйста, где автор неправ и почему.

    vortexx1, 11 Марта 2012

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

    +156

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    if (coms->Strings[1]=="install") {
              if (GetFile("localhost",WinDir+comms->Strings[3]) {
                execCommand=true;
              }else{
                execCommand=false;
              }

    вот такое вот чудо нашел в одном проЭкте предыдущего програмера, который до меня работал)
    вместо localhost передавалось имя файла на сервере

    stasuss, 07 Марта 2012

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

    +997

    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
    char* CFastSmtp::_formatHeader()
    {
    // check for at least one recipient
        if(Recipients.size() <= 0 )    {
            printf("Please add a message recipient!\r\n");
            return NULL;
        }
        int s=0;
        char *msgHeader = new char[16385];
        //char to[1024];
        for (unsigned int i=s=0;i<Recipients.size();i++) {        
            s+=strlen(Recipients.at(i)->GetEmail())+1;
        } if (s==0) s=1; char *to = new char[s];
        //char cc[1024];
        for (i=s=0;i<CCRecipients.size();i++) {        
            s+=strlen(CCRecipients.at(i)->GetEmail())+1;
        } if (s==0) s=1; char *cc = new char[s];
        //char bcc[1024];
        for (i=s=0;i<BCCRecipients.size();i++) {        
            s+=strlen(BCCRecipients.at(i)->GetEmail())+1;
        } if (s==0) s=1; char *bcc = new char[s];
    
        TCHAR szDate[500];
        TCHAR sztTime[500];
    
    // create the recipient string, cc string, and bcc string
        to[0] = '\0';        
        for (i=0;i<Recipients.size();i++) {        
            i > 0 ? strcat(to,","):strcat(to,"");
            strcat(to,Recipients.at(i)->GetEmail());
        }
    
        cc[0] = '\0';    
        for (i=0;i<CCRecipients.size();i++) {
            i > 0 ? strcat(cc,","):strcat(cc,"");
            strcat(cc,CCRecipients.at(i)->GetEmail());
        }
    
        bcc[0] = '\0';    
        for (i=0;i<BCCRecipients.size();i++) {
            i > 0 ? strcat(bcc,","):strcat(bcc,"");
            strcat(bcc,BCCRecipients.at(i)->GetEmail());
        }
    // get the current date and time
        SYSTEMTIME st={0};
        ::GetSystemTime(&st);
        ::GetDateFormat(LOCALE_SYSTEM_DEFAULT,0,&st,"ddd',
                        ' dd MMM yyyy",szDate,sizeof(szDate));
        ::GetTimeFormat(LOCALE_SYSTEM_DEFAULT,TIME_FORCE24HOURFORMAT,&st,
                        "HH':'mm':'ss tt",sztTime,sizeof(sztTime));
    // here it is...the main data of the message
        wsprintf(msgHeader,"DATE: %s %s\r\n", szDate, sztTime);    
        if (m_pcFromName != NULL) {
            strcat(msgHeader,"FROM: ");
            strcat(msgHeader, m_pcFromName);
            strcat(msgHeader, "\r\n");
        }
        strcat(msgHeader,"To: ");
        strcat(msgHeader, to);
        strcat(msgHeader, "\r\n");
        strcat(msgHeader,"Cc: ");
        strcat(msgHeader, cc);
        strcat(msgHeader, "\r\n");
        if (m_pcSubject != NULL) {
            strcat(msgHeader, "Subject: ");
            strcat(msgHeader, m_pcSubject);
            strcat(msgHeader, "\r\n");
        }
        if (m_pcXMailer != NULL) {
            strcat(msgHeader,"X-Mailer: ");
            strcat(msgHeader, m_pcXMailer);
            strcat(msgHeader, "\r\n");
        }
    // start optional fields
        if (m_pcReplyTo != NULL) {
            strcat(msgHeader, "Reply-To: ");
            strcat(msgHeader, m_pcReplyTo);
            strcat(msgHeader, "\r\n");
        }
    // start MIME versions
        strcat(msgHeader, 
               "MIME-Version: 1.0\r\nContent-type: text/plain; charset=US-ASCII\r\n");
    // send header finish command
        strcat(msgHeader, "\r\n");    
    // clean up
        delete to;
        delete cc;
        delete bcc;
    // done    
        return msgHeader;    
    }

    аццкий говнокодер
    http://www.codeproject.com/Articles/623/CFastSmtp-Fast-and-easy-SMTP-class

    63F45EF45RB65R6VR, 07 Марта 2012

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

    +997

    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
    static std::string printFloatNumber(float num,bool friendly=false)
    {
    	std::ostringstream out ;
    
    	if(friendly)
    	{
    		char tmp[100] ;
    		std::string units[4] = { "B/s","KB/s","MB/s","GB/s" } ;
    
    		int k=0 ;
    		while(num >= 800.0f && k<5)
    			num /= 1024.0f,++k;
    
    		sprintf(tmp,"%3.2f %s",num,units[k].c_str()) ;
    		return std::string(tmp) ;
    	}
    	else
    	{
    		out << num ;
    		return out.str() ;
    	}
    }

    Исходники RetroShare - это просто шедевр!

    rat4, 04 Марта 2012

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

    +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
    #ifdef P3TURTLE_DEBUG
    	std::cerr << "performing search. OwnId = " << mLinkMgr->getOwnId() << std::endl ;
    #endif
    	while(mLinkMgr->getOwnId() == "")
    	{
    		std::cerr << "... waitting for connect manager to form own id." << std::endl ;
    #ifdef WIN32
    		Sleep(1000) ;
    #else
    		sleep(1) ;
    #endif
    	}

    trunk/libretroshare/src/turtle/p3turtle.cc

    rat4, 04 Марта 2012

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

    +158

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    // easy-to-use function for use printf-formatting with stl-strings
    std::string StrFormat(const char* fmt,...);
    
    void MakeBackup(const char* dataTime)
    {
    	std::string name = StrFormat("%s", dataTime);
    	...
    }

    lifemaker, 03 Марта 2012

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

    +159

    1. 1
    2. 2
    3. 3
    4. 4
    double KoDeData::toDouble(bool realValue)
    {
        return this->value(realValue).toInt();
    }

    Часа два искал почему вместо 1.7 выводится 2.

    ir4y, 03 Марта 2012

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