1. C++ / Говнокод #3463

    +158

    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
    #include <math.h>
    #include <stdio.h>
    double zero = 0, three = 3, four = 4;
    class Complex
         {
            public:
            double &x, &y;
            Complex() : x(zero), y(zero) { }
            Complex( double &z ) : x(y), y(z) { }
            Complex( double &_x, double &_y ) : x(_x), y(_y) { }
         };
         double square( double const &x ) { return x * x; }
         double absValue( Complex &c ) { return sqrt( square(c.x)+square(c.y) ); }
         int main()
         {
             Complex c(four);
             printf( "absolute value is %g\n", absValue( c ) );
             return 0;
         }

    говно отсюда http://www.gimpel.com/html/bugs.htm

    xXx_totalwar, 13 Июня 2010

    Комментарии (13)
  2. PHP / Говнокод #3462

    +154

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    function nameFilter(str){
    
    		var re = /^(oxypit|Штемп|хуй|пиде|пидр|пидо|пида|гыы|Techn|PIZDA)/i
    		if (re.test(str)) return true; else return false;
    
    }

    hromjo, 12 Июня 2010

    Комментарии (24)
  3. VisualBasic / Говнокод #3461

    −98

    1. 1
    lDate = DateSerial(Year(Date), Month(Date), Day(Date) - Day(Date) + 1)

    Человек формирует дату - 1 число текущего месяца.
    В каком классе учат упрощать выражения вида х-х+у?

    govnobot, 11 Июня 2010

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

    +167

    1. 1
    2. 2
    3. 3
    4. 4
    $filename_enc = urlencode($link);
    header("Content-Type: application/octet-stream");
    header("Content-Disposition: attachment; filename=kino.css");
    echo(file_get_contents("ftp://127.0.0.1/pub/films/06/1096/01/1096_01_01.mkv"));

    symbix, 11 Июня 2010

    Комментарии (12)
  5. JavaScript / Говнокод #3459

    +184

    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
    function reverse_string(str, len) {
    	if (len == 1) {
    		return str.charAt(0);
    	}
    	if (len == 2) {
    		return str.charAt(1) + str.charAt(0);
    	}
    	if (len == 3) {
    		return str.charAt(2) + str.charAt(1) + str.charAt(0);
    	}
    	if (len == 4) {
    		return str.charAt(3) + str.charAt(2) + str.charAt(1) + str.charAt(0);
    	}
    	if (len == 5) {
    		return str.charAt(4) + str.charAt(3) + str.charAt(2) + str.charAt(1) + str.charAt(0);
    	}
    	if (len == 6) {
    		return str.charAt(5) + str.charAt(5) + str.charAt(3) + str.charAt(2) + str.charAt(1) + str.charAt(0);
    	}
    	if (len == 7) {
    		return str.charAt(6) + str.charAt(5) + str.charAt(4) + str.charAt(3) + str.charAt(2) + str.charAt(1) + str.charAt(0);
    	}
    	if (len == 8) {
    		return str.charAt(7) + str.charAt(6) + str.charAt(5) + str.charAt(4) + str.charAt(3) + str.charAt(2) + str.charAt(1) + str.charAt(0);
    	}
    	if (len == 9) {
    		return str.charAt(8) + str.charAt(7) + str.charAt(6) + str.charAt(5) + str.charAt(4) + str.charAt(3) + str.charAt(2) + str.charAt(1) + str.charAt(0);
    	}
    	if (len == 10) {
    		return str.charAt(9) + str.charAt(8) + str.charAt(7) + str.charAt(6) + str.charAt(5) + str.charAt(4) + str.charAt(3) + str.charAt(2) + str.charAt(1) + str.charAt(0);
    	}
    };

    Переворачивание строки при помощи новейших технологий. Также ожидается движок (по содержанию конечно кусок говна, но по размерам похож), который позволит переворачивать строки любой длины (таким же методом). В-общем, прогноз неутешительный.

    eval, 11 Июня 2010

    Комментарии (98)
  6. Pascal / Говнокод #3458

    +99

    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
    procedure TCommonFineEdit.SetTopControls;
    begin
      if beSummHist.Visible then
        SummEdit.Width := 92
      else
        SummEdit.Width := 108;
      if VarToInt(Oper.OperationType) in [otFine, otNoAgreeFine, otPayFine, otPayFineCorrect] then
        begin
          NameEdit.Top := 16;
          Label1.Top := NameEdit.Top+3;
          PODateEdit.Top := 47;
          AccountDateJvDateEdit.Top := PODateEdit.Top;
          label3.Top := PODateEdit.Top+3;
          lPODate.Top := PODateEdit.Top+3;
          beSummHist.Top := 77;
          SummEdit.Top := 78;
          POSummEdit.Top := SummEdit.Top;
          label12.Top := SummEdit.Top+3;
          lPOSumm.Top := SummEdit.Top+3;
          StateComboBox.Top := 109;
          label4.Top := StateComboBox.Top+3;
          InspectNameEdit.Top := 140;
          InspectNameLabel.Top := InspectNameEdit.Top+3;
          CommentEdit.Top := 171;
          label2.Top := CommentEdit.Top+3;
          if ftSale then
          begin
            RateNameEdit.Top := 202;
            lRate.Top := RateNameEdit.Top+3;
            BasePriceEdit.Top := 233;
            PaySummMoneyEdit.Top := BasePriceEdit.Top;
            lMoney.Top := BasePriceEdit.Top+3;
            lBasePrice.Top := BasePriceEdit.Top+3;
            Height := 368;
          end else
            Height := 310;
        end
    ...

    Umak, 11 Июня 2010

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

    +144

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    class MySoapClient extends SoapClient
    ...
    	public function __doRequest($request, $location, $action, $version, $one_way = null) {
    		$result = parent::__doRequest($request, $location, $action, $version, $one_way);
                    echo $this->__getLastRequest();//вот этот момент интересен
    		return $result;
    	}

    Кто-нибудь может объяснить почему ничего не возвращает строчка, с комментарием которая?
    При создании 'trace'=>TRUE указан.
    Если вызывать __getLastRequest() вне данной функции, то все работает.
    Можно ли в __doRequest это сделать?

    gansm, 11 Июня 2010

    Комментарии (15)
  8. Си / Говнокод #3456

    +139

    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
    int main() {
      unsigned long oct;
      int m,n,i,j;	
      int max=0;
      
      scanf("%d",&oct);
      for(i=0;i<=32/3;i++) {
        m=0;
        for(j=0;j<=2;j++) {
          n=oct & 1;
          if(n==1)
            m=m | power(2,j);
          oct=oct >> 1;  
        } 
      if(m>max)
        max=m;                   
      }
      printf("%d",max);  
      return 0;
    }
    
    int power(int x, int a) {
      int i;
      int t=x;
      if(a==0)
        t=1;
      else {  
      for(i=1;i<a;i++)
        t*=x; 
      }
      return t;  
    }

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

    movaxbx, 11 Июня 2010

    Комментарии (45)
  9. Python / Говнокод #3455

    −164

    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
    def _elementWidth(self,v,s):                                                                                        
        t = type(v)                                                                                                     
        if t in _SeqTypes:                                                                                              
            w = 0                                                                                                       
            for e in v:                                                                                                 
                ew = self._elementWidth(self,v)                                                                         
                if ew is None: return None                                                                              
                    w = max(w,ew)                                                                                           
                    return w                                                                                                    
                elif isinstance(v,Flowable) and v._fixedWidth:                                                                  
                    return v.width                                                                                              
                else:                                                                                                           
                    if t is not StringType: v = v is None and '' or str(v)                                                      
                        v = string.split(v, "\n")                                                                                   
                        return max(map(lambda a, b=s.fontname, c=s.fontsize,d=pdfmetrics.stringWidth: d(a,b,c), v))

    Нашел в коде библиотеки Reportlab. Особенно нравится строчка №13.

    Chaka_bum, 11 Июня 2010

    Комментарии (15)
  10. Си / Говнокод #3454

    +141

    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
    #include <stdio.h>
    
    int main() {
    	unsigned d,t,k;
    	scanf("%d",&d);
    	t=d;
    	for(k=0;t!=0;k++) //определяем кол-во значащих битов
    		t>>=1;
    	//обнуляем старший значащий бит
    	d<<=sizeof(d)*8-k+1; 
    	d>>=sizeof(d)*8-k+1; 
    	return 0;
    }

    Вот такое вот обнуление старшего бита

    movaxbx, 11 Июня 2010

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