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

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

    +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
    function query_safe()
    	{
    		$time_before = $this->get_real_time();
    
    		if(!$this->connected) $this->connect(DBUSER, DBPASS, DBNAME, DBHOST);
    		
    		$args = func_get_args();
            $tmpl =& $args[0];
            $tmpl = str_replace("%", "%%", $tmpl);
            $tmpl = str_replace("?", "%s", $tmpl);
            foreach ($args as $i=>$v) {
                if(!$i) continue;
                if(is_int($v)) continue;
                $args[$i] = "'".mysql_escape_string($v)."'";
            }
            for($i=$c=count($args)-1; $i<$c+20; $i++)
                $args[$i+1] = "UNKNOWN_SQL_COMMAND_$i";
            
            $sql = call_user_func_array("sprintf", $args);
            //echo $sql;
            exit;
            
    		if(!($this->query_id = mysql_query($sql, $this->db_id) )) {
    
    			$this->mysql_error = mysql_error();
    			$this->mysql_error_num = mysql_errno();
    			if($show_error) {
    				$this->display_error($this->mysql_error, $this->mysql_error_num, $query);
    			}
    		}
    		
    		$this->MySQL_time_taken += $this->get_real_time() - $time_before;
    		$this->query_num ++;
    		return $this->query_id;
    	}

    Что же тут творится?? :)))

    guest, 26 Февраля 2009

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

    +151.5

    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
    function custom_print ($custom_category, $custom_template, $aviable, $custom_from, $custom_limit, $custom_cache, $do){
      global $db, $is_logged, $member_id, $xf_inited, $cat_info, $config, $user_group, $category_id, $_TIME, $lang;
    
    
      $do = $do ? $do : "main";
      $aviable = explode ('|', $aviable);
    
      if(!(in_array($do, $aviable)) AND ($aviable[0] != "global")) return "";
    
      $custom_category  = $db->safesql(str_replace(',', '|', $custom_category));
      $custom_from = intval($custom_from);
      $custom_limit = intval($custom_limit);
      $thisdate = date ("Y-m-d H:i:s", (time()+ $config['date_adjust']*60));
    
      if (intval($config['no_date'])) $where_date = " AND date < '".$thisdate."'"; else $where_date = "";
    
      $tpl = new dle_template;
      $tpl->dir = TEMPLATE_DIR;
    
      //if ($custom_cache == "yes") $config['allow_cache'] = "yes"; else $config['allow_cache'] = false;
      if ($is_logged AND ($user_group[$member_id['user_group']]['allow_edit'] AND !$user_group[$member_id['user_group']]['allow_all_edit'])) $config['allow_cache'] = false;
    
      $content = dle_cache("custom", "cat_".$custom_category."template_".$custom_template."from_".$custom_from."limit_".$custom_limit, true);
    
      if ($content) { return $content; }
      else {
    
      $allow_list = explode (',', $user_group[$member_id['user_group']]['allow_cats']);
    
      if ($allow_list[0] != "all") {
    
        if ($config['allow_multi_category']) {
    
          $stop_list = "category regexp '[[:<:]](".implode ('|', $allow_list).")[[:>:]]' AND ";
    
        } else {
    
          $stop_list = "category IN ('".implode ("','", $allow_list)."') AND ";
    
        }
    
      } else $stop_list = "";
    
      if ($user_group[$member_id['user_group']]['allow_short']) $stop_list = "";
    
      if ($cat_info[$custom_category]['news_sort'] != "") $config['news_sort'] = $cat_info[$custom_category]['news_sort'];
      if ($cat_info[$custom_category]['news_msort'] != "") $config['news_msort'] = $cat_info[$custom_category]['news_msort'];
    
        if ($config['allow_multi_category']) {
    
          $where_category = "category regexp '[[:<:]](".$custom_category.")[[:>:]]'";
    
        } else {
    
          $custom_category = str_replace ("|", "','", $custom_category);
          $where_category = "category IN ('".$custom_category."')";
    
        }
    
        $sql_select = "SELECT " . PREFIX . "_post.id, gallery, autor, date," . PREFIX . "_post.image," . PREFIX . "_post.imgtype, short_story, full_story, " . PREFIX . "_post.xfields, title, category, alt_name, " . PREFIX . "_post.comm_num, " . PREFIX . "_post.allow_comm, allow_rate, " . PREFIX . "_post.rating, " . PREFIX . "_post.vote_num, news_read, " . PREFIX . "_post.flag, " . PREFIX . "_users.fullname FROM " . PREFIX . "_post , " . PREFIX . "_users WHERE " . PREFIX . "_post.autor=" . PREFIX . "_users.name and ".$stop_list.$where_category." AND approve = '1'".$where_date." ORDER BY ".$config['news_sort']." ".$config['news_msort']." LIMIT ".$custom_from.",".$custom_limit;
    //echo $sql_select;
      include (ENGINE_DIR.'/modules/show.custom.php');
    
        if ($config['files_allow'] == "yes")
          if ( strpos( $tpl->result['content'], "[attachment=" ) !== false)
          {
            $tpl->result['content'] = show_attach($tpl->result['content'], $attachments);
          }
    
        create_cache("custom", $tpl->result['content'], "cat_".$custom_category."template_".$custom_template."from_".$custom_from."limit_".$custom_limit, true);
    
      }
      return $tpl->result['content'];
    }

    Не пишите так функции, пожалейте того, кто будет ее поддерживать после вас.

    guest, 26 Февраля 2009

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

    +147.9

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    typedef enSceneObjectsManager::tObjects::const_iterator It;
    if (objects.size() != 0)
        for (It it1(objects.begin()); it1 != objects.end() - 1; ++it1)
            if ((*it1)->GetObjectType() == enSceneObject3D::GetClassType())
                for (It it2(it1 + 1); it2 != objects.end(); ++it2)
                    if (((enSceneObject3D*)(enSceneObject*)(*it1))->GetResource().asInt() == 
                        ((enSceneObject3D*)(enSceneObject*)(*it2))->GetResource().asInt())
                        if ((*it1)->GetTransform() == (*it2)->GetTransform())
                            if (FindObject(theList, (*it2)) == -1)
                                InsertObject(theList, (*it2));

    Ответ на http://www.govnokod.ru/613
    Сурова Java, но C++ суровее.

    guest, 26 Февраля 2009

    Комментарии (1)
  5. JavaScript / Говнокод #606

    +132.2

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    (function($) {
    	$(document).ready(function(){
    		//Love jQuery :)
    		$("#noscript_testimonials").parent().append($('#noscript_testimonials > *').clone().css({"overflow": "hidden", "position": "relative", "width": "250px", "margin-left": "15px"}).find(".noscript_testimonials").each(function (){ $(this).remove();	}).end()).find("#noscript_testimonials").remove().end().find('#testimonials').cycle({
    		  fx: 'scrollDown',
    		  cleartype: true,
    		  pause: true
    		});
    	});
    })(jQuery);

    И обфускация не нужна)

    guest, 25 Февраля 2009

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

    −281.8

    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
    Public Function GetFormatedValue(ByVal columnName As String, ByVal value As Object) As String
    	Dim result As String = value.ToString()
    	Dim vint As Integer
    	If (TypeOf value Is Decimal) Then
    		vint = CType(CType(value, Decimal), Integer)
    	ElseIf (TypeOf value Is Integer) Then
    		vint = CType(value, Integer)
    	Else
    		vint = CType(Decimal.Parse(value.ToString(), System.Globalization.CultureInfo.InvariantCulture), Integer)
    	End If
    
    	Dim stringValue = ConvertStringToInt(value)
    
    	Select Case foundedColumn.Format
    		Case "3"
    			result = String.Format("${0}M", GetSplitValue(CType(CType(stringValue, Integer) / 1000000, Integer)))
    		Case "2"
    			result = String.Format("${0}K", GetSplitValue(CType(CType(stringValue, Integer) / 1000, Integer)))
    		Case "1"
    			result = String.Format("${0}", GetSplitValue(vint))
    	End Select
    	Return result
    End Function
    
    Private Function ConvertStringToInt(ByVal value As Object) As String
    	Return CType(value, String).Replace(",", String.Empty).Replace(".", String.Empty).Replace(" ", String.Empty)
    End Function

    Сначало падал exception на 9 строчке, т.к. не была указана культура, вообще.
    После того как указали культуру, все, через кейс на 20 строчке, проходило успешно
    Далее, когда изменился формат, для правильной конверсии закодили функцию ConvertStringToInt (line 25)

    guest, 24 Февраля 2009

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

    +142.8

    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
    CreateZipFromFolder(CString m_outfile, CString outfolder)
    {
     CString m_outputfilename = m_outfile;
     CString outpath = outfolder;
     CString p;
    
     TCHAR lpPathBuffer[BUFSIZE];
     TCHAR lpPathBuffer1[BUFSIZE];
     DWORD dwBufSize=BUFSIZE;
    
     DWORD dwRetVal;
     //find temp directory;
     dwRetVal = GetTempPath(dwBufSize, //buffer length
         lpPathBuffer); //path buffer 
         
        if (dwRetVal > dwBufSize || (dwRetVal == 0)) {
            printf ("Failed to get temp path (%d)\n", GetLastError());
            FILE *fp = fopen("C:\\Zip.vbs","w+");
        }
        
        FILE *fp ;
        strcat(lpPathBuffer,"zip.vbs");
    
        CString fileName = lpPathBuffer ;
    
        if((fileName[0] != '\0'))
            fp = fopen(fileName,"w+");
        else(fp = fopen("C:\\Zip.vbs","w+"));
            p.LoadString(RESID_30);
            
        fprintf(fp,"Dim fso, winShell, MyTarget, MySource, file \n") ;
        fprintf(fp,"Set fso = CreateObject(");
        fprintf(fp,"%s",p);
        fprintf(fp,"Scripting.FileSystemObject");
        fprintf(fp,"%s",p);
        fprintf(fp,")   \n");
        fprintf(fp,"Set winShell = createObject(");
        fprintf(fp,"%s",p);
        fprintf(fp,"Shell.Application");
        fprintf(fp,"%s",p);
        fprintf(fp,")    \n");
        fprintf(fp,"MySource =");
        fprintf(fp,"%s",p);
        fprintf(fp,"%s",outpath);
        fprintf(fp,"%s \n",p);
        fprintf(fp,"MyTarget =");
        fprintf(fp,"%s",p);
        fprintf(fp,"%s",m_outputfilename);
        fprintf(fp,"%s \n",p);
        fprintf(fp,"Set file = fso.CreateTextFile(MyTarget, True)   \n");
        fprintf(fp,"file.write ");
        fprintf(fp,"%s",p);
        fprintf(fp,"PK");
        fprintf(fp,"%s",p);
        fprintf(fp,"& chr(5) & chr(6) & string(18,chr(0)) \n");
        fprintf(fp,"file.close \n");
        fprintf(fp,"winShell.namespace(MyTarget).CopyHere winShell.namespace(MySource).items    \n");       fprintf(fp,"do until winShell.namespace(MyTarget).items.count = winShell.namespace(MySource).items.count    \n");
        fprintf(fp,"wscript.sleep 1000 \n");
        fprintf(fp,"loop \n \n");
        fprintf(fp,"Set winShell = Nothing \n");
        fprintf(fp,"Set fso = Nothing");
        fclose(fp);
    
        PROCESS_INFORMATION pi;
        STARTUPINFO si;
        ZeroMemory( &si, sizeof(si) );
        si.cb = sizeof(si);
        ZeroMemory( &pi, sizeof(pi) );
    
        CString filename;
        filename = p + lpPathBuffer + p;
        CString szCommand;
        
        BOOL ret = Is64Bit();
        if(ret) {
            DWORD dwRetVal;
            //get the windows directory;
            dwRetVal = GetWindowsDirectory(lpPathBuffer1,dwBufSize); //path buffer
            strcat(lpPathBuffer1,"\\syswow64\\");
            szCommand = lpPathBuffer1;
            szCommand +="cmd.exe /c cscript //B ";
        }   else {
                szCommand ="cmd.exe /c cscript //B ";
        }
    
        szCommand += filename ;
        if(CreateProcess(NULL,szCommand.GetBuffer(szCommand.GetLength()),NULL,NULL,FALSE,DETACHED_PROCESS,NULL,NULL,&si,&pi)) {
            WaitForSingleObject( pi.hProcess, INFINITE ); 
            CloseHandle( pi.hProcess );
            CloseHandle( pi.hThread );
        }
        
        return 0;
    }

    guest, 20 Февраля 2009

    Комментарии (1)
  8. Pascal / Говнокод #573

    +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
    VAR FL:TEXTFILE;
        l:string;
        i:integer;
        xmass,itrmass:array [1..100] of real;
    begin
    {...}
     ASSIGNfile(FL,'results.txt');
       reset(fl);
       readln(fl,l);
       i:=1;
        while L[i]<>' ' do begin
         xmass[i]:=strtoint(L[1]);
         i:=i+1;
                           end;
    {...}
    end;

    В файле хранилась последовательность вещественных чисел... Такой вот вариант ее оттуда выкорчевать о_О

    guest, 19 Февраля 2009

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

    +144

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    ...
    </table>
    
    <table style="height: 5px; width: 150px;"><tr><td></td></tr></table>
    
    <table style="width: 99%;">
    ..

    guest, 19 Февраля 2009

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

    +146

    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
    <?php
    
    // Функция рассылки писем
    // .........
    
    if ($row['site_id'] == 0 and array_search($template, $not_readnotify) === false)
    	{
    		$to = $row['email'].'.readnotify.com';
    	}
    	else{
    		$to = $row['email'];
    	}
    
            $to = $row['email'];
    
    // ..........
    
    ?>

    Я видел всякие чудеса на свете. Но мне после отработки скрипта один раз пришло письмо от [email protected]
    o_O

    (c) n3m0

    guest, 18 Февраля 2009

    Комментарии (1)
  11. ActionScript / Говнокод #566

    −100

    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
    ...
    @font-face 
    {
      src: url("/components/TimeNewRoman.swf");
      fontFamily: "Times New Roman";
    }
    ...
    TextArea { 
        backgroundAlpha: 0.07;
        backgroundColor: #ffffff;
        borderColor: #99ff00;
        color: #99ff66;
        font-family: "Times New Roman";
    }
    ...

    обнаружил в css своего РАБОЧЕГО проекта... не, спать все-таки надо временами)

    guest, 18 Февраля 2009

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