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

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

    +155

    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
    void SimpleTest::testTrivial() {
        wxTst::TempInteractive interactive;
        wxTst::ModalDialogTimer timer(wxID_OK);
       // *** Loop up top level containers ***
        CPPUNIT_ASSERT_MESSAGE ("Application top window invalid", 
    			    wxTheApp->GetTopWindow () != NULL);
        wxMDIParentFrame *topFrame = 
    	dynamic_cast< wxMDIParentFrame * >(wxTheApp->GetTopWindow ());
        CPPUNIT_ASSERT_MESSAGE ("Top window is not an MDI Parent frame", 
    			    topFrame != NULL);
        wxMenuBar *menuBar = topFrame->GetMenuBar ();
        CPPUNIT_ASSERT_MESSAGE ("Menubar not found", menuBar != NULL);
    
    //    interactive.ShowCurrentGui (_T(__FILE__), __LINE__);
    
        // *** Check menu item ***
        int platformMenuItemId = menuBar->FindMenuItem (_("Advanced"), 
                MC _T("Platform Specific Example"));
        CPPUNIT_ASSERT_MESSAGE ("Menu item ID 'platformMenuItem' not found",
                platformMenuItemId != wxNOT_FOUND);
        wxMenuItem *platformMenuItem = menuBar->FindItem (
                platformMenuItemId);
        CPPUNIT_ASSERT_MESSAGE ("Menu item 'platformMenuItem' not found",
                platformMenuItem != NULL);
        wxTst::EventSimulationHelper::SelectMenuItem (
                platformMenuItemId, topFrame);
        wxTst::WxGuiTestHelper::FlushEventQueue ();
        wxWindow* wdw = topFrame->FindWindow(_T("platform_child"));
        if (wdw == NULL)
    	wdw = wxWindow::FindWindowByName(_T("platform_child"));
        CPPUNIT_ASSERT_MESSAGE("First Child not found", wdw != NULL);
        wxMDIChildFrame* child1 = dynamic_cast<wxMDIChildFrame*>(wdw);
        CPPUNIT_ASSERT_MESSAGE("Window isn't an MDI Child", child1 != NULL);
        wxTst::WxGuiTestHelper::FlushEventQueue ();
        interactive.ShowCurrentGui (_T(__FILE__), __LINE__);
    
        wxTst::EventSimulationHelper::SelectMenuItem (
                platformMenuItemId, topFrame);
        wxTst::WxGuiTestHelper::FlushEventQueue ();
    
    //    interactive.ShowCurrentGui (_T(__FILE__), __LINE__);
    
        wxMDIChildFrame* child2 = topFrame->GetActiveChild();
        CPPUNIT_ASSERT_MESSAGE("Second child not found", child2 != NULL);
        CPPUNIT_ASSERT_MESSAGE("Second child same as first ", child2 != child1);
    
        child2->Close();
    
        int derived_toolMenuItemId = menuBar->FindMenuItem (_("Advanced"),
                MC _T("Custom Class Example"));
        CPPUNIT_ASSERT_MESSAGE ("Menu item ID 'derived_toolMenuItem' not found",
                derived_toolMenuItemId != wxNOT_FOUND);
        wxMenuItem *derived_toolMenuItem = menuBar->FindItem (
                derived_toolMenuItemId);
        CPPUNIT_ASSERT_MESSAGE ("Menu item 'derived_toolMenuItem' not found",
                derived_toolMenuItem != NULL);
        wxTst::EventSimulationHelper::SelectMenuItem (
                derived_toolMenuItemId, topFrame);
        wxTst::WxGuiTestHelper::FlushEventQueue ();
    
         wxWindow *custom_child = 
    	 wxWindow::FindWindowByName (_T("custom_class_child"));
         CPPUNIT_ASSERT_MESSAGE ("Container window for button 'wxID_OK' not found", 
     			    custom_child != NULL);
    //    interactive.ShowCurrentGui (_T(__FILE__), __LINE__);
        wxWindow *wxID_OKWdw4 = custom_child->FindWindow (XRCID("wxID_OK"));
        CPPUNIT_ASSERT_MESSAGE ("Window for button 'wxID_OK' not found", 
                wxID_OKWdw4 != NULL);
        wxTst::EventSimulationHelper::ClickButton (wxID_OKWdw4->GetId (), 
                wxID_OKWdw4);
        wxTst::WxGuiTestHelper::FlushEventQueue ();
        CPPUNIT_ASSERT_MESSAGE("OK Button didn't hide Mac Specific Dialog",
    			   custom_child->IsShown() == false);
    
    
    
    
    }

    Источник: метод примера из wxGuiTesting

    guest, 27 Января 2009

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

    +133.4

    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
    // parse from the uninstall, the actuall installation path
    		try {
    			int jarLoc = uninstallDir.indexOf("-jar");
    			String s = uninstallDir.substring(jarLoc + 5);
    			// turn it into a normalized file
    			int uniLoc = s.indexOf("uninstaller");
    			s = s.substring(1,uniLoc);
    			s = s.replace("\\", "/");
    			if(s.endsWith("/"))
    				s = s.substring(0,s.length()-1);
    
    			File f = new File(s);
    			if(!f.exists()) {
    				throw new Exception("installation directory does not exist: " + s);
    			}
    			return f;
    		}
    		catch(Exception e) {
                throw new Exception("installation directory could not be parsed from: " + uninstallDir);		    
    		}

    Typical code of one highly paid "tech expert" from USA
    Exception handling makes me cry, this guy doesn't even now about any other exception classes

    guest, 26 Января 2009

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

    +34.7

    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
    } else {
    					$json_array = array('error'	=> $this->log_error('busy', true));
    				}
    			} else {
    				$json_array = array('error'	=> $this->log_error('busy', true));
    			}
    		} else {
    			$json_array = array('error'	=> $this->log_error('busy', true));
    		}
    	} else {
    		$json_array = array('error'	=> $this->log_error('busy', true));
    	}
    	
    	} else {
    		$json_array = array('error'	=> $this->log_error('bad_symbols', false));
    	}
    } else {
    	$json_array = array('error'	=> $this->log_error('check_error', false));
    						//	'errorStr'	=> $this->validation->error_string
    }

    Кусок метода в контроллере регистрации пользователя на одном из наших проектов. Вверху хренова гора ифов а внизу во такое вот счастье. "Авторская" табуляция сохранена

    guest, 25 Января 2009

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

    +28

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    $query = "update users set password = '{$cnf['userpass']}', email = '{$cnf['useremail']}' where login = 'root'";
    if (mysql_query($query, $link) === false) {
         throw new Exception(mysql_error($link));
    }
    mysql_close($link);

    удалить)

    guest, 23 Января 2009

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

    +28.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
    function DelFilterEx($arName, $varName, $session=true, $FilterLogic="FILTER_logic")
    {
    	global $strError, $$FilterLogic;
    	if ($session) unset($_SESSION["SESS_ADMIN"][$varName]);
    	for($i=0; $i<count($arName); $i++)
    	{
    		$name = $arName[$i];
    		$bdays = $name."_DAYS_TO_BACK";
    		global $$name, $$bdays;
    		$$name = "";
    		$$bdays = "";
    	}
    	$$FilterLogic = "and";
    }

    Голова недодумала и пришла к переменным переменным

    guest, 22 Января 2009

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

    +23.7

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    function _validateDelete($d) {
        $valid = true;
        if (!$d["product_id"]) {
          $this->setError(dgettext("Core", "Product not selected."));
          return false;
        }
        if (!$d["product_id"]) {
          $this->setError(dgettext("Core", "Please select a record to delete."));
          $valid = false;
        }
        return $valid;
      }

    Индусокод классический

    guest, 21 Января 2009

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

    +18.7

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    $path = "a/b/c/d";
    $sections = array_reverse (explode ("/", $path));
    $sql = "SELECT `t1`.`id` FROM ";
    for ($i = 1; $i <= count ($sections); $i ++)
      $from_tables[] = "`test` `t".$i."`";
    $sql = $sql.implode (", ", $from_tables);
    $sql .= " WHERE ";
    for ($i = 1; $i < count ($sections); $i ++)
      $sql .= "`t".$i."`.`parent_id` = `t".($i+1)."`.`id` AND `t".$i."`.`name` = '".$sections[$i-1]."' AND";
    $sql .= " `t".count ($sections)."`.`parent_id` = '0' AND `t".count ($sections)."`.`name` = '".$sections[count($sections)-1]."'";
    echo $sql;

    guest, 20 Января 2009

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

    +22

    1. 1
    2. 2
    3. 3
    set_include_path('.'.PATH_SEPARATOR . './library'
        .PATH_SEPARATOR.'./application/models/'
        .PATH_SEPARATOR.get_include_path());

    "Так и не смог я в тот вечер понять..." что имел в виду автор. Он, видимо, и сам не понял, поэтому сунул библиотеки зенда в несколько папок...

    guest, 20 Января 2009

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

    +33.4

    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
    <div id="timer">
    Включи JS
    </div>
    
    <script language="Javasсript" type="text/javasсript">
    //<![CDАТА[
    x642=10;
    function countdown() 
    {
    if ((0 <= 100) || (0 > 0))
    {
    x642--;
    if(x642 == 0)
    {
    document.getElementById("timer").innerHTML = '<a href="ссыла">bla<\/a>';
    }
    if(x642 > 0)
    {
    document.getElementById("timer").innerHTML = '<p align=center>Вы будете перенаправлены на страницу загрузки файлов через '+x642+' сек.</p>';
    setTimeout('countdown()',1000);
    }
    }
    }
    countdown();
    //]]>
    </script>

    счетчик...
    взято отсюда: http://vkontakte.ru/topic14311792

    guest, 19 Января 2009

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

    +40.4

    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 Ta=new Array(«2»,«2»,«2»,«2»,«2»,«2»,«2»,«2»,«2»,«2», «2»,«2»,«2»,«2»,«2»,«2»,«2»,«2»,«2»,«2», «2»,«2»,«2»,«2»,«2»,«2»,«2»,«2»,«2»,«2», «2»,«2»,«2»,«2»,«2»,«2»,«2»,«2»,«2»,«2», «2»,«2»,«2»,«2»,«2»,«2»,«2»,«2»,«2»,«2», «2»,«2»,«2»,«2»,«2»,«2»,«2»,«2»,«2»,«2»,«2»,«2»,«2»,«2»);?
    
    Этот массив я нашел в коде сайта поддерживаемом компанией, где я работаю.
    На разгадку ушло немного времени, значительно больше времени ушло на осознание… это что, они серьезно?
    
    Отгадка:
    
    В скрипте подсчета суммы заказа встречается
    
    for(i=0; i<Ta.length; i++) { ля-ля-ля, считаем сумму с каждого поля ввода }
    
    То есть количество элементов в массиве — это сколько полей нужно обработать… соответственно добавил 1 товар на страницу — будь добр, добавь «2» в массив.
    
    Что называется хотите верьте, хотите нет.

    Код был взят с http://habrahabr.ru/blogs/humour/42786/

    guest, 14 Января 2009

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