1. 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)
  2. PHP / Говнокод #9154

    +161

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

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

    dancebass, 17 Января 2012

    Комментарии (20)
  3. 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)
  4. 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)
  5. 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)
  6. 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)
  7. 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)
  8. Java / Говнокод #9146

    +69

    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
    package com.govnoistochnik.servleti;
    
    ...
     
    import javax.servlet.GenericServlet;
    ...
     
    public class GenericReportingServlet extends GenericServlet {
    
    ...
    
    public synchronized void  createReport(...)
    {
    // pessot strok govnokoda
    }
    
    public synchronized void service(ServletRequest request, ServletResponse response) throws ServletException, IOException {
    // Kucha govnokoda
       createReport(...);
    // Prodoljeniye kuchi
    }
    
     ...
     
    }

    Хороший пример как сделать однопоточный репортинг сервер.

    Обратите внимание на "synchronized".
    Результат:
    1) Мах Session (200).
    2) Жрёт всю память
    3) Сервер виснет. Никакой Psi prob, Lambda prob ету гадину не выявит.
    4) Хрен найдёшь почему говняет если кода нет.

    kirpi, 17 Января 2012

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

    +969

    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
    public static string ConvertNumberToString(double tmpStr)
            {
                string ret = "";
                try
                {
                    if (((long)tmpStr).ToString().Length > 3)
                    {
                        string len = ((long)tmpStr).ToString();
                        string[] strSplit = tmpStr.ToString().Split(',');
    
                        long tmpM = 0;
                        if (strSplit.Length > 1)
                            tmpM = Convert.ToInt64(strSplit[1]);
    
                        int count = (int)len.Length / 3;
                        ret = len.Substring(0, (len.Length - 3 * count));
                        for (int i = 0; i < count; i++)
                        {
                            ret += " " + len.Substring((ret.Length - i), 3);
                        }
                        if (tmpM > 0)
                        {
                            ret += "," + strSplit[1];
                        }
                    }
                    else
                        ret = tmpStr.ToString();
                }
                catch
                {
                }
                return ret.Trim();
            }

    Из той же оперы...

    yorikim, 17 Января 2012

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

    +126

    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
    public static bool IsLong(string tmpStr)
    {
    	bool blRetVal = true;
    	for (int i = 0; i < tmpStr.Length; i++)
    	{
    		if (tmpStr[i] != '0' && tmpStr[i] != '1' && tmpStr[i] != '2' &&
    			tmpStr[i] != '3' && tmpStr[i] != '4' && tmpStr[i] != '5' &&
    			tmpStr[i] != '6' && tmpStr[i] != '7' && tmpStr[i] != '8' &&
    			tmpStr[i] != '9')
    			blRetVal = false;
    	}
    	return blRetVal;
    }
    
    static public string ConvertDateTimeForSQL(DateTime tmpDateTime)
    {
    	return (
    		tmpDateTime.Year.ToString() + "-" +
    		(tmpDateTime.Month < 10 ? "0" : "") + tmpDateTime.Month.ToString() + "-" +
    		(tmpDateTime.Day < 10 ? "0" : "") + tmpDateTime.Day.ToString() + " " +
    		(tmpDateTime.Hour < 10 ? "0" : "") + tmpDateTime.Hour.ToString() + ":" +
    		(tmpDateTime.Minute < 10 ? "0" : "") + tmpDateTime.Minute.ToString() + ":" +
    		(tmpDateTime.Second < 10 ? "0" : "") + tmpDateTime.Second.ToString());
    }
    
    static public string ConvertDateTimeShortForSQL(DateTime tmpDateTime)
    {
    	return (tmpDateTime.Year.ToString() + "-" +
    		(tmpDateTime.Month < 10 ? "0" : "") + tmpDateTime.Month.ToString() + "-" +
    		(tmpDateTime.Day < 10 ? "0" : "") + tmpDateTime.Day.ToString());
    }
    
    -----------------------------------
    P.S. Версия .NET 3.5

    yorikim, 17 Января 2012

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