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

    +115

    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
    #include "iostream"
    
    using namespace std;
    
    int main()
    {
    	cout << "Vvedite storonu a:";
    	int a;
    	cin >> a;
    	cout << "Vvedite storonu b:";
    	int b;
    	cin >> b;
    	cout << "Vvedite storonu c:";
    	int c;
    	cin >> c;
    	int g=1;
    	while(g=1){
    		if(a==0||b==0||c==0){ cout << "Ne treugolnik";
    		break;}
    		if(a<=b+c || c<=a+b || b<=a+c){ cout << "Daaa!!! Treugolnik";}
    		break;}
    	return 0;
    }

    Вот как мы узнаем, треугольник ли это по сторонам.

    hromjo, 11 Мая 2010

    Комментарии (14)
  2. Assembler / Говнокод #3194

    +225

    1. 1
    2. 2
    fstp qword [tmp]
    fild qword [tmp]

    суровое округление через память

    3.14159265, 11 Мая 2010

    Комментарии (26)
  3. Си / Говнокод #3193

    +136

    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
    int check_process(pid_t pid, char *search) {
      char file[1024], buf[1024];
      FILE *FH=NULL;
      int rc, ret=0;
    
      snprintf(file, 1024, "/proc/%d/cmdline", pid);
      rc = check_file(file);
      if (!rc) {
        // cmdline exists
        ret = 1;
        if (search) {
          // check if cmdline contains 'search'
          FH = fopen(file, "r");
          if (FH) {
    	bzero(buf, 1024);
    	while(fgets(buf, 1024, FH)) {
    	  char *p;
    	  while((p = memchr(buf, '\0', 1024))) {
    	    *p = 'X';
    	  }
    	  buf[1023] = '\0';
    	  if (strstr(buf, search)) {
    	    ret = 0;
    	  }
    	}
    	fclose(FH);
          }
        } else {
          ret = 0;
        }
      } else {
        ret = 1;
      }
      return(ret);
    }

    Суровые калифорнийские студенты суровы.

    raorn, 11 Мая 2010

    Комментарии (1)
  4. Java / Говнокод #3192

    +75

    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
    private void changeName() throws Exception {
        File inFile = new File(torrentFilePath);
        File outFile = new File(torrentFilePath + Hashes.getRandom(6));
        BufferedInputStream inStream = new BufferedInputStream(new FileInputStream(inFile));
        BufferedOutputStream outStream = new BufferedOutputStream(new FileOutputStream(outFile));
    
        int bytesRead;
        int totalBytesRead = 0;
        byte[] bytes = new byte[1024];
        String inString = "";
    
        while((bytesRead = inStream.read(bytes)) > 0) {
            inString += new String(bytes, 0, bytesRead);
            totalBytesRead += bytesRead;
        }
        inStream.close();
        int len = inString.length();
        int idx = inString.indexOf(NAME_TAG);
        int lastidx = inString.indexOf(objectName) + objectName.length();
    
        outStream.write(bytes, 0, idx + NAME_TAG.length());
        outStream.write(new String(objectKey.length() + ":" + objectKey).getBytes());
        outStream.write(bytes, lastidx, totalBytesRead - lastidx);
    
        outStream.close();
        outFile.renameTo(inFile);
    }

    Горячий привет из солнечной Калифорнии. Таким образом студенты из Университета Санта-Барбары меняют имя файла в торренте.

    raorn, 11 Мая 2010

    Комментарии (0)
  5. Си / Говнокод #3191

    +136

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    if (init) {
    } else {
      // thread is not initialized, run first time local state setup
      ...
    }

    raorn, 11 Мая 2010

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

    +144

    1. 1
    2. 2
    3. 3
    4. 4
    string buf;
    ...
    char c_buf[MAX_LEN];
    strncpy(c_buf, buf.c_str(), MAX_LEN);

    в чём ошибка?

    skor4ik, 10 Мая 2010

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

    +103

    1. 1
    2. 2
    3. 3
    4. 4
    private ListBoxItem FindItem(string guid)
    {
            return _userlist.Items.Cast<ListBoxItem>().FirstOrDefault(item => ((TextBlock) ((StackPanel) item.Content).Children[1]).Text == guid);
    }

    Функция поиска элемента в ListBox по значению Guid в одну строку. Наговнокодил ReSharper.

    botinko, 09 Мая 2010

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

    +116

    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
    struct Epica
    {
    public:
    	signed int Value;
    };
    
    //...
    
    Epica* ValEp[10][17]; 
    
    //...
    
    ValEp[i][jj][0].Value;

    Угадайте, что с автором?

    Говногость, 09 Мая 2010

    Комментарии (14)
  9. Perl / Говнокод #3187

    −122

    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
    sub PrintToFile {
    	
    	my ($filename, @file) = @_;
    	
    	@file = sort {$a <=> $b} @file;
    	
    	open BK, ">backup.txt";
    	foreach $line(@file) {
    		print BK "$line";
    	}
    	close BK;
    	
    	rename "backup.txt", "$filename";
    	unlink "backup.txt";
    	
    }

    А вот так мы записываем в файл. И нас не интересует многопоточность или проверка имени файла (в вызывающей функции тоже нет). А не записать ли нам ../index.html?

    Прошу не кидаться калом. Первый раз вижу перл. Может быть так и надо? Волшебник-интерприатор все поправит, и не даст сучиться ужасному?

    ps взято с разломанного недображелателем хостинга, для того, чтобы "поправить все как следует".

    da4ever, 09 Мая 2010

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

    +167

    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
    abstract class DataBaseConnection {
      static public  $user   = "root";
      static private $pass   = "";
      static private $host   = "localhost";
      static private $dbName = "example";
    
      //this method creates connection to server and selects data base    
      static public function dbConnect () {
            //initialize connection variables 
            $host   = self :: $host;
            $dbName = self :: $dbName;
            $pass   = self :: $pass;
            $user   = self :: $user;
            // connect to server
            $connection = mysql_connect ( $host, $user, $pass, TRUE ) or die ("DATA BASE CONNECTION FAIL : " . mysql_error());
            // select database
            mysql_select_db ( $dbName, $connection ) or die ("DATA BASE HAS NOT BEEN SELECT");
            //set query encoding
            mysql_query("set names utf8") or die("set names utf8 failed") ;  
            
            return $connection;
      }
    }
    
    DataBaseConnection :: $user = "root";
     
    $connection = DataBaseConnection :: dbConnect ();

    kkkoi8r, 08 Мая 2010

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