1. JavaScript / Говнокод #12277

    +156

    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
    this.start = function() {
    		// Инициализирует парсинг выгрузки из Агента Плюс.
    		if (this.open()) {
    			this.catalogs = this.getTags("catalogs", true)[0].childs;
    			this.subdocuments = this.getTags("documents", true)[1].childs;
    			this.guids = this.document.childs[0].childs[0].childs;
    			this.sellhistory = this.getCatalog("ИсторияПродаж").childs[0].childs;
    			this.sellpoints = this.getCatalog("ТорговыеТочки").childs[0].childs;
    			this.contragents = this.getCatalog("Контрагенты").childs[1].childs;
    			this.deals = this.getCatalog("Договоры").childs[0].childs;
    			this.nomenclature = this.getCatalog("Номенклатура").childs;
    			this.measure = this.getCatalog("ЕдиницыИзмерения").childs[0].childs;
    			this.route = this.getDocument("Маршрут").childs[0].childs[0].childs[0].childs[0]
    			this.names = {deals: [], catalog: [], nomenclature: [], measure: [], contragents: [], sellpoints: []};
    			this.info = {deals: [], catalog: [], nomenclature: [], measure: [], contragents: [], sellpoints: []};
    			this.hash = {deals: {}, nomenclature: {}, consts: {}, contragents: {}, sellpoints: [], measure: {}};
    			for (var i = 0; i < this.catalogs.length; i++) {
    				this.names.catalog.push(this.catalogs[i].attrib.Comment.replace(/Справочник\./g, ""));
    				this.info.catalog.push(this.catalogs[i].attrib);
    			}
    			for (var i = 0; i < this.nomenclature[1].childs.length; i++) {
    				this.names.nomenclature.push(this.nomenclature[1].childs[i].attrib.Name);
    				this.info.nomenclature.push(this.nomenclature[1].childs[i].attrib);
    				this.hash.nomenclature[this.nomenclature[1].childs[i].attrib.GUID] = this.nomenclature[1].childs[i].attrib;
    			}
    			for (var i = 0; i < this.deals.length; i++) {
    				this.names.deals.push(this.deals[i].attrib.Name);
    				this.info.deals.push(this.deals[i].attrib);
    				this.hash.deals[this.deals[i].attrib.GUID] = this.deals[i].attrib;
    			}
    			for (var i = 0; i < this.measure.length; i++) {
    				this.names.measure.push(this.measure[i].attrib.Name);
    				this.info.measure.push(this.measure[i].attrib);
    				this.hash.measure[this.measure[i].attrib.GUID] = this.measure[i].attrib;
    			}
    			for (var i = 0; i < this.contragents.length; i++) {
    				this.names.contragents.push(this.contragents[i].attrib.Name);
    				this.info.contragents.push(this.contragents[i].attrib);
    				this.hash.contragents[this.contragents[i].attrib.GUID] = this.contragents[i].attrib;
    			}
    			for (var i = 0; i < this.sellpoints.length; i++) {
    				this.names.sellpoints.push(this.sellpoints[i].attrib.Name);
    				this.info.sellpoints.push(this.sellpoints[i].attrib);
    				this.hash.sellpoints[this.sellpoints[i].attrib.GUID] = this.sellpoints[i].attrib;
    			}
    			for (var i = 0; i < this.guids.length; i++) {
    				this.hash.consts[this.guids[i].attrib.GUID] = this.guids[i].attrib.VALUE;
    			}
    			
    			this.dynamic.routes = new Array();
    			for (var i = 0; i < this.route.childs.length; i++) {
    				var sp = this.getSPointByGUID(this.route.childs[i].attrib.A02);
    				var adr = sp.Name;
    				var ca = this.getCAgentByGUID(this.route.childs[i].attrib.A01);
    				var ptypeguid = this.hash.deals[ca.A08].A06;
    				var cagent = ca.Name;
    				var dealguid = ca.A08;
    				var exists = false;
    				for (var j = 0; j < this.dynamic.routes.length; j++) if (this.dynamic.routes[j].address.trim().toLowerCase() == adr.trim().toLowerCase()) exists = exists || true;
    				if (!exists) this.dynamic.routes.push({ptypeguid: ptypeguid, spointguid: sp.GUID, address: adr, dealguid: dealguid, cagent: cagent, cagentguid: ca.GUID, datestamp: this.convRouteDate(this.route.childs[i].attrib.A03)});
    			}
    		} else return;
    	};

    Маленькая часть нашего скрипта для работы с 1С - Node.JS - WebClient.

    Govnisti_Diavol, 12 Декабря 2012

    Комментарии (9)
  2. Си / Говнокод #12276

    +133

    1. 1
    2. 2
    3. 3
    4. 4
    if ((frequency < config->frequency_max) || (frequency > config->frequency_min)) {
          printk(KERN_ERR "%s: Frequency beyond limits, frequency=%d\n", __func__, frequency);
          return -EINVAL;
        }

    Коллега отыскал где-то в недрах dvb подсистемы, в драйвере mopll'ки TDA6651.

    Necromant, 12 Декабря 2012

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

    +79

    1. 001
    2. 002
    3. 003
    4. 004
    5. 005
    6. 006
    7. 007
    8. 008
    9. 009
    10. 010
    11. 011
    12. 012
    13. 013
    14. 014
    15. 015
    16. 016
    17. 017
    18. 018
    19. 019
    20. 020
    21. 021
    22. 022
    23. 023
    24. 024
    25. 025
    26. 026
    27. 027
    28. 028
    29. 029
    30. 030
    31. 031
    32. 032
    33. 033
    34. 034
    35. 035
    36. 036
    37. 037
    38. 038
    39. 039
    40. 040
    41. 041
    42. 042
    43. 043
    44. 044
    45. 045
    46. 046
    47. 047
    48. 048
    49. 049
    50. 050
    51. 051
    52. 052
    53. 053
    54. 054
    55. 055
    56. 056
    57. 057
    58. 058
    59. 059
    60. 060
    61. 061
    62. 062
    63. 063
    64. 064
    65. 065
    66. 066
    67. 067
    68. 068
    69. 069
    70. 070
    71. 071
    72. 072
    73. 073
    74. 074
    75. 075
    76. 076
    77. 077
    78. 078
    79. 079
    80. 080
    81. 081
    82. 082
    83. 083
    84. 084
    85. 085
    86. 086
    87. 087
    88. 088
    89. 089
    90. 090
    91. 091
    92. 092
    93. 093
    94. 094
    95. 095
    96. 096
    97. 097
    98. 098
    99. 099
    100. 100
    //Unit1.h
    const float RADIAN=0.01744444444;
    TForm1 *Form1;
    Graphics::TBitmap*ZadniyBuffer;
    float ShipPosX,ShipPosY;
    float ShipAngle;
    float ShipSpeed;
    bool LEFT,RIGHT,UP;
    TList*Bullets;
    TList*Asteroids;
    class Bullet
    {
    public:
    float x,y,dx,dy;
    void CreateBullet()
            {
            x=ShipPosX;y=ShipPosY;
            dx=10*cos(RADIAN*ShipAngle);
            dy=10*sin(RADIAN*ShipAngle);
            }
    void Draw()
            {
            ZadniyBuffer->Canvas->Pen->Color=clRed;
            ZadniyBuffer->Canvas->MoveTo(x,y);
            ZadniyBuffer->Canvas->LineTo(x+dx,y+dy);
            }
    };
    class CRock
    {
    public:
    float x,y;
    int Figure[50];
    float Angle;
    float Spin;
    float XSpeed,YSpeed;
    int Tip;
    void CreateAsteroid(int t)
            {
            Tip=t;
            XSpeed=random(4)+(random(9)/10.0)-2;
            YSpeed=random(4)+(random(9)/10.0)-2;
            Spin=random(10)-5;
            for(int i=0;i<20;i++)
                    {
                    if(Tip==1)Figure[i]=random(10)+25;
                    if(Tip==2)Figure[i]=random(10)+10;
                    if(Tip==3)Figure[i]=random(5)+5;
                    }
            }
    void Move()
            {
            x+=XSpeed;y+=YSpeed;
            Angle+=Spin;
            if(x>440)x=-40;if(x<-40)x=440;
            if(y>440)y=-40;if(y<-40)y=440;
            }
    void Draw()
            {
             ZadniyBuffer->Canvas->Pen->Color=clRed;
            float tAng=0;
                    int tx=cos(RADIAN*(Angle+tAng))*Figure[0]+x;
                    int ty=sin(RADIAN*(Angle+tAng))*Figure[0]+y;
                    ZadniyBuffer->Canvas->MoveTo(tx,ty);
            for(int i=0;i<20;i++,tAng+=19)
                    {
                    int tx=cos(RADIAN*(Angle+tAng))*Figure[i]+x;
                    int ty=sin(RADIAN*(Angle+tAng))*Figure[i]+y;
                    ZadniyBuffer->Canvas->LineTo(tx,ty);
                    }
            }
    };
    //---------------------------------------------------------------------------
    __fastcall TForm1::TForm1(TComponent* Owner)
            : TForm(Owner)
    {
    randomize();
    ZadniyBuffer=new Graphics::TBitmap();
    ZadniyBuffer->Width =400;
    ZadniyBuffer->Height=400;
    ZadniyBuffer->Canvas->Pen->Color=clWhite;
    Bullets  =new TList();
    Asteroids=new TList();
    LEFT=false;RIGHT=false;
    ShipPosX=200;ShipPosY=200;
    ShipAngle=0;
    ShipSpeed=0;
    for(int i=0;i<4;i++)
    {
    CRock*a=new CRock();
    a->x=random(400);
    a->y=40;
    a->CreateAsteroid(1);
    Asteroids->Add((void*)a);
    }
    }
    //---------------------------------------------------------------------------
    void TForm1::CLS()
    {
            ZadniyBuffer->Canvas->Brush->Color=clBlack;
            ZadniyBuffer->Canvas->FillRect(Rect(0,0,400,400));

    Привет. Вот, украл, вернее, скачал с розришения автора код для курсача. На учебу билдера тупо времени нет, ибо есть много хвостов. Можете ли вы мне обьяснить весь код? Буду благодарен.

    kolybasov, 12 Декабря 2012

    Комментарии (36)
  4. C# / Говнокод #12274

    +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
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    /// <summary>
    /// Проверка пароля *
    /// </summary>
    private string CheckPassword(String _password)
    {
        int kol = 0;
        const int LEN = 32;
        if (_password.Length == LEN)
            return _password;
        else
        {
            StringBuilder _pass = new StringBuilder(_password, LEN);
            if (_password.Length > LEN)
            {
                kol = _password.Length - LEN;
                return (_password.Substring(0, _password.Length - kol));
            }
            else
            {
                kol = LEN - _password.Length;
                int i = 0;
                while (i != kol)
                {
                    _pass.Append(" ");
                    i++;
                }
            }
            return _pass.ToString();
        }
    }

    Crazzy, 12 Декабря 2012

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

    −90

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    def getEML(self):
            for i in self.__mandatory_headers:
                if i not in self.__headers:
                    return None
            return '{}\r\n\r\n{}'.format('\r\n'.join(['{}: {}'.format(k, v) for k, v in self.__headers.iteritems()]), self.__body)

    Наверное, надо подумать, как переписать в виде лямбды для пущего эффекта

    Miketsukami, 12 Декабря 2012

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

    +91

    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
    procedure RecursiveVisibility(e : PCreature; oct, depth : integer; slopeA, slopeB : single);
    var
      x, y : integer;
    begin
      case oct of
        1 : begin
          y := e^.y - depth;                                                { initialize y }
          x := round(e^.x - slopeA * depth);                                { initialize z }
          while GetSlopeStd(x, y, e^.x, e^.y) >= slopeB do begin            { while in octant }
            if GetVisDistance(x, y, e^.x, e^.y) <= mw then begin            { if within max visual range }
              if WorldSurface[x, y].entity^.obstruct then begin             { if obstruction }
                if not WorldSurface[x - 1, y].entity^.obstruct then begin   { if no prior obstruction }
                  RecursiveVisibility(e, 1, depth + 1, slopeA, GetSlopeStd(x - 0.5, y + 0.5, e^.x, e^.y));
                end;                                                        { ^create recursive scan }
              end else begin                                                { no obstruction }
                if WorldSurface[x - 1, y].entity^.obstruct then begin       { if prior obstruction }
                  slopeA := GetSlopeStd(x - 0.5, y - 0.5, e^.x, e^.y);      { adjust slope for later recursion }
                end;
              end;
              WorldSurface[x, y].visibility := 3;                           { set block visible }
            end;
            inc(x);
          end;
          dec(x)
        end;
        2 : begin
          y := e^.y - depth;                                                { initialize y }
          x := round(e^.x + slopeA * depth);                                { initialize z }
          while GetSlopeStd(x, y, e^.x, e^.y) <= slopeB do begin            { while in octant }
            if GetVisDistance(x, y, e^.x, e^.y) <= mw then begin            { if within max visual range }
              if WorldSurface[x, y].entity^.obstruct then begin             { if obstruction }
                if not WorldSurface[x + 1, y].entity^.obstruct then begin   { if no prior obstruction }
                  RecursiveVisibility(e, 2, depth + 1, slopeA, GetSlopeStd(x + 0.5, y + 0.5, e^.x, e^.y));
                end;                                                        { ^create recursive scan }
              end else begin                                                { no obstruction }
                if WorldSurface[x + 1, y].entity^.obstruct then begin       { if prior obstruction }
                  slopeA := -GetSlopeStd(x + 0.5, y - 0.5, e^.x, e^.y);     { adjust slope for later recursion }
                end;
              end;
              WorldSurface[x, y].visibility := 3;                           { set block visible }
            end;
            dec(x);
          end;
          inc(x)
        end;
     // Далее всё в таком же духе.

    Отсюда: http://roguebasin.roguelikedevelopment.org/index.php?title=FOV_using_recursive_shad owcasting_-_improved
    Можно было сделать менее говнокодистей?

    Govnocoder#0xFF, 11 Декабря 2012

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

    +75

    1. 1
    2. 2
    echo( TRUE ? "1" : TRUE ? "2":"3");
    //2

    http://ideone.com/UBg3T2
    В ответ на это:
    http://govnokod.ru/12268#comment163978

    3.14159265, 11 Декабря 2012

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

    −100

    1. 1
    (lambda x:request.profile.role if request.profile.role!=5 else 4)(request.profile.role)

    хуита, 11 Декабря 2012

    Комментарии (48)
  9. Си / Говнокод #12269

    +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
    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
    #include <stdio.h>
    #include <conio.h>
    #include <windows.h>
    
    int main()
    {
    	nachalo: system("cls");
    	int a;
    	printf("Write first number...");
    	scanf("%i", &a);
    
    	int b;
    	printf("Write second number...");
    	scanf("%i", &b);
    
    	int res1;
    	res1=a+b;
    
    	int res2;
    	res2=a-b;
    
    	int res3;
    	res3=a*b;
    
    	float res4;
    	res4=(float)a/b;
    
    	int res5;
    	res5=a*a;
    
    	int res6;
    	res6=b*b;
    
    	printf("\nSumm of %i + %i = %i\n", a, b, res1);
    	printf("Difference of %i - %i = %i\n", a, b, res2);
    	printf("Production of %i * %i = %i\n", a, b, res3);
    	printf("Private of %i / %i = %.4f\n\n", a, b, res4);
    	printf("Square of %i is %i\n", a, res5);
    	printf("Square of %i is %i\n\n", b, res6);
    
    	int max;
    	max = (b>a) ? b:a;
    	printf("The greatest number of %i and %i is %d\n\n", a, b, max);
    
    	int choice;
    	printf("To run program again, press number 1, else numbers \nor symbols will close the program...\n> ");
    	scanf("%i", &choice);
    	if (choice == 1)
    	{
    		goto nachalo;
    	}
    	else (choice != 1);
    	{
    		return 0;
    	}
    }

    Калькулятор. Nuff said

    heivizi, 11 Декабря 2012

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

    +50

    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
    <?php
    session_start();
    if(empty($_SESSION['UserLogin']) or empty($_SESSION['UserId']))
    {
      header('Location: /');
    }
    else
    {
      include("application/db.config.php");
      $GetterUser = $_POST['ForUser'];
      $SenderUser = $_SESSION['UserId'];
      $Rem = strip_tags($_POST['Rem']);
      $Text = strip_tags($_POST['Text']);
    
      if($Rem == "" or $Text == "")
      {
        header("Location: sent_mess?to=$GetterUser&status=bad");
      }
      else
      {
        $SendingMessQuery = mysql_query("INSERT INTO Dialogs(From, To, Rem, Text) VALUES($SenderUser, $GetterUser, '$Rem', '$Text')", $db) or die(mysql_error());
        mysql_close($db);
        header("Location: sent_mess?to=$GetterUser&status=good");
      }
    }
    ...

    Govnisti_Diavol, 11 Декабря 2012

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