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

    +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
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    while(myBot.loop) {
                    sleep(15);
                    myBot.connect(false);
    
                    while(myBot.loop) {
                            if(myBot.client->recv( 750000 )!=ConnNoError) {
                                   	break;
                            } else {
                                    hostent * record = gethostbyname(myBot.client->server().c_str());
                                   	if(record == NULL) {
                                            break;
                                    }
                           	}
                    }
    
                    myBot.disconnect();
           	}

    Бот на gloox. В строчках с 5 по 14 проверяется, не пропал ли линк, и пытается реконнектится, если, собственно, пропал.

    kainwinterheart, 14 Августа 2010

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

    +160

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    void log(string srv, string text) {
                    time_t rawtime; tm * ptm; time ( &rawtime ); ptm = gmtime ( &rawtime );
                    ofstream logfile(LOG, ios::app);
                    logfile << (ptm->tm_year+1900) << "-" << (ptm->tm_mon+1) << "-" << ptm->tm_mday << " "
                            << (ptm->tm_hour+MSD%24) << ":" << ptm->tm_min << ":" << ptm->tm_sec << endl << srv << ":\t" << text << endl << endl;
                    logfile.close();
            }

    Жистоке, брутальне логирование.

    kainwinterheart, 14 Августа 2010

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

    +155

    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
    typedef unsigned char byte;
    
    byte masks[] =
    {
    	0,
    	0x1,
    	0x3,
    	0x7,
    	0xF,
    	0x1F,
    	0x3F,
    	0x7F,
    	0xFF
    };
    
    class RegionBool
    {
    public:
    	RegionBool(unsigned int width, unsigned int height) : w_(width), h_(height), arr_(0), lineLenBytes_(0)
    	{
    		double lineLenBytes = 0;	// байт на строку
    		byte strLenAddBits = static_cast<byte>(modf(static_cast<double>(w_) / 8, &lineLenBytes) * 8);
    		lineLenBytes_ = static_cast<long>(lineLenBytes) + ((strLenAddBits > 0) ? 1 : 0);
    
    		long bytes = lineLenBytes_ * h_;
    		arr_ = new byte[bytes];
    		memset(arr_, 0, bytes);
    	}
    
    	virtual ~RegionBool()
    	{
    		delete[] arr_;
    	}
    
    	inline byte* createLineMask(int x, int w)
    	{
    		// Hey! Attention, animal! Me is you. Listen: you can replace "masks[i]" with "(0xFF >> (8-i))". ХЗ, хав ит фастер.
    
    		byte* mask = new byte[lineLenBytes_];
    		memset(mask, 0, lineLenBytes_);
    
    		double skipBytes = 0;
    		byte startSkipBits = static_cast<byte>(modf(static_cast<double>(x) / 8, &skipBytes) * 8);
    		byte* pmask = mask + static_cast<int>(skipBytes);
    
    
    		byte before = (startSkipBits) ? (8 - startSkipBits) : 0;
    		if (before > w)
    			*pmask |= (masks[w] << startSkipBits);
    		else
    		{
    			if (before)
    				*pmask++ |= (masks[before] << startSkipBits);
    
    			double fillBytes = 0;
    			byte after = static_cast<byte>(modf(static_cast<double>(w - before) / 8, &fillBytes) * 8);
    			
    			if (fillBytes)
    			{
    				memset(pmask, 0xFF, static_cast<int>(fillBytes));
    				pmask += static_cast<int>(fillBytes);
    			}
    
    			if (after)
    				*pmask |= masks[after];
    		}
    
    		return mask;
    	}
    
    	virtual void OR(int x, int y, unsigned int w, unsigned int h)
    	{
    		byte* mask = createLineMask(x,w);
    
    		unsigned int lim = y + h;
    		byte* cur = arr_ + (y * lineLenBytes_);
    		for (unsigned int ty = y; ty < lim; ty++)
    		{
    			byte* m = mask;
    			for (int i = 0; i < lineLenBytes_; i++)
    				*cur++ |= *m++;
    		}
    		delete[] mask;
    	}
    
    private:
    	long lineLenBytes_;
    	unsigned int w_;
    	unsigned int h_;
    	unsigned char* arr_;
    };

    Простите, что много букв.
    Подобие региона, в котором пиксель представлен битом. Операции предполагаются только с прямоугольниками, подразумевается, что прямоугольники вмещаются в регион.
    Рассказывайте мне про меня))

    Altravert, 13 Августа 2010

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

    +142

    1. 1
    2. 2
    string a = "Hello World!";
    printf("%s", a);

    sergylens, 12 Августа 2010

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

    +163

    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
    typedef char char_array_2 [2] ;
    typedef char char_array_3 [3] ;
    typedef char char_array_22[32];
    
    /* ... */
    
    if( 0 == (purpose          = new char_array_3[ dArraySize ]  ) )
    {
       ALLOC_ERROR();
    }
    
    if( 0 == (mode             = new char_array_3[ dArraySize ]  ) )
    {
       ALLOC_ERROR();
    }
    
    if( 0 == (state            = new char_array_2[ dArraySize ]  ) )
    {
       ALLOC_ERROR();
    }
    
    if( 0 == (referencedate    = new char_array_22[ dArraySize ] ) )
    {
       ALLOC_ERROR();
    }
    
    /* и еще десяток в таком же стиле */

    С++ в (болгарские) массы. и пусть только попробуют сказать что мы ошибок выделения памяти не обрабатываем.

    ЗЫ самый прикол что код который этой памятью пользуется 100% совместим с std::vector<std::string>. хотя я бы лично все строки в структуру загнал (и структуры в вектор) бо 10+ массивов это говно.

    Dummy00001, 12 Августа 2010

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

    +163

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    foo(int objType)
    {
      std:string sObjType;
      char outStr[256];
      memset(outStr,NULL,256);
      sprintf(outStr,"0x%x",(unsigned int)objType);
      sObjType = outStr;
      //…
      std::ostringstream str;
      str << "Ready: list of objects, type " << sObjType;
      TRACE(str.str());
    }

    belca, 10 Августа 2010

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

    +152

    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
    bool Pl::load(QString &path){
        if(path.isEmpty()){
            return false;
        }
        QFile file(path);
        if(!file.exists()){
            return false;
        }
        file.open(QIODevice::ReadOnly | QIODevice::Text);
        file.setTextModeEnabled(true);
        if(!file.isOpen()){
            return false;
        }
        QString str;
        QString title;
        while(file.bytesAvailable() > 0){
        str = QString::fromUtf8(file.readLine(1024).trimmed());
            if(str.isEmpty()){
                continue;
            }
            else{
                if(str.at(0) == '#' && title.isEmpty()){
                    if(str.left(10) == "#EXTINF:0,"){
                        title = str.mid(10);
                    }
                    else{
                        title = "";
                    }
                }
            }
            if(this->addTrack(str, title)){
                title = "";
            }
            else{
                QUrl _u(str);
                if(this->addURL(_u, title)){
                    title = "";
                }
            }
        }
        file.close();
        return true;
    }

    Некий кусок кода для парсинга m3u от товарища POPSul

    cutwater, 07 Августа 2010

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

    +157

    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
    struct Vertex
    {
    	float x, y, z;
    	float tu0, tv0;
    } vertices[20000] = 
    {
    	-X,  0,  Z, 0, 0,
    	 X,  0,  Z, 0, 0,
    	-X,  0, -Z, 0, 0, 
    	 X,  0, -Z, 0, 0,
    
    	 0,  Z,  X, 0, 0,
    	 0,  Z, -X, 0, 0,
    	 0, -Z,  X, 0, 0,
    	 0, -Z, -X, 0, 0,
    
    	 Z,  X,  0, 0, 0,
    	-Z,  X,  0, 0, 0,
    	 Z, -X,  0, 0, 0,
    	-Z, -X,  0, 0, 0,
    };

    Kirinyale, 06 Августа 2010

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

    +151

    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
    std::string wbfunc(std::string& hash)
    {
       std::string line;
       std::ifstream f("/home/hromjo/q");
       int l = 0;
       while (std::getline(f, line))
       {
          std::cout << "Перебор: " << l << "паролей." << "\n";
          l++;
          if (md5(line) == hash)
          {
            return line;
            break;
          }
       }
    }

    Возможно слегка не в тему.
    Писал я и хочу проверить, говнокод ли это.
    И что можно исправить в этом говнокоде.

    hromjo, 04 Августа 2010

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

    +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
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    int main() {
    	srand(time(NULL));
    	for (int k=1;k<=75;k++) {
    		char file_name[] = "input      ";
    		if (k<10) {file_name[5]='0'; file_name[6]=(k+'0'); } else
    		{
    			file_name[5]=(k/10+'0'); file_name[6]=(k%10+'0');
    		}
    		file_name[7]='.'; file_name[8]='t'; file_name[9]='x'; file_name[10]='t';
    		freopen(file_name,"wt",stdout);
    		n=rand()%500+1;
    		m=rand()%500+1;
    		cout << n << " " << m << endl;
    		for (i=0;i<n;i++) {
    			for (j=0;j<m;j++)
    				cout << rand()%10000000+1 << " ";
    			cout << endl;
    		}
    	}
    	return 0;
    }

    jfn, 03 Августа 2010

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