1. bash / Говнокод #27767

    −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
    #!/bin/bash
    
    status=$(xinput list-props 11 | grep 'Device Enabled' | tail -c 2 | tr -d '\n')
    
    echo "Current TB status: $status"
    
    if [[ $status = "0" ]]
    then
        xinput enable 11
        echo "Enabled touchpad!"
    else
        xinput disable 11
        echo "Disabled touchpad!"
    fi

    Как вам мой скриптик?

    JloJle4Ka, 25 Октября 2021

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

    −1

    1. 1
    IT Оффтоп #131

    #101: https://govnokod.ru/27511 https://govnokod.xyz/_27511
    #102: https://govnokod.ru/27518 https://govnokod.xyz/_27518
    #103: https://govnokod.ru/27526 https://govnokod.xyz/_27526
    #104: https://govnokod.ru/27534 https://govnokod.xyz/_27534
    #105: https://govnokod.ru/27544 https://govnokod.xyz/_27544
    #106: https://govnokod.ru/27552 https://govnokod.xyz/_27552
    #107: https://govnokod.ru/27554 https://govnokod.xyz/_27554
    #108: https://govnokod.ru/27557 https://govnokod.xyz/_27557
    #109: https://govnokod.ru/27581 https://govnokod.xyz/_27581
    #110: https://govnokod.ru/27610 https://govnokod.xyz/_27610
    #111: https://govnokod.ru/27644 https://govnokod.xyz/_27644
    #112: https://govnokod.ru/27648 https://govnokod.xyz/_27648
    #113: https://govnokod.ru/27652 https://govnokod.xyz/_27652
    #114: https://govnokod.ru/27659 https://govnokod.xyz/_27659
    #115: https://govnokod.ru/27665 https://govnokod.xyz/_27665
    #116: https://govnokod.ru/27671 https://govnokod.xyz/_27671
    #117: https://govnokod.ru/27675 https://govnokod.xyz/_27675
    #118: https://govnokod.ru/27685 https://govnokod.xyz/_27685
    #119: https://govnokod.ru/27701 https://govnokod.xyz/_27701
    #120: https://govnokod.ru/27703 https://govnokod.xyz/_27703
    #121: https://govnokod.ru/27710 https://govnokod.xyz/_27710
    #122: https://govnokod.ru/27728 https://govnokod.xyz/_27728
    #123: https://govnokod.ru/27729 https://govnokod.xyz/_27729
    #124: https://govnokod.ru/27730 https://govnokod.xyz/_27730
    #125: https://govnokod.ru/27732 https://govnokod.xyz/_27732
    #126: https://govnokod.ru/27733 https://govnokod.xyz/_27733
    #127: https://govnokod.ru/27737 https://govnokod.xyz/_27737
    #128: https://govnokod.ru/27742 https://govnokod.xyz/_27742
    #129: https://govnokod.ru/27747 https://govnokod.xyz/_27747
    #130: https://govnokod.ru/27755 https://govnokod.xyz/_27755

    nepeKamHblu_nemyx, 23 Октября 2021

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

    +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
    78. 78
    79. 79
    80. 80
    81. 81
    waiting_for_data(info, {Driver,Socket,Data},
                     #state{socket=Socket, driver=Driver, driver_mod=DriverMod, peer=Peer, control=Control, list=List} = State) ->
        %% The meat of the whole project: process a function call and return
        %% the data
        try erlang:binary_to_term(Data) of
            {{CallType,M,F,A}, Caller} when CallType =:= call; CallType =:= async_call ->
                {ModVsnAllowed, RealM} = check_module_version_compat(M),
                case check_if_module_allowed(RealM, Control, List) of
                    true ->
                        case ModVsnAllowed of
                            true ->
                                WorkerPid = erlang:spawn(?MODULE, call_worker, [CallType, RealM, F, A, Caller, Socket, Driver, DriverMod]),
                                ?log(debug, "event=call_received driver=~s socket=\"~s\" peer=\"~s\" caller=\"~p\" worker_pid=\"~p\"",
                                     [Driver, gen_rpc_helper:socket_to_string(Socket), gen_rpc_helper:peer_to_string(Peer), Caller, WorkerPid]),
                                {keep_state_and_data, gen_rpc_helper:get_inactivity_timeout(?MODULE)};
                            false ->
                                ?log(debug, "event=incompatible_module_version driver=~s socket=\"~s\" method=~s module=~s",
                                     [Driver, gen_rpc_helper:socket_to_string(Socket), CallType, RealM]),
                                waiting_for_data(info, {CallType, Caller, {badrpc,incompatible}}, State)
                        end;
                    false ->
                        ?log(debug, "event=request_not_allowed driver=~s socket=\"~s\" control=~s method=~s module=~s",
                             [Driver, gen_rpc_helper:socket_to_string(Socket), Control, CallType, RealM]),
                        waiting_for_data(info, {CallType, Caller, {badrpc,unauthorized}}, State)
                end;
            {cast, _M, _F, _A} = Cast ->
                handle_cast(Cast, State),
                {keep_state_and_data, gen_rpc_helper:get_inactivity_timeout(?MODULE)};
            BatchCast when is_list(BatchCast) ->
                [handle_cast(Cast, State) || Cast <- BatchCast],
                {keep_state_and_data, gen_rpc_helper:get_inactivity_timeout(?MODULE)};
            {abcast, Name, Msg} ->
                _Result = case check_if_module_allowed(erlang, Control, List) of
                    true ->
                        ?log(debug, "event=abcast_received driver=~s socket=\"~s\" peer=\"~s\" process=~s message=\"~p\"",
                             [Driver, gen_rpc_helper:socket_to_string(Socket), gen_rpc_helper:peer_to_string(Peer), Name, Msg]),
                        Msg = erlang:send(Name, Msg);
                    false ->
                        ?log(debug, "event=request_not_allowed driver=~s socket=\"~s\" control=~s method=~s",
                             [Driver, gen_rpc_helper:socket_to_string(Socket), Control, abcast])
                    end,
                {keep_state_and_data, gen_rpc_helper:get_inactivity_timeout(?MODULE)};
            {sbcast, Name, Msg, Caller} ->
                Reply = case check_if_module_allowed(erlang, Control, List) of
                    true ->
                        ?log(debug, "event=sbcast_received driver=~s socket=\"~s\" peer=\"~s\" process=~s message=\"~p\"",
                             [Driver, gen_rpc_helper:socket_to_string(Socket), gen_rpc_helper:peer_to_string(Peer), Name, Msg]),
                        case erlang:whereis(Name) of
                            undefined -> error;
                            Pid -> Msg = erlang:send(Pid, Msg), success
                        end;
                    false ->
                        ?log(debug, "event=request_not_allowed driver=~s socket=\"~s\" control=~s method=~s",
                             [Driver, gen_rpc_helper:socket_to_string(Socket), Control, sbcast]),
                         error
                end,
                waiting_for_data(info, {sbcast, Caller, Reply}, State);
            ping ->
                ?log(debug, "event=ping_received driver=~s socket=\"~s\" peer=\"~s\" action=ignore",
                     [Driver, gen_rpc_helper:socket_to_string(Socket), gen_rpc_helper:peer_to_string(Peer)]),
                {keep_state_and_data, gen_rpc_helper:get_inactivity_timeout(?MODULE)};
            OtherData ->
                ?log(debug, "event=erroneous_data_received driver=~s socket=\"~s\" peer=\"~s\" data=\"~p\"",
                     [Driver, gen_rpc_helper:socket_to_string(Socket), gen_rpc_helper:peer_to_string(Peer), OtherData]),
                {stop, {badrpc,erroneous_data}, State}
        catch
            error:badarg ->
                {stop, {badtcp,corrupt_data}, State}
        end;
    
    %% Handle the inactivity timeout gracefully
    waiting_for_data(timeout, _Undefined, #state{socket=Socket, driver=Driver} = State) ->
        ?log(info, "message=timeout event=server_inactivity_timeout driver=~s socket=\"~s\" action=stopping",
             [Driver, gen_rpc_helper:socket_to_string(Socket)]),
        {stop, normal, State};
    
    waiting_for_data(info, {DriverClosed, Socket} = Msg, #state{socket=Socket, driver_closed=DriverClosed} = State) ->
        handle_event(info, Msg, waiting_for_data, State);
    
    waiting_for_data(info, {DriverError, Socket, _Reason} = Msg, #state{socket=Socket, driver_error=DriverError} = State) ->
        handle_event(info, Msg, waiting_for_data, State).

    Срочно требуется учитель литературы, чтобы объяснить, что хотел сказать автор.

    CHayT, 22 Октября 2021

    Комментарии (37)
  4. Куча / Говнокод #27764

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    make_process_name("client", {Node,Key}) when is_atom(Node) ->
        %% This function is going to be called enough to warrant a less pretty
        %% process name in order to avoid calling costly functions
        KeyStr = erlang:integer_to_list(erlang:phash2(Key)),
        NodeStr = erlang:atom_to_list(Node),
        erlang:list_to_atom("gen_rpc.client." ++ NodeStr ++ "/" ++ KeyStr);

    Самый страшный грех, который только возможен в Erlang.

    CHayT, 22 Октября 2021

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

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    let textarea = document.querySelector('textarea')
    let list = document.querySelector('ol')
    let newTask = document.createElement('li')
    newTask.innerText = textarea.value
    
    function submitTask() {
        list.appendChild(newTask)
    }

    При попытке добавлять новый HTML элемент функция добавления срабатывает только один раз, к тому же для добавления используется не то значение которое я ввожу в текстовое поле, а только дефолтное. Так как я перепробовал уже массу вариантов и с инпутом, и с событием нажатия Enter, какие-то варианты, которые уже забыл, я подозреваю, что проблема, вероятно, в appendChild, но не уверен, и не понимаю её.

    shuric, 22 Октября 2021

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

    −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
    let glb1 = 0;
    
    class Color {
        static constructor() {
            glb1++;
            print("Static construct");
        }
    
        constructor(public r: number,
            public g: number,
            public b: number) {
        }
    
        static white = 1;
    }
    
    class Color2 {
        static constructor() {
            glb1++;
            print("Static construct 2");
        }
    }
    
    function main() {
        assert(glb1 == 2);
        print("done.");
    }

    добавил статические кострукторы... а то забыл эту хню сделать

    ASD_77, 21 Октября 2021

    Комментарии (25)
  7. 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)
  8. Си / Говнокод #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)
  9. Куча / Говнокод #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)
  10. 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)