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

    Всего: 89

  2. Haskell / Говнокод #29250

    +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
    {-# LANGUAGE OverloadedStrings #-}
    import qualified Data.Text.Lazy.IO as LIO
    import GHC.IO.StdHandles
    import Text.Regex.TDFA
    import qualified Text.Regex.TDFA.Text.Lazy as RL
    import Data.Array
    import qualified Data.Text.Lazy as TL
    import System.Environment
    import System.Exit
    import System.IO
    import qualified Language.C.Syntax.Constants as CC
    import Data.Char
    
    printMatch t matches i =
        let (offset, len) = matches ! i in
        let offset' = fromIntegral offset in
        let len' = fromIntegral len in
        LIO.putStr $ TL.take len' $ TL.drop offset' t
    
    printHead t matches =
        let (offset, len) = matches ! 0 in
        let offset' = fromIntegral offset in
        let len' = fromIntegral len in
        LIO.putStr $ TL.take offset' t
    
    printTrail t matches =
        let (offset, len) = matches ! 0 in
        let offset' = fromIntegral offset in
        let len' = fromIntegral len in
        LIO.putStr $ TL.drop (offset' + len') t
    
    need_capture_trail acc ".*" = (False, reverse acc)
    need_capture_trail acc [] = (True, reverse acc)
    need_capture_trail acc (c : rest) = need_capture_trail (c : acc) rest
    
    getRE :: [String] -> Either String (RL.Regex, Bool, String)
    getRE args =
        case args of
          (re_str : repl_str : _) ->
              let (trail_needed, re_str') = need_capture_trail [] re_str in
              let re_text = TL.pack $ CC.unescapeString re_str' in
              case RL.compile defaultCompOpt defaultExecOpt re_text of
                Right re ->
                    Right (re, trail_needed, CC.unescapeString repl_str)
                Left err ->
                    Left err
          _ ->
              Left "Regexp expected"
    
    -- replacement :: TL.Text -> Int -> _ -> String -> IO ()
    replacement _ _ _ [] = return ()
    replacement t n_matches matches (c : rest)
        | ord c <= n_matches = do
               printMatch t matches (ord c)
               replacement t n_matches matches rest
        | True = do
            putChar c
            replacement t n_matches matches rest
    
    exitError :: String -> IO ()
    exitError msg = do
      hPutStrLn stderr msg
      exitWith (ExitFailure 1)
    
    main :: IO ()
    main = do
        args <- getArgs
        case getRE args of
          Right (re, trail_needed, repl) -> do
              t <- LIO.hGetContents stdin
              case RL.execute re t of
                Right (Just matches) ->
                    do
                      let n_matches = snd $ bounds matches
                      -- print matches
                      printHead t matches
                      replacement t n_matches matches repl
                      if trail_needed then
                          printTrail t matches
                      else
                          return ()
                Right Nothing -> do
                    exitError "Pattern not found"
                Left err -> do
                    exitError err
          Left err -> do
             exitError err

    Текст UNIX-way утилиты fed
    Капча: p2ux

    CHayT, 25 Апреля 2026

    Комментарии (2)
  3. Assembler / Говнокод #29179

    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
    mov r8, qword ptr [rsi]
    mov rdx, qword ptr [rdi]
    bswap rdx
    mov rcx, rdx
    ror rcx, 1
    movabs rax, 0x808080808080808
    and rcx, rax
    or r8, rcx
    mov rcx, rdx
    ror rcx, 3
    movabs rax, 0x404040404040404
    and rcx, rax
    or r8, rcx
    mov rcx, rdx
    ror rcx, 5
    movabs rax, 0x202020202020202
    and rcx, rax
    or r8, rcx
    mov rcx, rdx
    ror rcx, 7
    movabs rax, 0x101010101010101
    and rcx, rax
    or r8, rcx
    mov rcx, rdx
    ror rcx, 0x39
    movabs rax, 0x8080808080808080
    and rcx, rax
    or r8, rcx
    mov rcx, rdx
    ror rcx, 0x3B
    movabs rax, 0x4040404040404040
    and rcx, rax
    or r8, rcx
    mov rcx, rdx
    ror rcx, 0x3D
    movabs rax, 0x2020202020202020
    and rcx, rax
    or r8, rcx
    mov rcx, rdx
    ror rcx, 0x3F
    movabs rax, 0x1010101010101010
    and rcx, rax
    or r8, rcx
    mov qword ptr [rsi], r8

    Разворот битов в uint64

    CHayT, 15 Сентября 2025

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

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    SparseMatrix<double> mat(rows,cols);
    for (int k=0; k<mat.outerSize(); ++k)
      for (SparseMatrix<double>::InnerIterator it(mat,k); it; ++it)
      {
        it.value();
        it.row();   // row index
        it.col();   // col index (here it is equal to k)
        it.index(); // inner index, here it is equal to it.row()
      }

    Random access to the elements of a sparse object can be done through the coeffRef(i,j) function. However, this function involves a quite expensive binary search. In most cases, one only wants to iterate over the non-zeros elements. This is achieved by a standard loop over the outer dimension, and then by iterating over the non-zeros of the current inner vector via an InnerIterator. Thus, the non-zero entries have to be visited in the same order than the storage order.

    CHayT, 03 Сентября 2025

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

    0

    1. 1
    https://github.com/PlummersSoftwareLLC/Primes/blob/drag-race/PrimeChapel/solution_1/primes.chpl#L92

    Царские анроллы.

    CHayT, 06 Сентября 2022

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

    −1

    1. 1
    https://github.com/tejdnk-2019-ShortNotes/

    CHayT, 14 Марта 2022

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

    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
    %% Note: set and unset are not thread-safe.
    -spec set(key(), value()) -> ok.
    set(Key, Value) ->
        case ets:lookup(?status_tab, Key) of
            [{_, {set, _OldValue}}] ->
                ets:insert(?status_tab, {Key, {set, Value}});
            [{_, {unset, Pid}}] ->
                MRef = monitor(process, Pid),
                Pid ! {set, Value},
                receive
                    {'DOWN', MRef, _, _, _} -> ok
                end;
            [] ->
                case ets:insert_new(?status_tab, {Key, {set, Value}}) of
                    true  ->
                        ok;
                    false ->
                        set(Key, Value)
                end
        end,
        ok.
    
    -spec unset(key()) -> ok.
    unset(Key) ->
        case ets:lookup(?status_tab, Key) of
            [{_, {set, _OldValue}}] -> ets:delete(?status_tab, Key);
            _                       -> ok
        end,
        ok.
    
    -spec read(key()) -> value().
    read(Key) ->
        case read_or_wait(Key) of
            {set, Value} ->
                Value;
            {wait, MRef} ->
                receive
                    {'DOWN', MRef, _, _, {cvar_set, Value}} ->
                        Value;
                    {'DOWN', MRef, _, _, noproc} ->
                        read(Key)
                end
        end.
    
    -spec read_or_wait(key()) -> {set, value()} | {wait, reference()}.
    read_or_wait(Key) ->
        case ets:lookup(?status_tab, Key) of
            [] ->
                {Pid, MRef} = spawn_monitor(?MODULE, waker_entrypoint, [Key, self()]),
                receive
                    {Pid, proceed} ->
                        {wait, MRef};
                    {'DOWN', MRef, _, _, Reason} ->
                        cvar_retry = Reason,
                        read_or_wait(Key)
                end;
            [{_, {set, Val}}] ->
                {set, Val};
            [{_, {unset, Pid}}] ->
                {wait, monitor(process, Pid)}
        end.
    
    -spec waker_entrypoint(key(), pid()) -> no_return().
    waker_entrypoint(Key, Parent) ->
        case ets_insert_new({Key, {unset, self()}}) of
            false ->
                exit(cvar_retry);
            true ->
                Parent ! {self(), proceed},
                receive
                    {set, Value} ->
                        ets_insert({Key, {set, Value}}),
                        exit({cvar_set, Value})
                end
        end.

    CHayT, 08 Февраля 2022

    Комментарии (23)
  8. C++ / Говнокод #27969

    +2

    1. 1
    https://github.com/golded-plus/golded-plus/blob/master/golded3/gccfgg0.cpp#L162

    CHayT, 25 Января 2022

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

    +3

    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
    #!/usr/bin/env escript
    -mode(compile).
    
    main(["-p"|Filenames]) ->
      put(pretend, true),
      main(Filenames);
    main(Filenames) ->
      case get(pretend) of
        true -> ok;
        _    -> put(pretend, false)
      end,
      Albums = lists:filtermap(fun parse_name/1, Filenames),
      lists:foreach(fun process_album/1, Albums).
    
    process_album({Zip, Artist, Album}) ->
      Dir = filename:absname(filename:join(Artist, Album)),
      case filelib:wildcard(Dir ++ "/cover.*") of
        [] ->
          io:format("Will create ~p~n", [Dir]),
          get(pretend) orelse do_process_album(Dir, Zip, Album);
        _ ->
          io:format("Ignoring ~p : ~p~n", [Artist, Album])
      end.
    
    do_process_album(Dir, Zip, Album) ->
      ok = filelib:ensure_dir(Dir ++ "/fake"),
      0 = exec(Dir, "/usr/bin/unzip", [Zip, "-d", Dir]),
      postprocess(Album, Dir).
    
    postprocess(Album, Dir) ->
      Files = filelib:wildcard(Dir ++ "/*-*[0-9]*.flac"),
      lists:foreach(fun(I) -> rename_flac(Album, I) end, Files).
    
    rename_flac(Album, OldFile) ->
      Dir = filename:dirname(OldFile),
      OldName = filename:basename(OldFile),
      Options = [{capture, all_but_first, list}],
      {ok, RE} = re:compile(Album ++ " - ([0-9]+.*\\.flac)", [unicode]),
      case re:run(OldName, RE, Options) of
        {match, [NewName]} ->
          io:format("New name: ~p~n", [NewName]),
          NewFile = filename:join(Dir, NewName),
          ok = file:rename(OldFile, NewFile);
        nomatch ->
          ok
      end.
    
    parse_name(Filename) ->
      Opts = [{capture, ['band', album], list}],
      case re:run(filename:basename(Filename), "(?<band>[^-]+) - (?<album>.*)\\.zip", Opts) of
        {match, [Band, Album]} ->
          {true, {filename:absname(Filename), Band, Album}};
        nomatch ->
          false
      end.
    
    -spec exec(file:filename(), file:filename(), [string() | binary()]) -> integer().
    exec(Dir, CMD, Args) ->
      Port = open_port( {spawn_executable, CMD}
                      , [ exit_status
                        , binary
                        , stderr_to_stdout
                        , {args, Args}
                        , {cd, Dir}
                        , {line, 300}
                        ]
                      ),
      collect_port_output(Port, filename:basename(CMD)).
    
    -spec collect_port_output(port(), string()) -> integer().
    collect_port_output(Port, CMD) ->
      receive
        {Port, {data, {_, Data}}} ->
          io:format("~s: ~s~n", [CMD, Data]),
          collect_port_output(Port, CMD);
        {Port, {exit_status, ExitStatus}} ->
          ExitStatus
      end.

    CHayT, 08 Января 2022

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

    +2

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    Ltac2 make_match fields :=
      destruct x;
      iter (fun a => focus 1 1 (fun () =>
                               let a := a ()
                               in refine (fun () => '((w_rep $a) _)))
             ) fields.

    Итерация по конструкторам индуктивного типа данных.

    CHayT, 03 Декабря 2021

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

    +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
    (** Set of all possible interleaving of two traces is a trace
      ensemble. As we later prove in [interleaving_to_permutation], this
      definition is dual to [Permutation]. *)
      Inductive Interleaving : list TE -> list TE -> TraceEnsemble :=
      | ilv_cons_l : forall te t1 t2 t,
          Interleaving t1 t2 t ->
          Interleaving (te :: t1) t2 (te :: t)
      | ilv_cons_r : forall te t1 t2 t,
          Interleaving t1 t2 t ->
          Interleaving t1 (te :: t2) (te :: t)
      | ilv_nil : Interleaving [] [] [].
    
    Попытка оптимизации:
    
      (* Left-biased version of [Interleaving] that doesn't make
      distinction between schedulings of commuting elements: *)
      Inductive UniqueInterleaving : list TE -> list TE -> TraceEnsemble :=
      | uilv_cons_l : forall l t1 t2 t,
          UniqueInterleaving t1 t2 t ->
          UniqueInterleaving (l :: t1) t2 (l :: t)
      | uilv_cons_r1 : forall l r t1 t2 t,
          ~trace_elems_commute l r ->
          UniqueInterleaving (l :: t1) t2 (l :: t) ->
          UniqueInterleaving (l :: t1) (r :: t2) (r :: l :: t)
      | uilv_cons_r2 : forall r1 r2 t1 t2 t,
          UniqueInterleaving t1 (r1 :: t2) (r1 :: t) ->
          UniqueInterleaving t1 (r2 :: r1 :: t2) (r2 :: r1 :: t)
      | uilv_nil : forall t, UniqueInterleaving [] t t.

    Сложный говнокод. Почему вторая "оптимизированная" версия работает хуже первой?

    CHayT, 01 Ноября 2021

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