1. Лучший говнокод

    В номинации:
    За время:
  2. Куча / Говнокод #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)
  3. PHP / Говнокод #27039

    +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
    /**
     * formHostnameRule: правило, проверяющее имя хоста
     *
     * @package system
     * @subpackage forms
     * @version 0.1.1
     */
    class formHostnameRule extends formAbstractRule
    {
        private $validTlds = array(
        'ac', 'ad', 'ae', 'aero', 'af', 'ag', 'ai', 'al', 'am', 'an', 'ao',
        'aq', 'ar', 'arpa', 'as', 'at', 'au', 'aw', 'ax', 'az', 'ba', 'bb',
        'bd', 'be', 'bf', 'bg', 'bh', 'bi', 'biz', 'bj', 'bm', 'bn', 'bo',
        'br', 'bs', 'bt', 'bv', 'bw', 'by', 'bz', 'ca', 'cat', 'cc', 'cd',
        'cf', 'cg', 'ch', 'ci', 'ck', 'cl', 'cm', 'cn', 'co', 'com', 'coop',
        'cr', 'cu', 'cv', 'cx', 'cy', 'cz', 'de', 'dj', 'dk', 'dm', 'do',
        'dz', 'ec', 'edu', 'ee', 'eg', 'er', 'es', 'et', 'eu', 'fi', 'fj',
        'fk', 'fm', 'fo', 'fr', 'ga', 'gb', 'gd', 'ge', 'gf', 'gg', 'gh',
        'gi', 'gl', 'gm', 'gn', 'gov', 'gp', 'gq', 'gr', 'gs', 'gt', 'gu',
        'gw', 'gy', 'hk', 'hm', 'hn', 'hr', 'ht', 'hu', 'id', 'ie', 'il',
        'im', 'in', 'info', 'int', 'io', 'iq', 'ir', 'is', 'it', 'je', 'jm',
        'jo', 'jobs', 'jp', 'ke', 'kg', 'kh', 'ki', 'km', 'kn', 'kr', 'kw',
        'ky', 'kz', 'la', 'lb', 'lc', 'li', 'lk', 'lr', 'ls', 'lt', 'lu',
        'lv', 'ly', 'ma', 'mc', 'md', 'me', 'mg', 'mh', 'mil', 'mk', 'ml', 'mm',
        'mn', 'mo', 'mobi', 'mp', 'mq', 'mr', 'ms', 'mt', 'mu', 'museum', 'mv',
        'mw', 'mx', 'my', 'mz', 'na', 'name', 'nc', 'ne', 'net', 'nf', 'ng',
        'ni', 'nl', 'no', 'np', 'nr', 'nu', 'nz', 'om', 'org', 'pa', 'pe',
        'pf', 'pg', 'ph', 'pk', 'pl', 'pm', 'pn', 'pr', 'pro', 'ps', 'pt',
        'pw', 'py', 'qa', 're', 'ro', 'ru', 'rw', 'sa', 'sb', 'sc', 'sd',
        'se', 'sg', 'sh', 'si', 'sj', 'sk', 'sl', 'sm', 'sn', 'so', 'sr',
        'st', 'su', 'sv', 'sy', 'sz', 'tc', 'td', 'tf', 'tg', 'th', 'tj',
        'tk', 'tl', 'tm', 'tn', 'to', 'tp', 'tr', 'travel', 'tt', 'tv', 'tw',
        'tz', 'ua', 'ug', 'uk', 'um', 'us', 'uy', 'uz', 'va', 'vc', 've',
        'vg', 'vi', 'vn', 'vu', 'wf', 'ws', 'ye', 'yt', 'yu', 'za', 'zm',
        'zw'
        );

    https://github.com/wiistriker/govnokod_legacy/blob/master/mzz/system/forms/validators/formHostnameRule.php

    Кажется, я эту хуйню уже выкладывал, но да ладно, похуй: это говнище достойно даже повторной публикации здесь. Проебал из-за какой-то древней тупой пхп-макаки деньги за домен!

    gost, 18 Октября 2020

    Комментарии (87)
  4. Python / Говнокод #26877

    +1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    def fake_bin(x):
        k = ''
        while len(x) > 0:
            if int(x) % 10 >= 5:
                k += '1'
                x = x[0:-1]
            else:
                k += '0'
                x = x[0:-1]
        return k[::-1]

    achtonepon, 18 Августа 2020

    Комментарии (87)
  5. Lua / Говнокод #24804

    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
    --Запрос в яндекс за спичером
    function thstart(text)
      
      local th = [[
      love.filesystem.remove("tmp.ogg");
      local str = ...
      local encodeURI = function(str)
    		if (str) then
    			str = string.gsub (str, "\n", "\r\n")
    			str = string.gsub (str, "([^%w ])",
    				function (c) return string.format ("%%%02X", string.byte(c)) end)
            str = string.gsub (str, " ", "+")
    	   end
    	   return str
      end
      str = encodeURI(str)
      local http = require("socket.http");
      body = http.request("https://tts.voicetech.yandex.net/generate?text="..str.."&format=mp3&lang=ru-RU&speaker=kolya&emotion=evil&key=069b6659-984b-4c5f-880e-aaedcfd84102&speed=0.8")
      if body then
        love.filesystem.write("tmp.mp3",body)
        love.thread.getChannel('im'):push("tmp.mp3")
      else
        love.thread.getChannel('im'):push("err")
      end
      --love.thread.getChannel('im'):push("err")
      ]]
      tred = nil
      tred = love.thread.newThread(th);  
      tred:start(text);
    end
    
    function thpop()
      local info = love.thread.getChannel( 'im' ):pop()
      if info then
        if info == "err" then
          return "err"
        else
          return info
        end
      end
      return nil
    end

    3oJIoTou_xyu, 24 Сентября 2018

    Комментарии (87)
  6. C++ / Говнокод #20825

    +322

    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
    void worker(int id)
    {
        while (true) {
            std::unique_lock<std::mutex> lock(connPoolMutex);
            connPoolCond.wait(lock, [] { return !connectionsPool.empty(); });
    
            ClientConnection conn = connectionsPool.front();
            connectionsPool.pop();
            lock.unlock();
    
            TCPSocket sock(conn);
            sock.setReadTimeout(READ_TIMEOUT);
    
            char buffer[MAX_PACKET_LEN] = {};
            int sz = sock.recv(buffer, sizeof(buffer));
    
            // [...]
        }
    }
    
    // [...]
    
    int main()
    {
        // [...]
        TCPSocket server("0.0.0.0:1234");
        server.bind();
        server.listen(1000);
    
        while (true) {
            ClientConnection conn = server.accept();
    
            std::unique_lock<std::mutex> l(connPoolMutex);
            connectionsPool.push(conn);
    
            connPoolCond.notify_one();
        }
    }

    Современный, многопоточный и масштабируемый сервер на C++!

    TCPSocket - очень тонкая обёртка над голым сокетом.

    gost, 17 Августа 2016

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

    +4

    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
    94. 94
    95. 95
    {- This code intentionally was made slightly cryptic -}
    {-# LANGUAGE GADTs, StandaloneDeriving, UnicodeSyntax, KindSignatures, FlexibleInstances, LambdaCase, CPP, BangPatterns #-}
    import System.Exit
    import Data.Functor
    import Control.Monad.IO.Class
    import Control.Monad.Trans.Cont
    import System.Random
    import System.Posix.Signals
    import System.Environment
    import Control.Concurrent.MVar
    
    instance Eq (Int → Int) where
      _ == _ = True -- It's a hack
    
    infixl 7 :.
    
    data T ∷ * where {J, Â, Â', S, K ∷ T; (:.) ∷ T → T → T; Ψ ∷ {σ ∷ String} → T
                     ;F ∷ (Int → Int) → T; N ∷ Int → T; Ø ∷ String → T}
    
    parse ∷ String → [T] → T
    parse ('f':'u':c) t = parse c (J:t)
    parse ('b':'a':'r':c) t = parse c (Â:t)
    parse ('~':c) (a:b:t) = parse c (b:.a:t)
    parse ('~':_) _ = error "Parse error: missing operand(s)"
    parse (_:c) t = parse c t
    parse [] (h:_) = h :. Ψ []
    parse [] [] = error "Parse error: empty program"
    
    s ∷ T → T
    s (J :. x) = (x :. S) :. K
    s (K :. x :. _) = x
    s (S :. x :. y :. z) = (x :. z) :. (y :. z)
    s (F f :. N i) = N $ f i
    s (F f :. F g) = F $ f . g
    s (Â' :. N i :. ψ @ (Ψ {})) = ψ {σ = toEnum i : σ ψ}
    s (Â :. n :. ψ @ (Ψ {})) = Â' :. (n :. F (+1) :. N 0) :. ψ
    -- Other cases
    s (a :. b) = (s a) :. (s b)
    s x = x
    
    eval ∷ (T → t) → (T → t) → T → t
    eval fp done t | t == t'   = done t
                   | otherwise = fp t'
        where t' = s t
    
    ψs a@Ψ{σ=s} = [(a, s)]
    ψs (a:.b) = ψs a ++ ψs b
    ψs _ = []
    
    r' ∷ T → [(T, String)]   -- Very inefficient; should be rewritten
    r' a | null t = [(a, s)] where ((_, s):t) = ψs a
    r' (a :. b) = r' a ++ r' b
    r' _ = []
    
    r ∷ T → IO (Maybe T)
    r t = case r' t of
            [] → return Nothing
            t' → ((t' !!) <$> randomRIO (0, length t' - 1)) >>= \case
               (Ψ{}, s) → putStrLn (reverse s) >> return Nothing
               (t'', s) → putStrLn (reverse s) >> return (Just t'')
    
    setMVar v = (tryTakeMVar v >>) . putMVar v
    
    loop v f n = callCC $ \done → loop1 done (\fp → f fp done) n
      where loop2 interrupt f' n = do
              n' ← liftIO (readMVar v) >>= \case
                0 → f' interrupt n
                _ → callCC $ \fp → f' fp n
              liftIO $ modifyMVar_ v $ (\k → return $ k-1)
              loop2 interrupt f' n'
            loop1 done f' n = do
              n' ← callCC $ \int → loop2 int f' n
              liftIO $ putStrLn "Measure (m) Abort (a) Continue (c) Run steps (number)"
              (liftIO getLine) >>= \case
                "a" → f' done n' >> return ()
                "c" → liftIO $ setMVar v (-1)
                "m" → liftIO (r n') >>= \case
                  Nothing → liftIO exitSuccess
                  Just n'' → loop1 done f' n'' >> return ()
                a → case readsPrec 0 a of
                       (n,_):_ → liftIO $ setMVar v n
                       _ → liftIO $ putStrLn "Not understood."
              loop1 done f' n'
    
    main ∷ IO ()
    main = do
      (file, n) ← getArgs >>= \case
        [f] → return (f, -1)
        ["-s", n, f] → case readsPrec 0 n of
                        (n',_):_ → return (f, n')
                        _ → error "Argument of -s should be a number"
        _ → error "Insufficient arguments. Expected [-s NUMBER_OF_STEPS] FILE"
      cnt ← newMVar n
      installHandler keyboardSignal (Catch $ setMVar cnt 0) Nothing
      void $ (r =<<) (evalContT $ loop cnt eval =<< (parse <$> readFile file))

    больше трясин богу тьюринг-полноты
    1) литературное программирование
    2) зайчатки REPL
    3) чисто функциональное IO без манад и uniq-types
    4) "квантовые" вычисления
    5) только два комбинатора

    CHayT, 18 Марта 2016

    Комментарии (87)
  8. Python / Говнокод #18404

    −146

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    n = 0
    for i in range(n):
        pass
    print i
    
    NameError: name 'i' is not defined

    3_14dar, 25 Июня 2015

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

    +9

    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
    template<...many params...>
    class Foo
    {
      template <typename T>
      class __Bar 
      {
        T t;
      public :
        __Bar(T t) : t(t) {}  
      };
    
    public :
      template <typename T>
      __Bar<T> Bar(T t)
      {
        return __Bar<T>(t); // просто __Bar(t) нельзя, вывод не сработает
      }
    
      template <typename T>
      void Buzz (T t)
      {
      }
    };
    
    ...
    Foo f;
    f.Buzz(Bar(5));

    А как вы выкручиваетесь из неумения определять тип результата по типу параметров конструктора?

    TarasB, 15 Апреля 2014

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

    −139

    1. 1
    2. 2
    >> # HTML/4.01 says that line breaks are represented as "CR LF" pairs (i.e., `%0D%0A')
    >> $content =~ s/(?<!%0D)%0A/%0D%0A/g if defined($content);

    HTTP::Request::Common 6.04, строка 86
    http://cpansearch.perl.org/src/GAAS/HTTP-Message-6.04/lib/HTTP/Request/Common.pm

    Оно просто берёт и изменяет передаваемый контент. Любой. В том числе просто бинарные данные.

    kainwinterheart, 13 Августа 2013

    Комментарии (87)
  11. C++ / Говнокод #12480

    +32

    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
    // *.h
    class MyClass {
    
    public:
    	MyClass ();
    	~MyClass ();
    	// ..etc
    
    };
    
    // *.cpp
    #include "*.h"
    
    MyClass *mycl;
    
    MyClass::MyClass ()
    {
    	mycl=this; // эту строчку не удалять без нее не работает, точнее не всегда работает иногда сбоит
    }
    
    MyClass::~MyClass ()
    {
    }

    Простите меня пожалуйста. Я уныл чуть мене чем полностью, но почему человек которые это написал хороший программист. Это писал не я. Извините пожалуйста за беспокойство :( ..

    neudachnik, 25 Января 2013

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