1. Pascal / Говнокод #17020

    +140

    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
    type func = function (x : real) : real;
    const
    	eps = 0.0000003;
    	pi = 3.14159265358979;
    function Integral (f : func; a, b : real) : real;
    var center : real;
    begin
    	center := (a + b) / 2;
    	if abs(b - a) < eps then
    		Integral := f(center) * (b - a)
    	else Integral := Integral(f, a, center) + 
    		Integral(f, center, b);
    end;
    function myFunc(x : real) : real;
    begin
    	myFunc := cos(x) / x;
    end;
    begin
    	writeln(Integral(myFunc, pi/2, pi));
    	readln;
    end.

    Толи я дурачек, толи автор кода - школьник....

    ShadowXX, 02 Ноября 2014

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

    +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
    protected boolean valid_move(int from, int to, int aBoard[], int colorfor) {
      if(plainType(colorfor) == userColor) {
        return (to>=0 && to<=35 && from >=0 && from<=35 && plainType(aBoard[from])==colorfor && aBoard[to]==emptyType 
                && ((from-to == 4 || from-to==5) 
                    || ((from-to == 10 && plainType(aBoard[from-5])==oppositeType(colorfor)) 
                        || (from-to == 8 && plainType(aBoard[from-4])==oppositeType(colorfor))) 
                    || (aBoard[from]==kingType(colorfor) 
                        && ((to-from == 4 || to-from==5) 
                            || ((to-from == 10 && plainType(aBoard[from+5])==oppositeType(colorfor)) 
                                || (to-from == 8 && plainType(aBoard[from+4])==oppositeType(colorfor)))))));
      }
      else {
        return (to>=0 && to<=35 && from >=0 && from<=35 && plainType(aBoard[from])==colorfor && aBoard[to]==emptyType 
                && ((to-from == 4 || to-from==5) 
                    || ((to-from == 10 && plainType(aBoard[from+5])==oppositeType(colorfor)) 
                        || (to-from == 8 && plainType(aBoard[from+4])==oppositeType(colorfor))) 
                    || (aBoard[from]==kingType(colorfor) 
                        && ((from-to == 4 || from-to==5) 
                            || ((from-to == 10 && plainType(aBoard[from-5])==oppositeType(colorfor)) 
                                || (from-to == 8 && plainType(aBoard[from-4])==oppositeType(colorfor))))))); // =)))))
      }
    }

    https://github.com/haiming020/BBS-AKB48/blob/master/src/Checkers.java

    zadrot, 01 Ноября 2014

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

    +139

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    struct Counter{
    	static int k;
    	Counter(){ k++; }
    	~Counter() { k--; }
    };
    int Counter::k = 0;
    #define LOL(x) {string s = #x; Counter c##x; cout<<s.substr(0,1+s.find('['))<<Counter::k<<"]="<<x<<'\n'; }

    Abbath, 01 Ноября 2014

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

    +145

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    function myscandir($dir){
    	if(!file_exists($dir)){
    		return false;
    	}
    
        $list = scandir($dir);
        unset($list[0],$list[1]);
        return array_values($list);
    }

    taras_shs, 31 Октября 2014

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

    +155

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    function generateSession()
    {
        $chars = "qazxswedcvfrtgbnhyujmkiolp1234567890QAZXSWEDCVFRTGBNHYUJMKIOLP";
        $max = rand(20, 32);
        $size = StrLen($chars) - 1;
        $sessionID = null;
        while ($max--)
            $sessionID .= $chars[rand(0, $size)];
        return $sessionID;
    }

    taras_shs, 31 Октября 2014

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

    +144

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    while (1) { // Не все знают логические значения
        ...
    }
    
    for (;;) // Ещё хуже
    { ... }

    nns2009, 31 Октября 2014

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

    +135

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    void SoundService::stop(){
        if (mOutputMixObj != NULL) {
            (*mOutputMixObj)->Destroy(mOutputMixObj);
            mOutputMixObj = NULL;
        }
        if(mEngineObj != NULL){
            (*mEngineObj)->Destroy(mEngineObj);
             mEngineObj = NULL; mEngine = NULL;
        }
    }

    Случайно нашёл в книге по Android NDK, открытой на случайной странице.

    tehned, 30 Октября 2014

    Комментарии (13)
  8. Python / Говнокод #17000

    −106

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    qdev_id, iops = _update_device_iops(instance, device_for_change)
    try:
    	qemu.volumes.set_io_throttle(controller.qemu(), qdev_id, iops)
    except Exception as e:
    	# Check if we turn off this instance? just a moment ago.
    	if "'NoneType' object has no attribute 'connected'" in e:
    		LOG.warning("kemu process seems to be killed")
    	else:
    		raise

    Метод set_io_throttle не бросает exception.
    Мы так проверяем,есть ли connection к qemu или нет.

    gmmephisto, 30 Октября 2014

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

    +133

    1. 1
    2. 2
    3. 3
    TopPassGridBox.ItemsSource = CollectionViewSource.GetDefaultView((from t in Edit_Curent_Pass.PassFieldList
    	where Edit_Curent_Pass.PassFieldList.IndexOf(t) == 0 || Edit_Curent_Pass.PassFieldList.IndexOf(t) == 1 || Edit_Curent_Pass.PassFieldList.IndexOf(t) == 2
    	select t).ToList());

    Я так и не понял, что хотели этим сказать...

    SantePaulinum, 30 Октября 2014

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

    +145

    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
    //bytes 0-13
      bmp.push_back('B'); bmp.push_back('M'); //0: bfType
      bmp.push_back(0); bmp.push_back(0); bmp.push_back(0); bmp.push_back(0); //2: bfSize; size not yet known for now, filled in later.
      bmp.push_back(0); bmp.push_back(0); //6: bfReserved1
      bmp.push_back(0); bmp.push_back(0); //8: bfReserved2
      bmp.push_back(54 % 256); bmp.push_back(54 / 256); bmp.push_back(0); bmp.push_back(0); //10: bfOffBits (54 header bytes)
    
      //bytes 14-53
      bmp.push_back(40); bmp.push_back(0); bmp.push_back(0); bmp.push_back(0);  //14: biSize
      bmp.push_back(width % 256); bmp.push_back(width / 256); bmp.push_back(0); bmp.push_back(0); //18: biWidth
      bmp.push_back(height % 256); bmp.push_back(height / 256); bmp.push_back(0); bmp.push_back(0); //22: biHeight
      bmp.push_back(1); bmp.push_back(0); //26: biPlanes
      bmp.push_back(outputChannels * 8); bmp.push_back(0); //28: biBitCount
      bmp.push_back(0); bmp.push_back(0); bmp.push_back(0); bmp.push_back(0);  //30: biCompression
      bmp.push_back(0); bmp.push_back(0); bmp.push_back(0); bmp.push_back(0);  //34: biSizeImage
      bmp.push_back(0); bmp.push_back(0); bmp.push_back(0); bmp.push_back(0);  //38: biXPelsPerMeter
      bmp.push_back(0); bmp.push_back(0); bmp.push_back(0); bmp.push_back(0);  //42: biYPelsPerMeter
      bmp.push_back(0); bmp.push_back(0); bmp.push_back(0); bmp.push_back(0);  //46: biClrUsed
      bmp.push_back(0); bmp.push_back(0); bmp.push_back(0); bmp.push_back(0);  //50: biClrImportant

    blackhearted, 30 Октября 2014

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