1. 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)
  2. 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)
  3. 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)
  4. 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)
  5. 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)
  6. 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)
  7. PHP / Говнокод #9800

    +151

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

    striker, 29 Марта 2012

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

    +162

    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
    if(
           (trim($class->antihacker($_POST['fio']))=='')or
           (trim($class->antihacker($_POST['phone']))=='')or
           (trim($class->antihacker($_POST['email']))=='')or
           (trim($class->antihacker($_POST['adress']))=='')
          ){$error="Указанные поля заполнены неверно!";}
       elseif(!$class->validate_email($_POST['email'])){$error="E-mail указан не корректно!";}
       elseif($_POST['is_company']=='1'){
         if(
           (trim($class->antihacker($_POST['company']))=='')or
           (trim($class->antihacker($_POST['fio_cmp']))=='')or
           (trim($class->antihacker($_POST['email_cmp']))=='')or
           (trim($class->antihacker($_POST['kchet']))=='')or
           (trim($class->antihacker($_POST['rchet']))=='')
          ){$error="Указанные поля заполнены неверно!";}
       }

    анти хакерз...

    Sulik78, 28 Марта 2012

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

    +73

    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
    public String XOR_Encrypt(String source, String key)
        {
            byte plain_text[] = new byte[source.length()];
            plain_text = source.getBytes();
            byte key_mas[] = new byte[key.length()];
            key_mas = key.getBytes();
            int key_len = key.length();
            int crypt_pos = 0;
            for(int i = 0; i < source.length(); i++)
            {
                plain_text[i] = (byte)(plain_text[i] ^ 0xaa);
                plain_text[i] = (byte)(plain_text[i] ^ key_mas[crypt_pos]);
                if(crypt_pos >= key_len - 1)
                    crypt_pos = 0;
                else
                    crypt_pos++;
            }
    
            String EText = ByteToHexString(plain_text);
            return EText;
        }
        public static String EncodeSimmetr(String s)
        {
            int MultKey = 62142;
            int AddKey = 11719;
            byte f1[] = new byte[s.length()];
            byte f[] = new byte[s.length()];
            f = s.getBytes();
            for(int i = 0; i < s.length(); i++)
            {
                f1[i] = (byte)(f[i] ^ MultKey);
                MultKey ^= AddKey;
            }
    
            s = new String(f1);
            return s;
        }

    Система шифрования в той-же платёжке...

    dinisoft, 28 Марта 2012

    Комментарии (13)
  10. Java / Говнокод #9797

    +71

    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
    String url = "http://*.*.*.*:*/java/?code=" + sCode + "&request=monitor";
    String LogPass = sName + ":" + sPass;
    String sAuth = "Basic " + encodeBase64(LogPass);
    try
                {
                    con = (HttpConnection)Connector.open(url);
                    con.setRequestMethod("GET");
                    con.setRequestProperty("User-Agent", "Profile/MIDP-2.0 Confirguration/CLDC-1.0");
                    con.setRequestProperty("Accept_Language", "en-US");
                    con.setRequestProperty("Content-Type", "//text plain");
                    con.setRequestProperty("Connection", "close");
                    con.setRequestProperty("Authorization", sAuth);
                    in = con.openInputStream();
                    if(con.getResponseCode() == 200)
                    {
                        StringBuffer sb = new StringBuffer();
                        int chr;
                        while((chr = in.read()) != -1) 
                            sb.append((char)(chr < 192 || chr > 255 ? chr : chr + 848));
                        sBuff = sb.toString();
                    }
    }

    Авторизация в одной из платёжных систем

    dinisoft, 28 Марта 2012

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