1. PHP / Говнокод #9158

    +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
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    $data = "";
    if (isset($_POST["json"]))
     $data = $_POST["json"];
    $send_str = "";
    
     $jsonObj=json_decode($data);
     if(json_last_error() == JSON_ERROR_NONE)
     {
      if ($jsonObj)
      {
       if (strlen($jsonObj->pass) != 32 || strlen($jsonObj->login)==0 || strlen($jsonObj->userName)==0)
       {
        $send_str = '{"RegistrationActionError":{"type":"2"}}';  
       }
       else
       {
        // проверка на совпадение логина
        if ($db->userExists($jsonObj->login))
         $send_str = '{"RegistrationActionError":{"type":"1"}}';
        else
        {
         $user = $db->createUser($jsonObj->login, $jsonObj->pass, $jsonObj->userName, $jsonObj->mail);
         $send_str = '{"RegistrationActionComplete"}';
        }
       }
      }
      else
       $send_str = '{"RegistrationActionError":{"type":"2"}}';
     }
     else
      $send_str = '{"RegistrationActionError":{"type":"2"}}';
    
     echo $send_str;

    Регистрация пользователя написанная человеком который себя позиционирует как пхпе миддл )

    kyzi007, 18 Января 2012

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

    +145

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    class beer
        {public: beer(){beer::in();}
         private: void in();void chek(int);void out(int);};
    main(){beer yeeah;}
    void beer::in()
        {int N;std::cout << "Input N: ";std::cin>>N;int mValue[N];
         for(int i=0;i<N;i++){std::cout << "Input ["<<i+1<<"] = ";std::cin>>mValue[i];}
         for(int i=0;i<N;i++){beer::chek(mValue[i]);};}
    void beer::chek(int Value){for(int i=2;i<Value;i++){if(Value%i==0){return;};};beer::out(Value);}
    void beer::out(int Value){std::cout<<Value<<std::endl;}

    Задачка на 45-50 баллов(по 50 бальной шкале), 2 курс технического ВУЗа

    KesrOne, 18 Января 2012

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

    +141

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    // строка добавлена, чтобы сраный парсер говнокода не сжирал пробелы, этого в коде не было
                  end;
                end;
              end;
            end;
          end;
        end;

    Увидел в своём коде.
    Очень сложный алгоритм.

    TarasB, 18 Января 2012

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

    +150

    1. 1
    2. 2
    3. 3
    4. 4
    if (!isset($pmas_table[0][3])) $pmas_table[0][3]='';
    if (!isset($pmas_table[0][5])) $pmas_table[0][5]='';
    if (!isset($pmas_table[0][6])) $pmas_table[0][6]='';
    if (!isset($pmas_table[0][7])) $pmas_table[0][7]='';

    UserSide v2.48 again. Так как там каждая строчка имеет право быть на этом сайте, выкладываю The best of the best =)

    Neka, 18 Января 2012

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

    +161

    1. 1
    while (!$db->query("INSERT INTO lots (lot_num) VALUES (".($unicnum=rand(1,99999)).")"));

    Проверка и создание уникального рандомного идентификатора

    dancebass, 17 Января 2012

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

    +156

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    string Delimiter(string Text, int Index, const char* Delimiter) {
    	int n = 0, find = 0;
    	for (int i = 0; i <= Index; i++) {
    		find = Text.find(Delimiter, n);
    		if (i == Index) {  
    			return Text.substr(n, find - n);
    		}
    		n = find + 1;
    	}
    	return "";
    }

    FalseCoder, 17 Января 2012

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

    +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
    16. 16
    17. 17
    18. 18
    19. 19
    void inline WriteXY(int X, int Y, byte szText, WORD fColor = 0x01F) {
    	DWORD cWritten;
    	COORD ptCoord = {X - 1, Y - 1};
    	gotoxy(X, Y);
    	cout << char(szText);
    	cout.flush();
    	FillConsoleOutputAttribute(hStdOut, fColor, 1, ptCoord, &cWritten);
    	return;
    }
    
    void inline WriteXY(int X, int Y, string szText, WORD fColor = 0x01F) {
    	DWORD cWritten;
    	COORD ptCoord = {X - 1, Y - 1};
    	gotoxy(X, Y);
    	cout << szText.c_str();
    	cout.flush();
    	FillConsoleOutputAttribute(hStdOut, fColor, strlen(szText.c_str()), ptCoord, &cWritten);
    	return;
    }

    Функция и её прототип

    FalseCoder, 17 Января 2012

    Комментарии (74)
  8. PHP / Говнокод #9151

    +150

    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
    public function run() {
      $stime = microtime(TRUE);
      $this->header('Content-Type: text/html');
      $this->setcookie('testcookie', '1');
      $this->registerShutdownFunction(function() {
    ?></html><?php
      });
    
    ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>It works!</title>
    </head>
    <body>
    <h1>It works! Be happy! ;-)</h1>
    ............
    ............
    ............

    phpDaemon Example.php line 63

    LmSys, 17 Января 2012

    Комментарии (0)
  9. PHP / Говнокод #9150

    +173

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    /*
          if($_REQUEST["act_id"]==8){
          а нет. маньяки так не пишут...
    */
    define("Э", $_REQUEST["act_id"]);
    if( 8===Э ){ 
    	...
    }

    оператор члена :)

    basename, 17 Января 2012

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

    −79

    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
    // Досталось по наследству:
    
    @try {
        if([[items objectAtIndex:indexPath.row] performSelector:@selector(songsArray)]){
            NSArray *songsArray = [[items objectAtIndex:indexPath.row] songsArray];
            for(Song *song in songsArray){
                [song setIsSelected:button.selected];
            }
        }
     }
    @catch (NSException *exception) {
        NSLog(@"need fix in next time");
    }
    
    // переделал в
    if ( [[items objectAtIndex:indexPath.row] respondsToSelector:@selector(songsArray)] )
    {
        NSArray *songsArray = [[items objectAtIndex:indexPath.row] songsArray];
        for(Song *song in songsArray){
             [song setIsSelected:button.selected];
        }
    }

    lime, 17 Января 2012

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