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

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

    +161

    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
    function render_menu_item($tag,$value,$css=null){
    $length=strlen($tag);
       
        //Validate the tags
          if($tag[0]=='<' && $tag[$length-1]=='>'){
            $closingtag=str_replace('<','</',$tag);
            if($css)
                $tag=str_replace('>',' class="'.$css.'">',$tag);        
          }
          else{
            if($css){       
            $classtag='<'.$tag.' class="'.$css.'">';
            $tag='<'.$tag.'>';
            $closingtag=str_replace('<','</',$tag);
            $tag=$classtag;
            }
            else{
            $tag='<'.$tag.'>';
            $closingtag=str_replace('<','</',$tag);
            }
          }  
      return $tag.$value.$closingtag;
    }

    Вот так пишут доблестные Drupal-разработчики из Иордании. Сохранено оригинальное форматирование.

    UncleAli, 13 Мая 2010

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

    +144

    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
    <?php
     $mon=array("1","2","3","4","5","6","7","8","9","10","11","12"); // здесь ахтунг, да?
     if($_REQUEST["lang"]=="ru")
      $mon=array("1.Январь","2.Февраль","3.Март","4.Апрель","5.Май","6.Июнь","7.Июль","8.Август","9.Сентябрь","10.Октябрь","11.Ноябрь","12.Декабрь");
     if($_REQUEST["lang"]=="en")
      $mon=array("1.January","2.February","3.March","4.April","5.May","6.June","7.July","8.August","9.September","10.October","11.November","12.December");
    
     $wk=array("1","2","3","4","5","6","7");
     if($_REQUEST["lang"]=="ru")
       $wk=array("Пн","Вт","Ср","Чт","Пт","Сб","Вс");
     if($_REQUEST["lang"]=="en")
       $wk=array("Mon","Tue","Wed","Thu","Fri","Sat","Sun");
    
    function writearray($name,$array,$bscripttags)
    {
     if($bscripttags)echo("<script language='javascript'>");
     echo("$name=new Array('");
     echo(implode("','",$array));
     echo("');");
     if($bscripttags)echo("</script>");
    }
    
    echo("<script language='javascript'>");
    echo("function mon(){");
    writearray("var monarr",$mon,false);
    echo("return monarr;}");
    
    echo("function wk(){");
    writearray("var wkarr",$wk,false);
    echo("return wkarr;}");
    
    echo("</script>");
    ?>

    запостил все, что бы был понятен контекст, но я сам не понимаю, зачем мне когда-то нужно было писать то, что написано во 2ой строке ))

    Lure Of Chaos, 12 Мая 2010

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

    +161

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    $a=explode("\r\n".$a);
    	if(in_array('',$a)) {
    		$y=sizeof($a);
    		for($x=0;$x<$y;$x++) {
    			if($a[$x]=='') {
    				for($z=$x;$z>-1;$z=$z-1) $head.=$a[$z]."\r\n";
    				break;
    			}
    		}
    		if($x<$y) for(1;$x<$y;$x++) {$text.=$a[$x];}
    	}

    сам писал)))
    а всё для того, чтобы отделить заголовки от текста в полученном через сокеты коде

    ura-anton, 12 Мая 2010

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

    +136

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    // Делаем из префикса количество хостов (без .0 и броадкаста)
    numips = pow(2.0, (double)(32 - slashnet)) - 2;
    
    // Делаем префикс из маски сети
    slashnet = 32 - ((int)log2((double)(0xFFFFFFFF - vnetconfig->nm)) + 1);

    Всё те же, всё оттуда же...

    raorn, 12 Мая 2010

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

    +67

    1. 1
    2. 2
    3. 3
    public boolean isActive() {
            return !isKilling() && !isKilled() && !isKillPending();
        }

    Made in Estonia (part 2)

    bot225, 28 Апреля 2010

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

    +166

    1. 1
    2. 2
    3. 3
    4. 4
    //выяснение адреса сайта
     define( "SITE_URL", "http://" . str_replace( "&#045;", "-", preg_replace('#^(.*)/[^/]*#', '\\1', $_SERVER['HTTP_HOST']).'/admin/' ) );
     define( "SITE_EDIT_URL", str_replace( "&#045;", "-", preg_replace('#^(.*)/[^/]*#', '\\1', $_SERVER['HTTP_HOST']) ) ); //.$_SERVER['REQUEST_URI'])."/" ) );
     define( "SITE_EDIT_URL_HTTP", "http://" . str_replace( "&#045;", "-", preg_replace('#^(.*)/[^/]*#', '\\1', $_SERVER['HTTP_HOST'])."/" ) ); //.$_SERVER['REQUEST_URI'])."/" ) );

    xynta, 27 Апреля 2010

    Комментарии (9)
  8. Куча / Говнокод #3113

    +143

    1. 1
    !<>

    Просто очень короткий говнокод:
    Читается как не больше и не меньше.
    Конечно, выдумано, но тем не менее :)

    wvxvw, 26 Апреля 2010

    Комментарии (9)
  9. VisualBasic / Говнокод #3108

    −86

    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
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    97. 97
    98. 98
    99. 99
    using System;
    using System.Web;
    using MaxPro;
    
    namespace HandlerFile
    {
    	public class FileHttpHandler : IHttpHandler
    	{
    		// Переопределяем метод ProcessRequest.
    		public void ProcessRequest(HttpContext context)
    		{
    			//var
    			Byte[] oImg;
    			Int32 iId=0;
    			Int32 iRemInt=0;
    			//var Zap
    			Int32 iNum=0;
    			Exception oErr;
    			Object[,] oZap=new Object[0,0];
    			//end var
    			if(All.IsInteger(context.Request.QueryString["iId"]))
    			{
    				iId=Convert.ToInt32(context.Request.QueryString["iId"]);
    				iNum=Ow.iZap1i("OneWindow.Procedure173","@iId",iId,out oZap,out oErr);
    			}
    			else if(All.IsInteger(context.Request.QueryString["iRemInt"]))
    			{
    				iId=Convert.ToInt32(context.Request.QueryString["iRemInt"]);
    				iNum=Ow.iZap1i("OneWindow.Procedure174","@iRemInt",iRemInt,out oZap,out oErr);
    			}
    			if(iNum>0)
    			{
    				oImg=(Byte[])oZap[0,0];
    				//генерация бинарного потока
    				/* Возможно пригодится, хотя ясности нет зачем,
    				 * но когда ie сбоит и не открывает файл, то это помогает, особенно ClearHeaders
    				 * Response.ClearContent()
    				 * Response.ClearHeaders()
    				 *///
    				context.Response.ContentEncoding=System.Text.Encoding.GetEncoding("UTF-8");
    				context.Response.Charset="UTF-8";
    				context.Request.ContentEncoding=System.Text.Encoding.UTF8;
    				switch (Convert.ToString(oZap[2,0]))
    				{
    					case "gif":
    						context.Response.ContentType="image/GIF";
    						context.Response.AddHeader("Content-Disposition","filename="+Convert.ToString(oZap[1,0]));
    						break;
    					case "jpg":
    						context.Response.ContentType="image/JPEG";
    						context.Response.AddHeader("Content-Disposition","filename="+Convert.ToString(oZap[1,0]));
    						break;
    					case "jpeg":
    						context.Response.ContentType="image/JPEG";
    						context.Response.AddHeader("Content-Disposition","filename="+Convert.ToString(oZap[1,0]));
    						break;
    					case "bmp":
    						context.Response.ContentType="image/BMP";
    						context.Response.AddHeader("Content-Disposition","filename="+Convert.ToString(oZap[1,0]));
    						break;
    					case "png":
    						context.Response.ContentType="image/PNG";
    						context.Response.AddHeader("Content-Disposition","filename="+Convert.ToString(oZap[1,0]));
    						break;
    					case "txt":
    						context.Response.ContentType="text/plain";
    						context.Response.AddHeader("Content-Disposition","filename="+Convert.ToString(oZap[1,0]));
    						break;
    					case "htm":
    						context.Response.ContentType="text/HTML";
    						context.Response.AddHeader("Content-Disposition","filename="+Convert.ToString(oZap[1,0]));
    						break;
    					case "html":
    						context.Response.ContentType="text/HTML";
    						context.Response.AddHeader("Content-Disposition","filename="+Convert.ToString(oZap[1,0]));
    						break;
    					case "xls":
    						context.Response.ContentType="application/vnd.ms-excel";
    						context.Response.AddHeader("Content-Disposition","attachment; filename="+Convert.ToString(oZap[1,0]));
    						break;
    					case "doc":
    						context.Response.ContentType="application/msword";
    						context.Response.AddHeader("Content-Disposition","attachment; filename="+Convert.ToString(oZap[1,0]));
    						break;
    					case "dot":
    						context.Response.ContentType="application/msword";
    						context.Response.AddHeader("Content-Disposition","attachment; filename="+Convert.ToString(oZap[1,0]));
    						break;
    					case "ppt":
    						context.Response.ContentType="application/vnd.ms-powerpoint";
    						context.Response.AddHeader("Content-Disposition","attachment; filename="+Convert.ToString(oZap[1,0]));
    						break;
    					default:
    						context.Response.AddHeader("Content-Disposition","attachment; filename="+Convert.ToString(oZap[1,0]));
    						break;
    				}
    				context.Response.OutputStream.Write(oImg,0,oImg.Length);
    			}
    		}

    а вам слабо? всё те же мос окна

    ursus, 26 Апреля 2010

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

    +118.2

    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
    private ArrayList SortListings(ArrayList _listings)
            {
                ArrayList result = new ArrayList();
                ArrayList company_names = new ArrayList();
                Hashtable entities = new Hashtable();
    
                foreach (ListOfListings l in _listings)
                {
                    try
                    {
                        entities.Add(l.ListingName, l);
                        company_names.Add(l.ListingName);
                    }
                    catch
                    {
                    }
                }
    
                company_names.Sort();
                for (int i = 0; i < company_names.Count; i++)
                {
                    result.Add(entities[company_names[i]]);
                }
                return result;
            }

    Сортировка :)

    bugotrep, 18 Апреля 2010

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

    +150.8

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    $tttr = rand( 1, 2 );
    if ( $tttr == 1 )
    {
        $bonusik = "&dd=10|";
    }
    if ( $tttr == 2 )
    {
        $bonusik = "&dd=5|dd=5|";
    }

    Random and naming fails.

    Bobby, 16 Апреля 2010

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