1. 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)
  2. 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)
  3. 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)
  4. 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)
  5. Python / Говнокод #12270

    −100

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

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

    Комментарии (48)
  6. Си / Говнокод #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)
  7. 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)
  8. SQL / Говнокод #12267

    −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
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    CREATE TABLE calendar
    (
      caldate date NOT NULL,
      "month" integer NOT NULL,
      month_txt character varying(10) NOT NULL,
      "year" integer NOT NULL,
      CONSTRAINT calendar_pkey PRIMARY KEY (caldate)
    )
    CREATE TABLE holiday
    (
      id numeric(10,0) NOT NULL DEFAULT nextval('holiday_seq'::regclass),
      caldate date NOT NULL,
      region integer,
      CONSTRAINT holidaypk PRIMARY KEY (id),
      CONSTRAINT fk_hday_caldate FOREIGN KEY (caldate)
          REFERENCES calendar (caldate) MATCH SIMPLE
          ON UPDATE NO ACTION ON DELETE NO ACTION,
      CONSTRAINT holidayfk FOREIGN KEY (region)
          REFERENCES region (id) MATCH SIMPLE
          ON UPDATE NO ACTION ON DELETE NO ACTION
    )

    Вот такая вот структура база в проекте в котором я работаю.
    Причём помимо таблицы calendar и дублирование там информации, обратите внимание на таблицу holiday в эту таблицу записи ручками вносятся о выходных днях или о праздниках, как впрочем и в таблицу calendar

    smpl, 10 Декабря 2012

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

    +163

    1. 1
    jQuery("body").trigger( F11 )

    Попытка перейти в полноэкранный режим.. Найдено в недрах одного довольно серьезного проекта.

    diezvl, 10 Декабря 2012

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

    +141

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    if(is_dir('install')|| is_dir('migrate')) {
            if (!file_exists(PATH.'/includes/config.inc.php')){
                header('location:/install/');
    			die();
            } else {
                include(PATH.'/core/messages/installation.html');
                die();
            }
        }

    Govnisti_Diavol, 10 Декабря 2012

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