1. Си / Говнокод #7037

    +147

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    ...
    char det(char a[4][4])
    { float det;
    det=a[0][0]*(a[1][1]*(a[2][2]*a[3][3]-a[3][2]*a[2][3])-a[1][2]*(a[2][1]*a[3][3]-a[2][3]*a[3][1])+a[1][3]*(a[2][1]*a[3][2]-a[2][2]*a[3][1]))
    -a[0][1]*(-a[1][0]*(a[2][2]*a[3][3]-a[3][2]*a[2][3])-a[1][2]*(a[2][0]*a[3][3]-a[3][0]*a[2][3])+a[1][3]*(a[2][0]*a[3][2]-a[3][0]*a[2][2]))
    +a[0][2]*(-a[1][0]*(a[2][1]*a[3][3]-a[3][1]*a[2][3])+a[1][1]*(a[2][0]*a[3][3]-a[3][0]*a[2][3])+a[1][3]*(a[2][0]*a[3][1]-a[2][1]*a[3][0]))
    -a[0][3]*(-a[1][0]*(a[2][1]*a[3][2]-a[3][1]*a[2][2])+a[1][1]*(a[2][0]*a[3][2]-a[3][0]*a[2][2])-a[1][2]*(a[2][0]*a[3][1]-a[3][0]*a[2][1]));
    return(det);
    }; 
    ...

    http://otvet.mail.ru/question/59918103/

    1_and_0, 23 Июня 2011

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

    +116

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    if ( check < 50000 ) {
        primaryAnimation = primaryAnimation;
    } else {
        int ani = (check - 50000) / 100;
        primaryAnimation = _OptionalAnimations["Run"][ani];
     }

    Найдено в недрах загрузчика MD2-моделек для XNA.

    RaZeR, 23 Июня 2011

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

    +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
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    public void chkStatus_OnCheckedChanged(object sender, EventArgs e)
    {
        CheckBox chkStatus = (CheckBox)sender;
        GridViewRow row = (GridViewRow)chkStatus.NamingContainer;
    
        
        string cid = row.Cells[1].Text;
        bool status = chkStatus.Checked;
    
        
        string constr = @"Server=.\SQLEXPRESS;Database=TestDB;uid=waqas;pwd=sql;";
        string query = "UPDATE Categories SET Approved = @Approved WHERE CategoryID = @CategoryID";
            
        SqlConnection con = new SqlConnection(constr);
        SqlCommand com = new SqlCommand(query, con);
    
        
        com.Parameters.Add("@Approved", SqlDbType.Bit).Value = status;
        com.Parameters.Add("@CategoryID", SqlDbType.Int).Value = cid;
    
        
        con.Open();
        com.ExecuteNonQuery();
        con.Close();
    
        
        LoadData();
    }

    Полезный говнокод

    in4man, 23 Июня 2011

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

    +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
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    // редиректим адреса без слеша на такие же со слешем
    $uri = $_SERVER['REQUEST_URI'];
    $is_file = false;
    if (	(substr_count($uri,".php")>0) or (substr_count($uri,".html")>0)		) {
    	$is_file = true;
    }
    
    if ($is_file == false) {
    	$len_uri = strlen($uri);
    	// находим последнее вхождение слеша
    	$reverst_str = strrev($uri);
    	//die($reverst_str);
    	$last_slash = strpos($reverst_str,"/");
    	
    	//die($last_slash);
    	if  ($last_slash!==0) {
    		
    		$uri .="/";
    		$status = "301 Found";
    		//header("Status: ".$status);
    		header('HTTP/1.1 301 Moved Permanently');
    		header("Location: http://www.thermostudio.ru"."$uri");
    		exit();
    
    	}
    }

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

    nislova, 23 Июня 2011

    Комментарии (14)
  5. Pascal / Говнокод #7033

    +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
    24. 24
    25. 25
    26. 26
    27. 27
    procedure info_();
      var
       i:integer;
       ActivityCategory,stroka,strok,stroka_sopr,http1100,http_sopr,tag,tag_sopr,until_date,date_:string;
       f1100,f_sopr,inf:textfile;
    begin  //главный
    clear();
    if form1.radioGroup1.ItemIndex=0 then begin
                                          http1100:='\\server1\Отдел 1\Program Files\Prof\profiki\1100\'+m+'.smc';
                                          http_sopr:='\\server1\Отдел 1\Program Files\prof\profiki\сопроводительное\'+m+'.smc';
                                          end;
    if form1.radioGroup1.ItemIndex=1 then begin
                                          http1100:='\\server1\Отдел 1\Program Files\Prof\banki\1100\'+m+'.smc';
                                          http_sopr:='\\server1\Отдел 1\Program Files\prof\banki\сопроводительное\'+m+'.smc';
                                          end;
    if form1.radioGroup1.ItemIndex=2 then begin
                                          http1100:='\\server1\Отдел 1\Program Files\Prof\YK\1100\'+m+'.smc';
                                          http_sopr:='\\server1\Отдел 1\Program Files\prof\YK\сопроводительное\'+m+'.smc';
                                          end;
    if form1.radioGroup1.ItemIndex=3 then begin
                                          http1100:='\\server1\Отдел 1\Program Files\Prof\NPF\1100\'+m+'.smc';
                                          http_sopr:='\\server1\Отдел 1\Program Files\prof\NPF\сопроводительное\'+m+'.smc';
                                          end;
    if form1.radioGroup1.ItemIndex=4 then begin
                                          http1100:='\\server1\Отдел 1\Program Files\Prof\REGISTRATOR\1100\'+m+'.smc';
                                          http_sopr:='\\server1\Отдел 1\Program Files\prof\REGISTRATOR\сопроводительное\'+m+'.smc';
                                          end;

    Пытался перенести в другую папку программу, после чего она по сути перестала работать, ругаясь ошибкой 63. Нашел ее исходники и увидел ЭТО... это лишь 5-10% всей процедуры, которая мало того, что ищет XML-файлы по определенному пути, так еще и парсит их...

    GhOsTMZ, 23 Июня 2011

    Комментарии (6)
  6. Java / Говнокод #7032

    +74

    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
    private static java.util.Hashtable<String, Session> sessions =
        new java.util.Hashtable<String, Session>();
    ...
    public static SessionOperations[] getSessions() {
        int cnt = sessions.size();
        SessionOperations[] res = new SessionOperations[cnt];
        java.util.Enumeration<String> e = sessions.keys();
        for( int i = 0; i < res.length; i++ ) {
          String sid = e.nextElement();
          res[i] = sessions.get( sid ).getOperations( sid );
        }
        return res;
    }

    Удаление из sessions между получением размера и набора ключей приводит к весьма печальным последствиям...

    P.S. В результате в течение трех суток в production не удалялись оставленные сессии (без Logout), sessions отожрал 600М и всё свалилось с OOM.

    Skipy, 23 Июня 2011

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

    +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
    #include <a_samp>
    
    new objects[MAX_OBJECTS];
    
    public OnFilterScriptInit()
    {
    	objects[0] = CreateObject(980, -2491.1276855469, -129.08126831055, 27.397054672241, 0, 0, 90.675659179688);
    	objects[1] = CreateObject(980,-2459.8862304688,-152.13926696777,27.652730941772,0,356,0);
        objects[2] = CreateObject(980,-2446.0773925781,-82.466796875,35.984577178955,0,356,0);
    	return 1;
    }
    
    public OnPlayerCommandText(playerid, cmdtext[])
    {
    	if (strcmp("/garage", cmdtext, true, 10) == 0)
    	{
    		MoveObject(objects[0], -2491.1276855469, -129.08126831055, 20, 2);
    		SetTimer("VTimer", 10000, 0);
    		return 1;
    	}
    	return 0;
    }
    
    forward VTimer();
    public VTimer()
    {
    	MoveObject(objects[0], -2491.1276855469, -129.08126831055, 27.397054672241, 2);
    	return 1;
    }

    smith, 23 Июня 2011

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

    +154

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    function getDateFromTime($dataTime){
      $strDate = date('d-m-Y', $dataTime);
      $arrDate = explode('-', $strDate);
    
      return mktime(0, 0, 0, $arrDate[1], $arrDate[0], $arrDate[2]);
    }

    руки-жопа-голова%)

    warider, 23 Июня 2011

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

    +159

    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 AClass::registerApplication( int pCaller )
    {
      if ( mRegistry == NULL )
      {
        // we will be the first application in registry
        mRegistry = createRegistryElement( pCaller );
      }
      else
      {
        // there are other applications already registered
        // first create registry entry
        Application *lApplication = NULL;
        lApplication = createRegistryElement( pCaller );
    
        // put entry in front
        lApplication->mNext = mRegistry;
        mRegistry = lApplication;
      }
    }

    добавляем новый элемент в односвязный список. mRegister голова списка. кто не видит говна - идти читать матчасть.

    Dummy00001, 22 Июня 2011

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

    +153

    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
    try
    			{
    				sw = gcnew StreamWriter(GetIniFileName());
    			}
    			catch(UnauthorizedAccessException^ e)
    			{
    				MessageBox::Show( "Access is denied.", "Ошибка", MessageBoxButtons::OK, MessageBoxIcon::Error );
    				ShowException(dynamic_cast<System::Exception^>(e));
    				return;
    			}
    			catch(ArgumentNullException^ e)
    			{
    				MessageBox::Show( e->ParamName + ": File path is null.", "Ошибка", MessageBoxButtons::OK, MessageBoxIcon::Error );
    				ShowException(dynamic_cast<System::Exception^>(e));
    				return;
    			}
    			catch(ArgumentException^ e)
    			{
    				MessageBox::Show( e->ParamName + ": Wrong file path.", "Ошибка", MessageBoxButtons::OK, MessageBoxIcon::Error );
    				ShowException(dynamic_cast<System::Exception^>(e));
    				return;
    			}
    			catch(DirectoryNotFoundException^ e)
    			{
    				MessageBox::Show( "The specified path is invalid, such as being on an unmapped drive.", "Ошибка", MessageBoxButtons::OK, MessageBoxIcon::Error );
    				ShowException(dynamic_cast<System::Exception^>(e));
    				return;
    			}
    			catch(PathTooLongException^ e)
    			{
    				MessageBox::Show( "The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters. ", "Ошибка", MessageBoxButtons::OK, MessageBoxIcon::Error );
    				ShowException(dynamic_cast<System::Exception^>(e));
    				return;
    			}
    			catch(IOException^ e)
    			{
    				MessageBox::Show( "File path includes an incorrect or invalid syntax for file name, directory name, or volume label syntax. ", "Ошибка", MessageBoxButtons::OK, MessageBoxIcon::Error );
    				ShowException(dynamic_cast<System::Exception^>(e));
    				return;
    			}
    			catch(SecurityException^ e)
    			{
    				MessageBox::Show( "The caller does not have the required permission." + e->ToString(), "Ошибка", MessageBoxButtons::OK, MessageBoxIcon::Error );
    				ShowException(dynamic_cast<System::Exception^>(e));
    				return;
    			}
    			catch(System::Exception^ e)
    			{
    				ShowException(e);
    				return;
    			}

    Обработка исключений.

    ScumCoder, 22 Июня 2011

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