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

    −1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    for (k = k + 0, j = 0; j < m; j++)
    {
        b[k] = mat[i][j];
        cout << b[k];
    }

    Увидел в лабе у чела из универа. Почему бы лишний раз не присвоить k собственное значение

    VladimirM4K, 21 Октября 2021

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

    0

    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
    /* https://github.com/v7unix/v7unix/blob/ed636a47207476db76d53b7869447889dee3bbad/v7/usr/src/cmd/sh/mac.h */
    
    #
    /*
     *	UNIX shell
     *
     *	S. R. Bourne
     *	Bell Telephone Laboratories
     *
     */
    
    #define LOCAL	static
    #define PROC	extern
    #define TYPE	typedef
    #define STRUCT	TYPE struct
    #define UNION	TYPE union
    #define REG	register
    
    #define IF	if(
    #define THEN	){
    #define ELSE	} else {
    #define ELIF	} else if (
    #define FI	;}
    
    #define BEGIN	{
    #define END	}
    #define SWITCH	switch(
    #define IN	){
    #define ENDSW	}
    #define FOR	for(
    #define WHILE	while(
    #define DO	){
    #define OD	;}
    #define REP	do{
    #define PER	}while(
    #define DONE	);
    #define LOOP	for(;;){
    #define POOL	}
    
    
    #define SKIP	;
    #define DIV	/
    #define REM	%
    #define NEQ	^
    #define ANDF	&&
    #define ORF	||
    
    #define TRUE	(-1)
    #define FALSE	0
    #define LOBYTE	0377
    #define STRIP	0177
    #define QUOTE	0200
    
    #define EOF	0
    #define NL	'\n'
    #define SP	' '
    #define LQ	'`'
    #define RQ	'\''
    #define MINUS	'-'
    #define COLON	':'
    
    #define MAX(a,b)	((a)>(b)?(a):(b))

    j123123, 20 Октября 2021

    Комментарии (76)
  3. Куча / Говнокод #27759

    0

    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
    Let's count a number of rules that can be built in GoL-like automatas. Rule is the matrix that maps some condition of cells to new state.
    Cell itself could be alive or dead. And cell could have 0-8 neighbors. So, there are 2^(2*9) = 262144 different rules. Well known, that
    the majority of them are primitive and produces some pure pattern or just dies in finite number of generations / infinitely fills the world
    with alive cells. We also know that some rules are symmetric to each other as if we just rename (swap colors of) alive and dead cells.
    
    Conway found the most interesting rule from entropy point of view.
    
    2^18 is not so much. Let's take a look at 2D automata known as Rule 110. State 100 keeps cell dead:
    
    100 -> 0
    
    While state 001 makes cell alive:
    
    001 -> 1
    
    In terms of neighborhood, this two rules are indifferent: both means one live neighbor next to dead cell. But in Rule 110 not only a /number/
    of neighbors is meaningful, but the /position/ of separate neighbor.
    
    Let's imagine the GoL-like rule with the same property: we will look not only at number of neighbors, but at their position. What if to have one
    neighbor at north-west gives not the same result as if neighbor were at south-east.
    
    This change gives us much more different rules. If each neighbor is meaningful, then we have 2 ^ 8 different states of neighborhood, and cell
    could be still alive or dead. If I'm not wrong there must be 2 ^ (2 * (2 ^ 8)) = 2 ^ 512 different rules.
    
    Obviously, this space includes Conway's Game of Life and all different rules from that 262144, and gives billions of new ones. Obviously,
    the majority of them are trivial too. But there may be some interesting entropy-like rules different from the Conway's one.
    
    This space is too huge to be discovered manually, and even with bruteforce algorithms too. But evolution algorithms could be used to find rules
    with some special properties.
    
    So, I have two questions:
    
    1) Does this space has a given name, anybody researched that?
    
    2) I will be glad to hear any ideas on how to make this space simpler by excluding symmetric states etc. to save the time for discovering.

    Any cellular nerds here?

    vistefan, 20 Октября 2021

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

    0

    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
    #include <string>
    #include <iostream>
     
    int foo() {
    	std::string str = "file://*";
    	std::cout << str << std::endl;
    	return 0;
    }
     
    /*
    int bar() {
    	std::string str = "file://*";       // warning: '/*' within block comment [-Wcomment]
    	std::cout << str << std::endl;
    	return 0;
    }
    */
     
    int main() {
    	foo();
    	//bar();
    }

    Какой багор

    https://ideone.com/NiXH2q

    3_dar, 19 Октября 2021

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

    0

    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
    class UserCreate(MethodView):
        """Data create."""
    
        def post(self):
            """Создание данных."""
            q = 1
            values = {}
            values['person'] = request.json_schema["person"]
            values['date_opr'] = request.json_schema["dateOpr"]
            values['year_input'] = request.json_schema["yearInput"]
            values['vuz'] = request.json_schema["vuz"]
            values['person_id'] = request.json_schema["personId"]
            q = 1
            with session_scope() as session:
                id = candidate_service.create_item(session, values)
            return {"msg": "Данные созданы", "data": {"id": id}}

    зачем эта переменная q???

    super_govnokoder, 18 Октября 2021

    Комментарии (36)
  6. Си / Говнокод #27753

    0

    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
    // https://github.com/x42/darc.lv2/blob/7f1f42b879777e570c83fd566ac28cbfdd51e6fc/src/lv2.c#L508
    static void
    create_pattern (Darc* self, const double w)
    {
    	const int x0 = floor (w * 0.05);
    	const int x1 = ceil (w * 0.95);
    	const int wd = x1 - x0;
    
    #define DEF(x) ((x0 + wd * ((x) + 20.) / 60.) / w)
    
    	cairo_pattern_t* pat = cairo_pattern_create_linear (0.0, 0.0, w, 0);
    	/* clang-format off */
    	cairo_pattern_add_color_stop_rgba (pat, 1.0,       .0, .5, .0, 0);
    	cairo_pattern_add_color_stop_rgba (pat, DEF (40),  .0, .5, .0, 0.5);
    	cairo_pattern_add_color_stop_rgba (pat, DEF (5),   .0, .5, .0, 0.5);
    	cairo_pattern_add_color_stop_rgba (pat, DEF (-5),  .5, .0, .0, 0.5);
    	cairo_pattern_add_color_stop_rgba (pat, DEF (-20), .5, .0, .0, 0.5);
    	cairo_pattern_add_color_stop_rgba (pat, 0.0,       .5, .0, .0, 0);
    	/* clang-format on */
    	self->mpat = pat;
    
    	pat = cairo_pattern_create_linear (0.0, 0.0, w, 0);
    	/* clang-format off */
    	cairo_pattern_add_color_stop_rgba (pat, 1.0,       .1, .9, .1, 0);
    	cairo_pattern_add_color_stop_rgba (pat, DEF (40),  .1, .9, .1, 1);
    	cairo_pattern_add_color_stop_rgba (pat, DEF (5),   .1, .9, .1, 1);
    	cairo_pattern_add_color_stop_rgba (pat, DEF (-5),  .9, .9, .1, 1);
    	cairo_pattern_add_color_stop_rgba (pat, DEF (-20), .9, .9, .1, 1);
    	cairo_pattern_add_color_stop_rgba (pat, 0.0,       .9, .9, .1, 0);
    	/* clang-format on */
    	self->cpat = pat;
    
    #undef DEF
    }

    Отключаем и включаем clang-формат, чтобы отступы красиво были. Да еще и такой вот локальный дефайн!

    j123123, 17 Октября 2021

    Комментарии (116)
  7. Pascal / Говнокод #27748

    −1

    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
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    function ReplaceHTMLSpec(First, Last, RepTo, RepEd:string):string;
    var
      I, P, St:Integer;
      SS, Temp:string;
    begin
      Temp:='';
      ST:=0;
      while True do
      begin
        P:=Pos(First, Result);
        if P = 0 then Break;
        SS:=Copy(Result, ST, P-1)+RepTo;
        Temp:=Temp+SS;
        ST:=P+Length(First);
        Result:=Copy(Result, ST, MaxInt);
        P:=Pos(Last, Result);
        if P > 0 then
        begin
          SS:=Copy(Result, 1, P-1)+RepEd;
          Temp:=Temp+SS;
          ST:=P+Length(Last);
          SS:=Copy(Result,ST, MaxInt);
          Temp:=Temp+SS;
        end;
        Result:=Temp;
      end;
    end;
    
    function DecorateText(S:string):string;
    const
      Arr:array[0..3] of string=('<br>','&quot;','&lt;','&gt;');
    var
      I, P, St:Integer;
      SS, Temp:string;
    begin
      Result:=S;
      for I:=0 to 3 do
      Result:=StringReplace(Result, Arr[I], '',[rfreplaceall]);
      Result:=StringReplace(Result,'<br />',#13#10,[rfreplaceall]);
      Result:=StringReplace(Result,'<i>','[i]',[rfreplaceall]);
      Result:=StringReplace(Result,'</i>','[/i]',[rfreplaceall]);
      Result:=StringReplace(Result,'<b>','[b]',[rfreplaceall]);
      Result:=StringReplace(Result,'</b>','[/b]',[rfreplaceall]);
      Temp:='';
      ST:=0;
     { while True do
      begin
        P:=Pos('<span style="font-size:10px;">', Result);
        if P = 0 then Break;
        SS:=Copy(Result, ST, P-1)+'[size=10]';
        Temp:=Temp+SS;
        ST:=P+Length('<span style="font-size:10px;">');
        Result:=Copy(Result, ST, MaxInt);
        P:=Pos('</span>', Result);
        if P > 0 then
        begin
          SS:=Copy(Result, 1, P-1)+'[/size]';
          Temp:=Temp+SS;
          ST:=P+Length('</span>');
          SS:=Copy(Result,ST, MaxInt);
          Temp:=Temp+SS;
          Result:=Temp;
        end;
      end;   }
    
      Result:=ReplaceHTMLSpec('<span style="color:white;">','</span>','[color=white]','[/color]');
      Result:=ReplaceHTMLSpec('<span style="color:red;">','</span>','[color=red]','[/color]');
      Result:=ReplaceHTMLSpec('<span style="color:blue;">','</span>','[color=blue]','[/color]');
      Result:=ReplaceHTMLSpec('<span style="color:green;">','</span>','[color=green]','[/color]');
      Result:=ReplaceHTMLSpec('<pre><code class="">','</code></pre>','[code]','[/code]');
      Result:=ReplaceHTMLSpec('<span style="font-size:10px;">','</span>','[size=10]','[/size]');
      Result:=ReplaceHTMLSpec('<span style="font-size:15px;">','</span>','[size=15]','[/size]');
      Result:=ReplaceHTMLSpec('<span style="font-size:20px;">','</span>','[size=20]','[/size]');
      Result:=ReplaceHTMLSpec('<span style="text-decoration:underline;">','</span>','[u]','[/u]');
      Result:=ReplaceHTMLSpec('<span style="text-decoration:line-through;">','</span>','[s]','[/s]');
      Result:=ReplaceHTMLSpec('<span style="text-decoration:blink;">','</span>','[blink]','[/blink]');
    end;

    Пахнет селёдкой. Ой блять, забыл подмыться.

    Support, 16 Октября 2021

    Комментарии (406)
  8. Куча / Говнокод #27746

    0

    1. 1
    Время вечерней молитвы.

    Примите положение А1. Постарайтесь сосредоточиться, соберитесь с мыслями. Прочтите молитву.
    Инициализируйте процедуру-коллбек.

    nPOnOBeDHuK, 15 Октября 2021

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

    0

    1. 1
    Application was halted by an exception.

    Error 520
    Ray ID: 69e3d61cfd95169b •
    2021-10-14 21:18:17 UTC
    Web server is returning an unknown error
    You
    Browser Working
    Moscow
    Cloudflare Working
    govnokod.ru
    Host Error
    What happened?

    There is an unknown connection issue between Cloudflare and the origin web server. As a result, the web page can not be displayed.
    What can I do?

    If you are a visitor of this website:

    Please try again in a few minutes.

    If you are the owner of this website:

    There is an issue between Cloudflare's cache and your origin web server. Cloudflare monitors for these errors and automatically investigates the cause. To help support the investigation, you can pull the corresponding error log from your web server and submit it our support team. Please include the Ray ID (which is at the bottom of this error page). Additional troubleshooting resources.
    Cloudflare Ray ID: 69e3d61cfd95169b
    Your IP: 91.197.11.236
    Performance & security by Cloudflare

    OCETuHCKuu_nemyx, 15 Октября 2021

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

    0

    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
    function main4() {
    
        let i = 0;
    
        try {
            try {
                throw 1.0;
            }
            catch (e: number) {
                i++;
                print("asd1");
                throw 2.0;
            }
            finally {
                print("finally");
            }
        }
        catch (e2: number) {
            i++;
            print("asd3");
        }
    
        assert(i == 2);
    }
    
    function main() {
        main4();
        print("done.");
    }

    Ну вот и все.. шах и мат С/C++ девелоперы... последняя хитровые...аная инструкция finally сделана. (надо еще для линуха сделать .. а то они разные)

    ASD_77, 13 Октября 2021

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