1. PHP / Говнокод #9810

    +28

    1. 1
    2. 2
    3. 3
    function _spb_similar_similar_video_html(&$item, $key) {
      $item = htmlspecialchars($item, ENT_NOQUOTES);
    }

    brainstorm, 29 Марта 2012

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

    +130

    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
    int i,j;
    	char alph[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    	//Подстановка по таблице 1
    	int S_there[26][8]={{1,0,0,1,1,0,0,1},{1,0,0,0,1,0,0,0},{1,0,1,0,1,0,1,0},{0,0,1,1,0,0,1,1},{1,1,1,0,0,0,0,1},
    {1,0,0,0,0,1,1,1},{1,1,1,1,1,1,1,1},{1,1,0,1,0,0,1,0},{0,1,1,1,1,0,0,0},{1,1,0,0,0,0,1,1},{1,0,1,0,0,1,0,1},{0,1,0,0,1,0,1,1},
    {0,0,0,1,1,1,1,0},{0,1,0,1,0,1,0,1},{1,1,0,0,1,1,0,0},{0,0,0,1,0,0,0,1},{1,1,0,1,1,1,0,1},{1,0,1,1,0,1,0,0},{0,0,1,0,1,1,0,1},
    {0,0,0,0,0,0,0,0},{0,1,1,0,0,1,1,0},{0,1,0,0,0,1,0,0},{1,1,1,1,0,0,0,0},{0,0,1,1,1,1,0,0},{0,1,1,0,1,0,0,1},{0,0,1,0,0,0,1,0}};
    	
    	char str[]="THIISATESTFILEFORCHECKINGCYPHERMODULE";
    	int len=strlen(str);
        	int num[len];//массив с порядковыми номерами
    	int vector[len][8];//массив с ОТ, переведённым в двоичные вектора длины 8
    
    	for (i=0; i< len; i++)//Присваиваем каждой букве порядковый номер (а=0,b=1 и т.д.)
    	{
    		num[i]=((strchr(alph, str[i])-alph)% 26 + 0x01);
    		num[i]--;
    	}
    
    	for (i=0; i<len; i++)//Меняем букву на двоичный вектор длины 8 согласно порядковому номеру
    	{
    		int number=num[i];//счётчик текста
    		for (j=0; j<8; j++)
    		{
    			vector[i][j]=S_there[number][j];
    		}
    	}
    	for (i=0; i<len; i++)//Вывод на экран ОТ
    	{
    		for (j=0; j<8; j++)
    		{
    			printf("%u",vector[i][j]);
    		}
    		printf(" %c\n",str[i]);
    	}

    Нашёл в своей очень старой лабе...Нужно было буквы на входе преобразовать в двоичные вектора (например, а=10011001, b=10001000 и т.д.) ну и дальше ковыряться с этими векторами...почему я категорически не захотел тогда использовать case - хз :)))

    Pecho, 29 Марта 2012

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

    +118

    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
    Params.Name                 =   GetControl(pnlName) ? edName.Text : "";                                    
    Params.DateMeasurement      =   TOperation.GetDateValue(edDateTime);            
    Params.HalfYear             =   pnlHalfYear.Tag                        != null &&      
                                                    pnlHalfYear.Tag                        is bool && 
                                                    (bool)pnlHalfYear.Tag                          &&
                                                    edHalfYear.SelectedItem         != null &&
                                                    edHalfYear.SelectedItem.Value   != null &&
                                                    edHalfYear.SelectedItem.Value   is byte ? (byte)
                                                    edHalfYear.SelectedItem.Value   : (byte)0;
    Params.IdDepSource          =   GetControl(pnlDepSource) ? TDataList.GetComboRecId(edDepSource) : 0;          
    Params.IdDepSource2         =   pnlDepSource2.Tag                        != null &&      
                                                    pnlDepSource2.Tag                        is bool && 
                                                    (bool)pnlDepSource2.Tag                          ?
                                                    TDataList.GetComboRecId(edDepSource2) : 0;
    Params.Salt                 =   pnlDepSource2.Tag                        != null &&      
                                                    pnlDepSource2.Tag                        is bool && 
                                                    (bool)pnlDepSource2.Tag                          ?
                                                    getSalt()                               : 0;
    Params.Description          =   edComment.Text;

    ацкий код сохранения параметров. Досталось в наследство. Автор кода естественно имеет в/о факультета компьютерных педиков.

    gcoder, 29 Марта 2012

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

    +162

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    class Program implements ProgramProvider {
            
            public static function getInstance() {
                    return new Program();
            }
    }

    Гениальная реализация singleton!

    viktor_poltorak, 29 Марта 2012

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

    +158

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    $sCmd='$result=$this->'.$aEvent['method'].'();';
    $this->Hook_Run("action_event_".strtolower($this->sCurrentAction)."_before",array('event'=>$this->sCurrentEvent,'params'=>$this->GetParams()));
    eval($sCmd);
    $this->Hook_Run("action_event_".strtolower($this->sCurrentAction)."_after",array('event'=>$this->sCurrentEvent,'params'=>$this->GetParams()));
    return $result;

    LiveStreet CMS... nuff said...

    nkarakin, 29 Марта 2012

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

    +153

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    do
      {
       $firstDate = ConvertTimeStamp($firstDateSt, "SHORT");
       $lastDate = ConvertTimeStamp($lastDateSt, "SHORT");
       
       $arPeriod = Array(
        "TITLE" => CSchool::GetDiaryPeriod($firstDate, $lastDate),
        "HREF" => $APPLICATION->GetCurPageParam('START_WEEK='.$firstDate.'&END_WEEK='.$lastDate, array("START_WEEK", "END_WEEK"))
       );

    Битрикс...
    do без while? лаконично

    nicksevenfold, 29 Марта 2012

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

    +163

    1. 1
    2. 2
    3. 3
    //fucking designers
    	if ( $page->importantshort ) $page->short = true;
    	if ( $page->importantNOTshort ) $page->short = false;	// так то!

    bot, 29 Марта 2012

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

    +157

    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
    while(true)
    {
    	if ($i==0)
    	{
    		$new_form_name = $form_res[0]['frm_name'] . ' ( Copy )';
    	} else
    	{
    		$new_form_name = $form_res[0]['frm_name'] . ' ( Copy '.$i.' )';
    	}
    	if(!in_array($new_form_name, $formaNames))
    	{
    		break;
    	}
    	$i++;
    }

    Есть имя формы $form_res[0]['frm_name'] , напр "FORMNAME".
    нужно получить новое имя вида "FORMNAME ( Copy 1)"

    iersir, 29 Марта 2012

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

    +999

    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
    template<class TVisitedComponentList>
    	TUniqueIDOfVisitedComponentList getUniqueIDOfVisitedComponentTypeList(void)
    	{
    		static Type2Type<TVisitedComponentList> UniqueObjectForVisitedComponentTypeList;
    		return (size_t)(&UniqueObjectForVisitedComponentTypeList);
    	}
    
    	template<class TVisitedComponentList>
    	TCastWindowComponentTo* const castWindowComponentInternal(PegThing* const Window)
    	{
    		ASSERT(Window!=NULL);
    		if(Window==NULL)
    			return NULL;
    		STATIC_CHECK(!(boost::mpl::empty<TVisitedComponentList>::value), TVisitedComponentList_must_be_not_empty_and_be__boost_mpl_list_c__type);
    		const TUniqueIDOfVisitedComponentList UniqueIDOfVisitedComponentList=this->getUniqueIDOfVisitedComponentTypeList<TVisitedComponentList>();
    		const TCasterRepositorys::const_iterator NotFound=_casterRepositorys.end();
    		TCasterRepositorys::const_iterator findedCasterRepositoryForThisVisitedComponentList=_casterRepositorys.find(UniqueIDOfVisitedComponentList);
    		if(findedCasterRepositoryForThisVisitedComponentList==NotFound)
    		{
    			this->registerVisitedComponentList<TVisitedComponentList>();
    			findedCasterRepositoryForThisVisitedComponentList=_casterRepositorys.find(UniqueIDOfVisitedComponentList);
    		}
    		ASSERT(findedCasterRepositoryForThisVisitedComponentList!=NotFound);
    		const TCasterRepository::const_iterator NotFoundCaster=findedCasterRepositoryForThisVisitedComponentList->second->end();
    		const unsigned int ComponentType=const_cast<PegThing* const>(Window)->Type();
    		const TCasterRepository::const_iterator findedCaster=findedCasterRepositoryForThisVisitedComponentList->second->find(ComponentType);
    		if(findedCaster==NotFoundCaster)
    			return NULL;
    		ASSERT(findedCaster!=NotFoundCaster);
    		return (*(findedCaster->second))(Window);		
    	}
    
    	template<class TCurrentItem, class TEnd>
    	void registerVisitedComponentListItem(TCasterRepository& casterRepository, TCurrentItem CurrentItem, TEnd End)
    	{
    		using namespace boost;
    		enum {WINDOW_COMPONENT_TYPE=mpl::deref<TCurrentItem>::type::value};
    		STATIC_CHECK((mpl::has_key<TWindowComponentsTypeIdToTypeMap, mpl::int_<WINDOW_COMPONENT_TYPE> >::value!=0), WINDOW_COMPONENT_TYPE_must_be_at_TWindowComponentsTypeIdToTypeMap);
    		typedef mpl::at<TWindowComponentsTypeIdToTypeMap, mpl::int_<WINDOW_COMPONENT_TYPE> >::type TRealTypeOfWindowComponent;
    		this->checkDuplicateComponentTypeID(WINDOW_COMPONENT_TYPE, casterRepository);
    		struct _
    		{
    			static TCastWindowComponentTo* const casterForEachWindowComponent(PegThing* const Window)
    			{
    				ASSERT(Window!=NULL);
    				if(Window==NULL)
    					return NULL;
    				TRealTypeOfWindowComponent* const RealTypeComponent = static_cast<TRealTypeOfWindowComponent* const>(Window);
    				ASSERT(RealTypeComponent!=NULL);
    				TCastWindowComponentTo* const FinalCastedWindowComponent = static_cast<TCastWindowComponentTo* const >(RealTypeComponent);
    				ASSERT(FinalCastedWindowComponent!=NULL);
    				return FinalCastedWindowComponent;
    			}
    		};
    		TCasterForEachWindowComponent CasterForEachWindowComponentFunction=&(_::casterForEachWindowComponent);
    		this->checkDuplicateType(CasterForEachWindowComponentFunction, casterRepository);
    		casterRepository[WINDOW_COMPONENT_TYPE]=CasterForEachWindowComponentFunction;
    		registerVisitedComponentListItem(casterRepository, mpl::next<TCurrentItem>::type(), TEnd());
    	}
    
    	template<class TEnd>
    	void registerVisitedComponentListItem(TCasterRepository& casterRepository, TEnd CurrentItem, TEnd End)
    	{}

    Код из того же большого проекта.
    Ассерты после static_cast и "шаблонная магия" особенно доставляют.
    Мне конечно boost::mpl нравиться, но я считаю, что его негоже использовать в реальных проектах.

    Говногость, 29 Марта 2012

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

    +151

    1. 1
    $now = date(date('Y-m-d H:i:s'));

    striker, 29 Марта 2012

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