1. Лучший говнокод

    В номинации:
    За время:
  2. PHP / Говнокод #5886

    +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
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    /**
         * 
         * Remove single symbols
         * string $text
         */
        public function removeSingleSymbols($text)
        {
            mb_internal_encoding("UTF-8");
            $searchQuery = str_replace('"', '', $text);
            $arr = explode(" ", $searchQuery);
           
            $flag = false;
            foreach ($arr as $word){
                if(mb_strlen($word) > 1){
                    if(flag){
                        $searchText .= " ";
                    }
                    $flag = true;
                    $searchText .= $word;
                }
            }
            $searchText = trim($searchText);
            if($flag){
               $searchText = '"' . $searchText . '"';
            }else{
               $searchText = '';
            }
            
            return $searchText;
        }

    blackray, 04 Марта 2011

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

    +137

    1. 1
    printf("%u\t%u\t%u\t%u\t%u\t%u\t%u\t%u\t%u\t%u\t%f\t%u\t%u\t%u\t%u\t%u\t%u\t%u\t%u\t%u\t%u\t%u\t%u\t%u\t%u\t", ...

    vayerx, 02 Марта 2011

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

    +166

    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
    $url=$_SERVER['REQUEST_URI'];
    $url9=substr($url,0,9);
    $url8=substr($url,0,8);
    $url14=substr($url,0,14);
    $url10=substr($url,0,10);
    $url5=substr($url,0,5);
    if ($url9=='/calendar') {
    printf('<!-- (C)2000-2010 Gemius SA - gemiusAudience / sitecom / Calendar -->
    <script type="text/javascript">
    <!--//--><![CDATA[//><!--
    var pp_gemius_identifier = new String(\'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\');
    //--><!]]>
    </script>
    <script type="text/javascript" src=" http://site.com/gemius/xgemius.js"></script>');
    }elseif ($url8=='/content'){
    printf('<!-- (C)2000-2010 Gemius SA - gemiusAudience / sitecom / Content -->
    <script type="text/javascript">
    <!--//--><![CDATA[//><!--
    var pp_gemius_identifier = new String(\'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\');
    //--><!]]>
    </script>
    <script type="text/javascript" src=" http://site.com/gemius/xgemius.js"></script>');
    }
    elseif ($url14=='/forum_arch'){
    printf('<!-- (C)2000-2010 Gemius SA - gemiusAudience / sitecom / Forum archiv -->
    <script type="text/javascript">
    <!--//--><![CDATA[//><!--
    var pp_gemius_identifier = new String(\'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\');
    //--><!]]>
    </script>
    <script type="text/javascript" src=" http://site.com/gemius/xgemius.js"></script>');
    }
    elseif ($url10=='/forum/'){
    printf('<!-- (C)2000-2010 Gemius SA - gemiusAudience / sitecom / Forum pages -->
    <script type="text/javascript">
    <!--//--><![CDATA[//><!--
    var pp_gemius_identifier = new String(\'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\');
    //--><!]]>
    </script>
    <script type="text/javascript" src=" http://site.com/gemius/xgemius.js"></script>');
    }
    elseif ($url5=='/news'){
    printf('<!-- (C)2000-2010 Gemius SA - gemiusAudience / sitecom / News -->
    <script type="text/javascript">
    <!--//--><![CDATA[//><!--
    var pp_gemius_identifier = new String(\'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\');
    //--><!]]>
    </script>
    <script type="text/javascript" src=" http://site.com/gemius/xgemius.js"></script>');
    }
    else {
    printf('<!-- (C)2000-2010 Gemius SA - gemiusAudience / sitecom / Glavnaja stranitsa sajta -->
    <script type="text/javascript">
    <!--//--><![CDATA[//><!--
    var pp_gemius_identifier = new String(\'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\');
    //--><!]]>
    </script>
    <script type="text/javascript" src=" http://site.com/gemius/xgemius.js"></script>');
    }

    Вместо xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxx в коде оригинальные id счетчиков. Это всё чудо лежит в базе и выполняется через eval()

    nergalic, 01 Марта 2011

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

    +159

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    $difference = strtotime($VipAcc['DateTime']) - time();
    
    $d = floor($difference/60/60/24);
    $h = floor(($difference - $d*60*60*24)/60/60);
    $m = floor(($difference - $d*60*60*24 - $h*60*60)/60);

    так и не выучил функций по работе со временем

    ($VipAcc['DateTime'] - значение взято з базы)

    Sergunik, 28 Февраля 2011

    Комментарии (3)
  6. JavaScript / Говнокод #5817

    +162

    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
    <script language="javascript" src="http://media.fastclick.net/w/get.media?sid=24280&m=1&tp=5&d=j&t=n"></script><noscript><a href="http://media.fastclick.net/w/click.here?sid=24280&m=1&c=1" target="_blank"><img src="http://media.fastclick.net/w/get.media?sid=24280&m=1&tp=5&d=s&c=1"width=728 height=90 border=1></a></noscript> 
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
    <title>unstyled form</title>
    <script type="text/JavaScript">
    <!--
    function myF(targ,selObj,restore){
      eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
      if (restore) selObj.selectedIndex=0;
    }
    //-->
    </script>
    </head>
    
    <body>
    <form id="form1">
    	<select name="menu1" onchange="myF('parent',this,0)">
    		<option>Return to home page</option>
    		<option>Contact</option>
    		<option>unnamed1</option>
    	</select>
    </form>
    </body>
    </html>

    С новым 1993-им годом!

    xxx, 28 Февраля 2011

    Комментарии (3)
  7. Java / Говнокод #5790

    +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
    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
    public static void getShops(Favorite favoriteBrands,
    			Favorite favoriteShops, StationItem station,
    			WorkingTimeFilter workTimeFilter, boolean[] filter, String keyword,
    			GeoLocationPointItem userLocation,
    			GeoLocationPointItem searchLocation, String catalogId,
    			String netId, String page, String pageSize, String api,
    			AsyncTask callback, ConnectionWatcher watcher) {
    //...
    //упаковка кучи параметров
    
    
    		boolean emptyFavBrands = false;
    		if (favoriteBrands != null) {
    			int i = 0;
    			for (FavoriteItem item : favoriteBrands) {
    				String id = item.getId();
    				Log.i(tag, "addFaforiteBrand " + id);
    				params.add(new BasicNameValuePair(PARAMS_FAVORITE_BRAND_ID
    						+ "[" + i + "]", id));
    				i++;
    			}
    			if (i == 0)
    				emptyFavBrands = true;
    		}
    
    		boolean emptyFavShops = false;
    		if (favoriteShops != null) {
    			int i = 0;
    			for (FavoriteItem item : favoriteShops) {
    				String id = item.getId();
    				Log.i(tag, "addFaforiteShop " + id);
    				params.add(new BasicNameValuePair(PARAMS_FAVORITE_SHOP_ID + "[" + i
    						+ "]", id));
    				i++;
    			}
    			if (i == 0)
    				emptyFavShops = true;
    		}
    
    		boolean error = false;
    
    		if (emptyFavBrands && emptyFavShops) {
    			if (favoriteBrands != null || favoriteShops != null)
    				error = true;
    		}
    
    		if (emptyFavShops) {
    			if (favoriteBrands == null && favoriteShops != null)
    				error = true;
    		}
    
    		if (emptyFavBrands) {
    			if (favoriteBrands != null && favoriteShops == null)
    				error = true;
    		}
    
    		if (error) {
    			callback.onError(JsonEntity.FAVORITE_ERROR, new IOException());
    			return;
    		}
    }

    Обращение к веб-сервису. Вызов этого метода при переносе IDE "растекается" на 5-6 строк.
    Самое интересное - проверка корректности параметров находится в самом конце метода (длиной 150 строк)

    rphx, 23 Февраля 2011

    Комментарии (3)
  8. SQL / Говнокод #5782

    −143

    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
    IF @Detail is not null
          AND (SELECT
                COUNT(AppraisalResponseID)
                FROM AppraisalResponseHistory
                WHERE AppraisalResponseID = @AppraisalResponseID) >0
          BEGIN
                INSERT INTO AppraisalResponseHistory 
                ( AppraisalResponseID, 
                      PermissionID, 
                      AppraisalTypeQuestionPromptID, 
                      Detail, 
                      ModifiedDate, 
                      PersonID )
          
                SELECT AppraisalResponse.ID, 
                      AppraisalResponse.PermissionID,
                       AppraisalResponse.AppraisalTypeQuestionPromptID,
                       AppraisalResponse.Detail, 
                      AppraisalResponse.ModifiedDate,
                      PersonID
                FROM AppraisalResponse
                WHERE AppraisalResponse.ID=@AppraisalResponseID AND AppraisalResponse.Detail<>@Detail
          
          END
    ELSE
          IF COALESCE(@Detail, '') = ''
    --if the reviewer is inserting a blank record after having filled in a response, insert into history
    --if the blank record is the place holder, do not insert into history
          AND (SELECT
                COUNT(AppraisalResponseID)
                FROM AppraisalResponseHistory
                WHERE AppraisalResponseID = @AppraisalResponseID) >0
          BEGIN
                INSERT INTO AppraisalResponseHistory 
                ( AppraisalResponseID, 
                      PermissionID, 
                      AppraisalTypeQuestionPromptID, 
                      Detail, 
                      ModifiedDate, 
                      PersonID )
          
                SELECT AppraisalResponse.ID, 
                      AppraisalResponse.PermissionID,
                       AppraisalResponse.AppraisalTypeQuestionPromptID,
                       AppraisalResponse.Detail, 
                      AppraisalResponse.ModifiedDate,
                      PersonID
                FROM AppraisalResponse
                WHERE AppraisalResponse.ID=@AppraisalResponseID AND AppraisalResponse.Detail<>@Detail
    END

    If @Detail is not null or blank, I need to check if AppraisalResponse.Detail is blank or null (- I think this is where I am running into so much trouble). If it is blank or null then
    I need to check if there is already a record in AppraisalHistory with this ID. If there is, I need to insert the blank record to history, otherwise not.

    If @Detail is null.
    I need to check if there is already a record in Appraisal History with this ID. If there is, I need to insert the blank record to history, otherwise not.

    Даже описание скопипащено

    3.14159265, 23 Февраля 2011

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

    +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
    $year = date("Y");
    $month = date("m");
    $day = date("d"); 
    
    if ($month == 9 or $month == 10 or $month == 11)
    {
    $month_new = $month + 1;
    echo $year.'-'.$month_new.'-'.$day;  
    }
    else 
    {
    
    if ($month == 12) {$year_new = $year + 1; 
    $year_new = $year + 1;
    $month_new = 1; 
    echo $year_new.'-0'.$month_new.'-'.$day;  }
    else {
    $month_new = $month + 1;
    echo $year.'-0'.$month_new.'-'.$day;} 
    }

    не удержался )

    Sulik78, 22 Февраля 2011

    Комментарии (3)
  10. Perl / Говнокод #5766

    −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
    # Функция обновляет файл базы
            # Пользоваться: cut_jnl($bc, $local_ip, $jnl_string_new);
            sub cut_jnl
            {
    
                         my ( $bc, $ip_old, $string_new ) = @_;
                         open (JNL, "<$bc->{const}{base_jnl}");
                         undef $\;
                         my @all_file = <JNL>;
                         close JNL;
                         chomp($string_new);
                         $string_new .= "\n" if ($string_new ne '');
                         grep { s/.*$ip_old;.*/$string_new/sg } @all_file;
                         open (JNL, ">$bc->{const}{base_jnl}");
                         grep { print JNL } @all_file;
                         close JNL;
                         $bc->{const}{info}->debug("Update jnl, update string: $ip_old on $string_new");
    
            }

    no comments... особенно доставляют инструкции grep {}, это похлеще map {} будет.

    SadKo, 22 Февраля 2011

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

    +162

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    CString sLineNumber = _T("Line");
    	for(int lineIndex = 0; lineIndex < 255; lineIndex++)
    	{
    		sLineNumber += (_itot(lineIndex + 1, temp, 10));
    		...
    		sLineNumber = _T("Line");
    	}

    Build the string variable in loop, instead of use CString::Format(...)

    ShuraKotov, 21 Февраля 2011

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