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

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

    +154

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    <?php
     $dPh = fopen("photos.cfg", "r");
     while (($aCrow = fgetcsv($dPh, 0, "|", "}")) !== FALSE){
    	$sNof = explode(".", $aCrow[0]);
    	echo "<a href='photo/_html/show.php?ph=$sNof[0]'>\n";
    	echo "\t<img src='photo/_thumbs/$aCrow[0]' alt='$aCrow[1]'>\n";
    	echo "</a>\n";
     }
    ?>

    Скрипт, который создаёт превьюшки со ссылками для фотогаллереи.
    photos.cfg - содержит строки вида: Имя_файла.jpg|Описание, которое видит пользователь.
    show.php - отдельная тема.

    Ambilight, 13 Августа 2009

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

    +154

    1. 1
    2. 2
    3. 3
    4. 4
    $max_b = 0;
        for($i=1;$i<=40;$i++){
          $max_b +=(41-$i);
        }

    Нашел у товарища в коде, данный кусочек вызывался в цикле порядка десятка тысяч раз

    vasly, 12 Августа 2009

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

    +154

    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
    if ( isset( $criterias['name'] ) && ($criterias['name'] = trim( $criterias['name'] )) )
    {
    	$conditions .= empty( $conditions ) ? '(' : ' AND ';
    	$conditions .= "name LIKE '%".addslashes( $criterias['name'] )."%'";
    }
    
    if ( isset( $criterias['address'] ) && ($criterias['address'] = trim( $criterias['address'] )) )
    {
    	$conditions .= empty( $conditions ) ? '(' : ' AND ';
    	$conditions .= "address LIKE '%".addslashes( $criterias['address'] )."%'";
    }
    
    // если условие непустое, то закрываем скобку
    $conditions .= empty( $conditions ) ? '' : ')';

    Вместо использования массива для условий и последующего его объединения

    wunge, 10 Августа 2009

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

    +154

    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
    <?php
    
    $socket = stream_socket_server("tcp://127.0.0.1:8982", $errno, $errstr);
    if (!$socket) 
        echo "$errstr ($errno)<br />\n";
    while (TRUE){
    	$conn = stream_socket_accept($socket);
    if(pcntl_fork() == -1) {
    			echo "Sorrr: fork failure!\n";
    			die();
    			}
    	if(pcntl_fork() == 0)
    	{
    	fwrite($conn, "Hello!\n");
    	$input=fread($conn,1024);
    	fwrite($conn,$input . "\n");
    	if ($input = "quit")
    			{
    			fwrite($conn,"Terminated");
    			fclose($conn);
    			fclose($socket);
    			sleep (5);
    			exit();
    			}else{
    			fwrite($conn,"Enter data:");
    }
    }
    }
    fclose($conn);
    ?>

    guest, 21 Июля 2009

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

    +154

    1. 1
    return !( Pattern.compile("['\"`]+").matcher(query.subSequence(0, query.length())).matches());

    Шедевр проверки на запретные символы в запросе

    guest, 21 Июля 2009

    Комментарии (4)
  7. Куча / Говнокод #1379

    +154

    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
    php_value error_reporting 7
    AddDefaultCharset UTF-8
    # CharsetDisable On
    # CharsetDefault windows-1251
    # CharsetSourceEnc windows-1251
    # CharsetRecodeMultipartForms off
    
    Options All -Indexes
    
    RewriteEngine On
    
    RewriteRule ^/?$ index.php [L]
    
    RewriteRule ^rated/?$ index.php?act=rated_screen [L]
    RewriteRule ^upload/?$ test.php?act=upload_screen [L]
    RewriteRule ^settings/?$ index.php?act=settings_screen [L]
    RewriteRule ^logout/?$ index.php?act=logout [L]
    RewriteRule ^([0-9]+)?$ index.php?act=id_screen&id=$1 [L]
    RewriteRule ^([0-9]+)/i.jpg?$ templates/direct.php?id=$1 [L]

    Есть в .htaccess вот такое "RewriteRule ^upload/?$ index.php?act=upload_screen [L]" и при переходе по ссылке site.ru/upload в адресной строке появляется http://site.ru/upload/?act=upload_screen ... почему такое может быть?

    guest, 16 Июля 2009

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

    +154

    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
    <?php
      $br="
    ";
      include "functions.php";
      mconnect();
      $result=mysql_query("TRUNCATE base");  
      $tags=file_get_contents("tag_cache");
    
      $tags=str_replace("'","\'",$tags);
      $tags=explode("songList begin",$tags);
      $j=0;
      for($i=1; $i<count($tags); $i++)
      {
        $tmp=explode("songList end",$tags[$i]);
        $tbase[$j++]=$tmp[0];
      }
      $j=0;
      for($i=0; $i<count($tbase); $i++)
      {
        $tmp=explode("key: ", $tbase[$i]);
        for($i2=1; $i2<count($tmp); $i2++)
    	$element[$j++]=$tmp[$i2];
      }
      for($i=0; $i<count($element); $i++)
      {
        $tmp=explode($br."file: ",$element[$i]);
        $track[$i]['key']=$tmp[0];
    
        $tmp=explode($br."Time: ",$tmp[1]);
        $track[$i]['file']=$tmp[0];
       
        $tmp=explode($br."Artist: ",$tmp[1]);
        $track[$i]['Time']=$tmp[0];
    
        $tmp=explode($br."Title: ", $tmp[1]);
        $track[$i]['Artist']=$tmp[0];
    
        $tmp=explode($br."Album: ", $tmp[1]);
        $track[$i]['Title']=$tmp[0];
    
        $tmp=explode($br."Track: ", $tmp[1]);
        $track[$i]['Album']=$tmp[0];
    
        $tmp=explode($br."Date: ", $tmp[1]);
        $track[$i]['Track']=$tmp[0];
    
        $tmp=explode($br."Genre: ", $tmp[1]);
        $track[$i]['Date']=$tmp[0];
    
        $tmp=explode($br."mtime: ", $tmp[1]);
        $track[$i]['Genre']=$tmp[0];
        $track[$i]['mtime']=$tmp[1];
    	$track[$i]['Size']=filesize(str_replace("\'","'", $track[$i]['file']));
      }
      for($i=0; $i<count($track); $i++)
      {
        //	echo $track[$i]['Artist']." -  ".$track[$i]['Album'].": ".$track[$i]['Title']."; " . round($track[$i]['Time']/60) . "m " .$track[$i]['Time']%60 . "s<hr>";
        $request="INSERT INTO base (file, Time, Artist, Title, Album, Track, Date, Genre, mtime, Size) VALUES ('".
    $track[$i]['file']."', '"
    .$track[$i]['Time']."', '"
    .$track[$i]['Artist']."', '"
    .$track[$i]['Title']."', '"
    .$track[$i]['Album']."', '"
    .$track[$i]['Track']."', '"
    .$track[$i]['Date']."', '"
    .$track[$i]['Genre']."', '"
    .$track[$i]['mtime']."', '"
    .$track[$i]['Size']."')";
    
      echo $request."<hr>";
      $result=mysql_query($request) or die(mysql_error().$i.";(");
      }
    ?>

    Прога, которая из базы mpd запихивает в mysql

    guest, 06 Июля 2009

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

    +154

    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
    /**
    	 * public static final int ARRAY 2003 public static final int BIGINT -5
    	 * public static final int BINARY -2 public static final int BIT -7 public
    	 * static final int BLOB 2004 public static final int BOOLEAN 16 public
    	 * static final int CHAR 1 public static final int CLOB 2005 public static
    	 * final int DATALINK 70 public static final int DATE 91 public static final
    	 * int DECIMAL 3 public static final int DISTINCT 2001 public static final
    	 * int DOUBLE 8 public static final int FLOAT 6 public static final int
    	 * INTEGER 4 public static final int JAVA_OBJECT 2000 public static final
    	 * int LONGVARBINARY -4 public static final int LONGVARCHAR -1 public static
    	 * final int NULL 0 public static final int NUMERIC 2 public static final
    	 * int OTHER 1111 public static final int REAL 7 public static final int REF
    	 * 2006 public static final int SMALLINT 5 public static final int STRUCT
    	 * 2002 public static final int TIME 92 public static final int TIMESTAMP 93
    	 * public static final int TINYINT -6 public static final int VARBINARY -3
    	 * public static final int VARCHAR 12
    	 */
    	public Class getColumnClass(int column) {
                ...
            }

    guest, 30 Июня 2009

    Комментарии (1)
  10. Куча / Говнокод #1264

    +154

    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
    "IF ACK01 <> ""IB"" or ""IR""
    {
      If Partner = ""CARDINAL HEALTH""  THEN 
      {
          if ACK01= ""IA""  and not exist LIN.SCC.4017=1  THEN ""017""  ELSE ""011""
         Else 
         {
            if Partner = ""NOVANT HEALTH"" OR ""KAISER"" OR ""KAISER HAWAII""
            then
               CASE  (ACK01)
                    ""IA"":  THEN ""068""
                    ""IR"" : THEN ""100""
                    ""IC"" : THEN ""068""  
             else
                BLANK
           }
       } 
    }"

    из ТЗ

    guest, 26 Июня 2009

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

    +154

    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
    private void bazaknjigeDataGridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
    
    {
    
    int rowIndex = e.RowIndex;
    
    DataGridViewRow theRow = bazaknjigeDataGridView.Rows[rowIndex];
    
    double cellValue = double.Parse(theRow.Cells["dataGridViewTextBoxColumn14"].Value.ToString());
    
    if (cellValue == 0)
    
    {
    
    theRow.DefaultCellStyle.BackColor = Color.Red;
    
    }
    
    else
    
    {
    
    theRow.DefaultCellStyle.BackColor = Color.White;
    
    }
    }

    MSDN - рассадник индусокода. Вот седня нарыл там:

    guest, 16 Июня 2009

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