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

    +993

    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
    if(layerHeader.mFlags&AE_ANIM_BEZIER_EFFECT)
    {
    		btlv=(Point*)calloc(layer->frames.size(),sizeof(Point));
    		btlt=(Point*)calloc(layer->frames.size(),sizeof(Point));
    		btrt=(Point*)calloc(layer->frames.size(),sizeof(Point));
    		brtv=(Point*)calloc(layer->frames.size(),sizeof(Point));
    		brtt=(Point*)calloc(layer->frames.size(),sizeof(Point));
    		brbt=(Point*)calloc(layer->frames.size(),sizeof(Point));
    		bbrv=(Point*)calloc(layer->frames.size(),sizeof(Point));
    		bbrt=(Point*)calloc(layer->frames.size(),sizeof(Point));
    		bblt=(Point*)calloc(layer->frames.size(),sizeof(Point));
    		blbv=(Point*)calloc(layer->frames.size(),sizeof(Point));
    		blbt=(Point*)calloc(layer->frames.size(),sizeof(Point));
    		bltt=(Point*)calloc(layer->frames.size(),sizeof(Point));
    }

    lifemaker, 16 Марта 2012

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

    +994

    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
    int main()
    {   
       //выводит на экран среднее арифметическое чисел 1, 3, 5
       std::cout << Mean + 1 + 3 + 5 << std::endl;
       //выводит на экран среднее геометрическое чисел 2, 4, 8
       std::cout << Mean * 2 * 4 * 8 << std::endl;
    }
    
    //реализация
    
    class CMean
    {
       mutable double out;
       mutable size_t cnt;
       mutable size_t type;
    public:
       CMean(): out(0), cnt(0), type(-1)  {}
       CMean& operator + (double n)
       {
          return type = 0, out+= n, ++cnt, *this;   
       }
       CMean& operator * (double n)
       {   
          return (type == (size_t)-1 ? type = 1, out = 1 : 0), out*= n, ++cnt, *this;   
       }
       size_t reset() const {return type = -1, out = cnt = 0;};
       friend std::ostream& operator << (std::ostream&, const CMean&);   
    } Mean;
    
    std::ostream& operator << (std::ostream& _os, const CMean& _arith)
    {
       return _os << (!_arith.type ? _arith.out / _arith.cnt : std::pow(_arith.out, 1.0 / _arith.cnt)) + _arith.reset();
    }

    Вывод на экран арифметической и геометрической прогрессии.

    gooseim, 15 Марта 2012

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

    +999

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    assert(t1.tm_sec == t2.tm_sec);
            assert(t1.tm_min == t2.tm_min);
            assert(t1.tm_hour == t2.tm_hour);
            assert(t1.tm_mday == t2.tm_mday);
            assert(t1.tm_mon == t2.tm_mon);
            assert(t1.tm_year == t2.tm_year);
            assert(t1.tm_wday == t2.tm_wday);
            assert(t1.tm_yday == t2.tm_yday);
            assert(t1.tm_isdst == t2.tm_isdst);

    фрагмент из кода библиотеки SOCI: http://soci.sourceforge.net/

    наконец-то исправили на: assert(memcmp(&t1, &t2, sizeof(std::tm)) == 0);

    niXman, 15 Марта 2012

    Комментарии (27)
  4. 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)
  5. 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)
  6. C++ / Говнокод #9669

    +159

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

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

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

    Комментарии (7)
  7. 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)
  8. 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)
  9. 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)
  10. 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)