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

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

    +149

    1. 1
    $years = range(date('Y', $now), date('Y', strtotime('+ 1 year', $now)));

    Пятница в моей голове... А надо было всеголтшь действующий и следующий

    nonamez, 24 Мая 2013

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

    +147

    1. 1
    <cbimport_import_check_checkimport>

    надо вдуматся что бы понять
    нода из конфигурации модуля под маженто

    vesan, 21 Мая 2013

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

    +156

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    // Если больше 23:30, то сверяем мультиреестровые
            if (mktime(date('H'), date('i'), date('s'), date('m'), date('d'), date('Y')) >= mktime(23, 30, 0, date('m'), date('d'), date('Y')) || $notime == 1)
                $sql .= ' AND pi.multiregistry = "1"';
            else
                $sql .= ' AND pi.multiregistry = "0"';

    Колдуем даты

    dimkich, 17 Мая 2013

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

    +127

    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
    //top edge
                if (normal)
                    for (int i = y; i > 0; i--)
                        if (_map[x, i] == 0)
                            if ((i - 1) > minDist) { mnt.Corners[0] = new Point(x, i - 1 + minDist); break; }
                            else { normal = false; mnt.Height = -1; }
    
                //top-right edge
                if (normal)
                    for (int i = 0; ((x + i) < MAP_SIZE) & ((y - i) > 0); i++)
                        if (_map[x + i, y - i] == 0)
                            if (Math.Sqrt(2) * (MAP_SIZE - i) > minDist) { mnt.Corners[1] = new Point(x + i - 1 - minDist, y - i + 1 + minDist); break; }
                            else { normal = false; mnt.Height = -1; }
    
                //right edge
                if (normal)
                    for (int i = x; i < MAP_SIZE; i++)
                        if (_map[i, y] == 0)
                            if ((MAP_SIZE - i - 1) > minDist) { mnt.Corners[2] = new Point(i - 1 - minDist, y); break; }
                            else { normal = false; mnt.Height = -1; }
    
                //bottom-right edge
                if (normal)
                    for (int i = 0; ((x + i) < MAP_SIZE) & ((y + i) < MAP_SIZE); i++)
                        if (_map[x + i, y + i] == 0)
                            if (Math.Sqrt(2) * (MAP_SIZE - i) > minDist) { mnt.Corners[3] = new Point(x + i - 1 - minDist, y + i - 1 - minDist); break; }
                            else { normal = false; mnt.Height = -1; }
    
                //bottom edge
                if (normal)
                    for (int i = y; i > 0; i++)
                        if (_map[x, i] == 0)
                            if ((i - 1) > minDist) { mnt.Corners[4] = new Point(x, i - 1 - minDist); break; }
                            else { normal = false; mnt.Height = -1; }
    
                //bottom-left edge
                if (normal)
                    for (int i = 0; ((x - i) < MAP_SIZE) & ((y + i) > 0); i++)
                        if (_map[x - i, y + i] == 0)
                            if (Math.Sqrt(2) * (MAP_SIZE - i) > minDist) { mnt.Corners[5] = new Point(x - i + 1 + minDist, y + i - 1 - minDist); break; }
                            else { normal = false; mnt.Height = -1; }
    
                //left edge
                if (normal)
                    for (int i = x; i > 0; i--)
                        if (_map[i, y] == 0)
                            if ((i + 1) > minDist) { mnt.Corners[6] = new Point(i + 1 + minDist, y); break; }
                            else { normal = false; mnt.Height = -1; }
    
                //top-left edge
                if (normal)
                    for (int i = 0; ((x - i) > 0) & ((y - i) > 0); i++)
                        if (_map[x - i, y - i] == 0)
                            if (Math.Sqrt(2) * (MAP_SIZE - i) > minDist) { mnt.Corners[7] = new Point(x - i + 1 + minDist, y - i + 1 + minDist); break; }
                            else { normal = false; mnt.Height = -1; }

    Мне было лень думать. Очень лень.

    RaZeR, 11 Мая 2013

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

    +102

    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
    if (
         !(this.Department.Length == 4 && 
                "0123456789".Contains(this.Department[0]) && 
                "0123456789".Contains(this.Department[1]) && 
                "0123456789".Contains(this.Department[2]) && 
                "0123456789".Contains(this.Department[3])) &&
         !(this.Department.Length == 4 && 
                "0123456789".Contains(this.Department[0]) && 
                "ABCDEFGHIJKLMNOPQRSTUVWXYZ".Contains(this.Department[1]) && 
                "ABCDEFGHIJKLMNOPQRSTUVWXYZ".Contains(this.Department[2]) && 
                "ABCDEFGHIJKLMNOPQRSTUVWXYZ".Contains(this.Department[3])) &&
         !(this.Department.Length == 5 && 
                "0123456789".Contains(this.Department[0]) && 
                "0123456789".Contains(this.Department[4]) && 
                "ABCDEFGHIJKLMNOPQRSTUVWXYZ".Contains(this.Department[1]) && 
                "ABCDEFGHIJKLMNOPQRSTUVWXYZ".Contains(this.Department[2]) && 
                "ABCDEFGHIJKLMNOPQRSTUVWXYZ".Contains(this.Department[3])))
         {
          return "error";
         }

    Он видимо не знал о существовании регулярных выражений

    NeoN, 02 Мая 2013

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

    +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
    ....
    #define MAX_PROC_LIST 1024
    enum PROCCESS_TYPE
    {
    	 OFFRO,
             GFEER,
             OLLYD,
    	 FLOOT,
              SFOIT,
    };
    
    typedef struct 
    {
    	PROCCESS_TYPE tType;
    	unsigned short uPid;
    	bool bIA32;
    }ACTIVE_PROCCESS_INFO, *PACTIVE_PROCCESS_INFO;
    ....
    
    bool MONITOR_PROCCESS_ENGINE::GetActiveProccessInfo(PACTIVE_PROCCESS_INFO pActiveInfoProccess, const unsigned int nIndex)
    {
    	if(nIndex < 0) return false;
    	PROCESSENTRY32 pe32;
    	HANDLE hProcessSnap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
    	bool bFound = false;
    	pe32.dwSize = sizeof( PROCESSENTRY32 );
    	if(!Process32First( hProcessSnap, &pe32 )) return false;
    	char szNameImage[MAX_PATH];
    	ZeroMemory(szNameImage, MAX_PATH);
    	do 
    	{
    		if(pe32.th32ProcessID == aProccessList[nIndex])
    		{
    			bFound = true;
    		        wcstombs(szNameImage, (const wchar_t *)pe32.szExeFile, wcslen(pe32.szExeFile));
    			break;
    		}
    
    	} while( Process32Next( hProcessSnap, &pe32 ));
    	CloseHandle(hProcessSnap);
    
    	if(bFound && strlen(szNameImage)) 
            {
    		  if(!strcmp(szNameImage, szActiveList32[0])) 
    			  pActiveInfoProccess->tType = OFFRO;
    		  else
    		  if(!strcmp(szNameImage, szActiveList32[1])) 
    			   pActiveInfoProccess->tType = GFEER;
    		  else
    		  if(!strcmp(szNameImage, szActiveList32[2]))
    			  pActiveInfoProccess->tType =  OLLYD;
    		  else 
    		  if(!strcmp(szNameImage, szActiveList32[3]))
    			  pActiveInfoProccess->tType =  FLOOT;
    		  else 
    		  if(!strcmp(szNameImage, szActiveList32[4]))
    			  pActiveInfoProccess->tType =  SFOIT;
    		  else  return false;
    		 pActiveInfoProccess->uPid = (unsigned short) aProccessList[nIndex];
    		 pActiveInfoProccess->bIA32 = true; // Fixme x64?
    	}
    	else return false;
    	return true;
    }

    Cи в стиле C++

    not123, 09 Апреля 2013

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

    +151

    1. 1
    if (Scene.generatedFast || (typeof generatedFast != "undefined" && generatedFast) )

    Lure Of Chaos, 28 Марта 2013

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

    +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
    getInsideText($part1[0],'<string>','</string>',1,true);
    
    function getInsideText($str,$fstr,$lstr,$limit=0,$trim=true){
        $temp_arr=array();
        $lcnt=0;
        while(strpos($str,$fstr)!==false && ($limit ? $lcnt<$limit : true)){
            $fpos=($fstr ? strpos($str,$fstr)+strlen($fstr) : 0);
            $str=substr($str,$fpos);
            $lpos=strpos($str,$lstr);
            $val=($lpos!==false ? substr($str,0,$lpos) : $str);
            $temp_arr[]=($trim ? trim($val) : $val);
            $str=substr($str,$lpos+strlen($lstr));
            $lcnt++;
        }
        return ($limit==1 ? (isset($temp_arr[0]) ? $temp_arr[0] : '') : $temp_arr);
    }

    Конечный автомат своими силами.

    alexx, 21 Марта 2013

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

    +16

    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
    class Context;
    
    class AbstractState
    {
    	Context * m_context;
    
    protected:
    	Context * context() const { return m_context; }
    
    public:
    	AbstractState(Context * context) : m_context(context) { };
    	virtual ~AbstractState() { }
    	virtual void doSomething() = 0;
    };
    
    class Context
    {
    	std::unique_ptr<AbstractState> m_state;
    
    public:
    	enum State
    	{
    		State1,
    		State2,
    	};
    	Context() { switchToState(State1); }
    	void switchToState(State newState);
    	void doSomething() { m_state->doSomething(); }
    	void someCleanup() { }
    };
    
    class ConcreteState1 : public AbstractState
    {
    public:
    	ConcreteState1(Context * context) : AbstractState(context) { }
    	virtual void doSomething()
    	{
    		context()->switchToState(Context::State2);
    		context()->someCleanup();
    	}
    };
    
    class ConcreteState2 : public AbstractState
    {
    public:
    	ConcreteState2(Context * context) : AbstractState(context) { }
    	virtual void doSomething()
    	{
    		context()->switchToState(Context::State1);
    		context()->someCleanup();
    	}
    };
    
    void Context::switchToState(State newState)
    {
    	switch(newState)
    	{
    	case State1:
    		m_state.reset(new ConcreteState1(this));
    		return;
    	case State2:
    		m_state.reset(new ConcreteState2(this));
    		return;
    	}
    }

    Бывает, на меня находит состояние "сначала делай, потом думай", благо результат был быстро обнаружен отладчиком.

    Xom94ok, 10 Марта 2013

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

    −169

    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
    DECLARE @IsPerson BIT  
     ,@ContactTypeID INT  
    
     SET @ContactTypeID = CASE WHEN @IsPerson = 0 THEN 3 ELSE 4 END  
    
     IF (LEN(ISNULL(@FirstName,'')) <= 0 AND LEN(ISNULL(@LastName,'')) <= 0 AND (LEN(@EntityName) > 0 OR LEN(@TradingAs) > 0))  
     BEGIN  
      SET @IsPerson = 0  
     END   
     ELSE  
     BEGIN  
      SET @IsPerson = 1  
     END

    Такая себе Stored Procedure...
    Magic numbers - это всё фигня. Меня всегда интересовало, почему тип контакта всегда 4?
    И, да, строки идут именно в такой очерёдности.

    kore_sar, 28 Февраля 2013

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