1. Список говнокодов пользователя CHayT

    Всего: 91

  2. Куча / Говнокод #27464

    +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
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    insert(Alias, Tab, Val) ->
        ok.
    
    delete(_Alias, _Tab, _Key) ->
        ok.
    
    add_aliases(_) ->
        ok.
    
    remove_aliases(_) ->
        ok.
    
    check_definition(_Alias, _Tab, _Nodes, _Properties) ->
        ok.
    
    close_table(_Alias, _Tab) ->
        ok.
    
    create_table(_Alias, _Tab, _Properties) ->
        ok.
    
    delete_table(_Alias, _Tab) ->
        ok.
    
    first(_Alias, _Tab) ->
        '$end_of_table'.
    
    fixtable(_Alias, _Tab, _Bool) ->
        ok.
    
    last(_Alias, _Tab) ->
        '$end_of_table'.
    
    index_is_consistent(_Alias, _IxTag, _Bool) ->
        ok.
    
    init_backend() ->
        ok.
    
    info(_Alias, Tab, memory) ->
        0;
    info(Alias, Tab, size) ->
        0;
    info(_Alias, _Info, _Item) ->
        nobody_here_but_us_chicken.
    
    lookup(_Alias, _Tab, _Key) ->
        [].
    
    is_index_consistent(_Alias, _IxTag) ->
        true.
    
    load_table(_Alias, _Tab, _Reason, _CsList) ->
        ok.
    
    match_delete(_Alias, _Tab, _Pattern) ->
        ok.
    
    next(_Alias, _Tab, _Key) ->
        '$end_of_table'.
    
    prev(_Alias, _Tab, _Key) ->
        '$end_of_table'.
    
    real_suffixes() ->
        [].
    
    repair_continuation(Continuation, _MatchSpec) ->
        Continuation.
    
    select(_Continuation) ->
        '$end_of_table'.
    
    select(_Alias, _Tab, _Pattern) ->
        '$end_of_table'.
    
    select(_Alias, _Tab, _Pattern, _Limit) ->
        '$end_of_table'.
    
    
    semantics(_Alias, storage) -> ram_copies;
    semantics(_Alias, types  ) -> [set, ordered_set, bag];
    semantics(_Alias, index_types) -> [];
    semantics(_Alias, _) -> undefined.
    
    slot(_Alias, _Tab, _Pos) ->
        '$end_of_table'.
    
    sync_close_table(_Alias, _Tab) ->
        ok.
    
    tmp_suffixes() ->
        [].

    If /dev/null is fast in web scale I will use it. Is it web scale? Does /dev/null support sharding?

    CHayT, 09 Июня 2021

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

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    %% Generates a Normal-distributed random variable using Box-Muller method
    %% from: https://github.com/basho/basho_stats/blob/develop/src/basho_stats_rv.erl
    -spec rnd_normal(integer(), integer()) -> non_neg_integer().
    rnd_normal(Mean, Sigma) ->
      Rv1 = random:uniform(),
      Rv2 = random:uniform(),
      Rho = math:sqrt(-2 * math:log(1-Rv2)),
      abs(trunc(Rho * math:cos(2 * math:pi() * Rv1) * Sigma + Mean)).

    Это норма.

    CHayT, 07 Мая 2021

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

    +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
    %% This function is needed as a hack to guide dialyzer into inferring
    %% the correct types.
    -spec id(A) -> A.
    id(A) ->
      A.
    
    %% Где-то в header'е....
    
    -define(deftarget(RECIPE), {RECIPE, fun my_module:id/1}).
    
    %% A horrible, horrible hack to make Dialyzer infer right type of the promise return value
    -define(want(TARGET),
            (fun() ->
                 case TARGET of
                   {_, ___IAmSorryYouHaveToSeeThisWorkaroundForDialyzer} ->
                     ___IAmSorryYouHaveToSeeThisWorkaroundForDialyzer(my_module:want(TARGET))
                 end
             end)()).

    Пути статический типизации в Erlang неисповедимы.

    CHayT, 26 Апреля 2021

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

    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
    -export([parse_transform/2, abstract/2]).
    
    parse_transform(Forms, _Options) ->
      normal(Forms).
    
    normal({call, _Line, {atom, _, '$$'}, [Outer]}) ->
      case Outer of
        {'fun', _, {clauses, Quoted}} ->
          %% Remove outer `fun' and only leave its clauses:
          ok;
        Quoted ->
          %% A plain term has been quoted, leave it as is:
          ok
      end,
      Result = abstract(Quoted),
      %% io:format("Quoted block ~p~n", [Result]),
      Result;
    normal(L) when is_list(L) ->
      lists:map(fun normal/1, L);
    normal(T) when is_tuple(T) ->
      list_to_tuple(lists:map(fun normal/1, tuple_to_list(T)));
    normal(T) ->
      T.
    
    -define(line, 0).
    
    %% @doc Create AST of the AST
    abstract({call, _Line, {atom, _, '$'}, [Splice]}) ->
      normal(Splice);
    abstract(Orig = {var, Line, VarName}) ->
      case lists:suffix("__AST", atom_to_list(VarName)) of
        true ->
          Orig;
        false ->
          {tuple, ?line, [ {atom, ?line, var}
                         , {integer, ?line, Line}
                         , {atom, ?line, VarName}
                         ]}
      end;
    abstract(T) when is_tuple(T) ->
      {tuple, ?line, lists:map(fun abstract/1, tuple_to_list(T))};
    abstract([]) ->
      {nil, ?line};
    abstract([Hd|Tail]) ->
      {cons, ?line, abstract(Hd), abstract(Tail)};
    abstract(A) when is_atom(A) ->
      {atom, ?line, A};
    abstract(I) when is_integer(I) ->
      {integer, ?line, I}.

    Мета-метушня, убогое подобие лисповского квотирования.

    CHayT, 23 Апреля 2021

    Комментарии (7)
  6. Куча / Говнокод #27315

    +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
    ?check_trace(
           begin
               %% Inject some orderings to make sure the replicant
               %% receives transactions in all states.
               %%
               %% 1. Commit some transactions before the replicant start:
               ?force_ordering(#{?snk_kind := trans_gen_counter_update, value := 5}, #{?snk_kind := state_change, to := disconnected}),
               %% 2. Make sure the rest of transactions are produced after the agent starts:
               ?force_ordering(#{?snk_kind := subscribe_realtime_stream}, #{?snk_kind := trans_gen_counter_update, value := 10}),
               %% 3. Make sure transactions are sent during TLOG replay:
               ?force_ordering(#{?snk_kind := state_change, to := bootstrap}, #{?snk_kind := trans_gen_counter_update, value := 15}),
               %% 4. Make sure some transactions are produced while in normal mode
               ?force_ordering(#{?snk_kind := state_change, to := normal}, #{?snk_kind := trans_gen_counter_update, value := 25}),
    ...

    Какой тест )))

    CHayT, 24 Марта 2021

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

    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
    start_link(Shard, Subscriber) ->
        gen_server:start_link(?MODULE, {server, Shard, Subscriber}, []).
    
    start_link_client(Shard, RemoteNode, Parent) ->
        gen_server:start_link(?MODULE, {client, Shard, RemoteNode, Parent}, []).
    
    
    init({server, Shard, Subscriber}) ->
        {ok, #server{ shard      = Shard
                    , subscriber = Subscriber
                    }};
    init({client, Shard, RemoteNode, Parent}) ->
        {ok, #client{ parent     = Parent
                    , shard      = Shard
                    }}.

    CHayT, 12 Марта 2021

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

    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
    -define(snk_int_match_arg(ARG),
            fun(__SnkArg) ->
                case __SnkArg of
                  ARG -> true;
                  _   -> false
                end
            end).
    
    -define(snk_int_match_arg2(M1, M2, GUARD),
            fun(__SnkArg1, __SnkArg2) ->
                case __SnkArg1 of
                  M1 ->
                    case __SnkArg2 of
                      M2 -> (GUARD);
                      _  -> false
                    end;
                  _ -> false
                end
            end).
    
    
    ....
    
    -spec maybe_delay(map()) -> ok.
    maybe_delay(Event) ->
      [{_, Delays}] = ets:lookup(?DELAY_TAB, ?SINGLETON_KEY),
      [snabbkaffe_collector:block_until( fun(WU) -> ContP(Event, WU) end
                                       , infinity
                                       , infinity
                                       )
       || #delay{ continue_predicate = ContP
                , delay_predicate    = DelayP
                } <- Delays, DelayP(Event)],
      ok.

    Наметушил.

    CHayT, 02 Марта 2021

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

    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
    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
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    Fixpoint mint_add0 {N} (i k : Fin.t N) te_i te' t0 vec
                 (Ht : MInt nonCommRel N k vec (te' :: t0))
                 (Hik : k < i)
                 (Hcomm0 : trace_elems_commute te_i te')
                 {struct Ht} :
          exists t' : list TE,
              MInt nonCommRel N k (vec_append i te_i vec) (te' :: t') /\
              Permutation trace_elems_commute (te_i :: te' :: t0) (te' :: t').
        Proof with eauto.
          (* Welcome to the hell proof! *)
          remember (te' :: t0) as t_.
          destruct Ht as [k
                         |k j vec te_k t Hij Ht
                         |k j vec te_k te_j t Hij Hcomm Ht
                         ];
            [discriminate
            |replace te' with te_k in * by congruence; clear Heqt_..
            ].
          2:{ destruct (trace_elems_commute_dec te_i te_j).
              - apply mint_add0 with (te_i := te_i) (i := i) in Ht; [|lia|assumption].
                destruct Ht as [t' [Ht' Hperm']].
                exists (te_j :: t'). split.
                + swap_vec_append.
                  eapply mint_cons2...
                + apply permut_cons with (a := te_k) in Hperm'.
                  eapply permut_trans...
                  now apply permut_head'.
              - exists (te_i :: te_j :: t). split.
                + swap_vec_append.
                  apply mint_cons1 with (j0 := i); [lia|].
                  apply mint_cons2 with (j0 := j); [lia|auto..].
                + now apply permut_head'.
          }
          { inversion_ Ht.
            - exists [te_i]. split.
              + swap_vec_append.
                apply mint_cons1 with (j0 := i); [lia|].
                apply mint_cons1 with (j0 := i); [lia|].
                constructor.
              + now apply permut_head'.
            - rename te into te_j.
              destruct (PeanoNat.Nat.lt_ge_cases j i).
              2:{ exists (te_i :: te_j :: t1). split.
                  - swap_vec_append.
                    apply mint_cons1 with (j1 := i); [lia|].
                    apply mint_cons1 with (j1 := j); [lia|assumption].
                  - now apply permut_head'.
              }
              { destruct (trace_elems_commute_dec te_i te_j) as [Hte_ij|Hte_ij].
                - apply mint_add0 with (i := i) (te_i := te_i) in Ht; [|lia|assumption].
                  destruct Ht as [t' [Ht' Hperm']].
                  exists (te_j :: t'). split.
                  + swap_vec_append.
                    eapply mint_cons1...
                  + apply permut_cons with (a := te_k) in Hperm'.
                    now apply permut_head.
                - exists (te_i :: te_j :: t1). split.
                  + swap_vec_append.
                    apply mint_cons1 with (j1 := i); [lia|].
                    apply mint_cons2 with (j1 := j); [lia|assumption..].
                  + apply permut_head; [assumption|constructor].
              }
            - rename j0 into i0. cbn in H0.
              destruct (PeanoNat.Nat.lt_ge_cases j i).
              2:{ exists (te_i :: te_i0 :: te_j :: t1). split.
                  + swap_vec_append.
                    apply mint_cons1 with (j0 := i); [lia|].
                    apply mint_cons1 with (j0 := j); [lia|assumption].
                  + now apply permut_head'.
              }
              { destruct (trace_elems_commute_dec te_i te_i0).
                - apply mint_add0 with (i := i) (te_i := te_i) in Ht; [|lia|assumption].
                  destruct Ht as [t' [Ht' Hperm']].
                  exists (te_i0 :: t'). split.
                  + swap_vec_append.
                    eapply mint_cons1...
                  + apply permut_cons with (a := te_k) in Hperm'.
                    now apply permut_head.
                - exists (te_i :: te_i0 :: te_j :: t1). split.
                  + swap_vec_append.
                    apply mint_cons1 with (j0 := i); [lia|].
                    apply mint_cons2 with (j0 := j); [lia|assumption..].
                  + apply permut_head.
                    * assumption.
                    * constructor.
              }
          }
        Qed.

    Мой magnum opus. Часть доказательства про выкидывание из рассмотрения коммутирующих системных вызовов.

    CHayT, 17 Ноября 2020

    Комментарии (87)
  10. Куча / Говнокод #27028

    −1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    Lemma mint_head_eq CR1 CR2 (te : TE) l m r (t t' : list TE) :
        MInt CR1 (l, m, r) (te :: t) ->
        MInt CR2 (l, m, r) t' ->
        exists t'', t' = te :: t''.
      Proof.
        intros H1 H2.
        inversion_ H1; inversion_ H2; (* generates 25 goals *)
        match goal with
          |- (exists _, te :: ?T = te :: _) => now exists T
        end.
      Qed.

    Против метушни нет приёма.

    CHayT, 14 Октября 2020

    Комментарии (33)
  11. Куча / Говнокод #26957

    +2

    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
    Definition read_t key cont : Thread :=
          call tx_context <- get_tx_context;
          call cell <- get_cell key tx_context;
          match cell.(cell_write) with
          | Some v =>
              do _ <- log (read key v);
              cont v
          | None =>
              do v <- read_d key;
              let tx_context' := set tx_cells <[key := cell]> tx_context in
              do _ <- pd_set tx_context';
              do _ <- log (read key v);
              cont v
          end.

    Continuations are like violence, if they don't work then you're not using enough of them.

    CHayT, 16 Сентября 2020

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