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

    В номинации:
    За время:
  2. C++ / Говнокод #11458

    +23

    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
    const Tifon& Tifon::operator=(const Tifon& Buffer)
    {
            assert(&Buffer!=this);
            if(&Buffer==this)
                    return *this;
            Tifon OldForExceptionSafe(*this);
            try{
                    this->~Tifon();
                    ::new((void*)this)Tifon(Buffer);
            }catch(...){//try restore
                    ::new((void*)this)Tifon(OldForExceptionSafe);
            }
            return *this;
    };
     //...
    namespace std
    {
            const Tifon&swap (Tifon& a, Tifon& b) {
            assert(&a!=&b);
            if(&a==&b)
                    return a;
            Tifon c(a);
            a=b;
            b=c;
            }
    };

    USB, 22 Июля 2012

    Комментарии (88)
  3. Pascal / Говнокод #8447

    +111

    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
    var
    s:string;
    begin
    repeat
    readln(s);
    until
    (length(s)=4)
    and(
                    (s[1]='1')
                  or(s[1]='2')
                  or(s[1]='3')
                  or(s[1]='4')
                  or(s[1]='5')
                  or(s[1]='6')
                  or(s[1]='7')
                  or(s[1]='8')
                  or(s[1]='9')
                              )
    and(
                    (s[2]='1')
                  or(s[2]='2')
                  or(s[2]='3')
                  or(s[2]='4')
                  or(s[2]='5')
                  or(s[2]='6')
                  or(s[2]='7')
                  or(s[2]='8')
                  or(s[2]='9')
                  or(s[2]='0')
                              )
    and(
                    (s[3]='1')
                  or(s[3]='2')
                  or(s[3]='3')
                  or(s[3]='4')
                  or(s[3]='5')
                  or(s[3]='6')
                  or(s[3]='7')
                  or(s[3]='8')
                  or(s[3]='9')
                  or(s[3]='0')
                              )
    and(
                    (s[4]='1')
                  or(s[4]='2')
                  or(s[4]='3')
                  or(s[4]='4')
                  or(s[4]='5')
                  or(s[4]='6')
                  or(s[4]='7')
                  or(s[4]='8')
                  or(s[4]='9')
                  or(s[4]='0')
                              )
    end.

    Нашёл у себя из первого курса.

    ReallyBugMeNot2, 07 Ноября 2011

    Комментарии (88)
  4. Pascal / Говнокод #6689

    +107

    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
    function HexToInt(s: string): integer;
    label
      gte;
    var
      tempt: string;
      i: integer;
    begin
      tempt := '';
      if s = '' then
      begin
        HexToInt := 0;
        goto gte;
      end;
      for i := 1 to Length(s) do
      begin
        tempt := tempt + IntToHex(Ord(s[i]), 2);
      end;
      HexToInt := StrToInt('$' + tempt);
      gte:
    end;

    Ряд гениальных решений из-за незнания особенностей языка.

    Честно взято с: http://www.delphisources.ru/pages/faq/base/hex_to_int.html
    Честно написано автором: Перегинец Иваном ( [email protected] )

    miLord-Corwin, 17 Мая 2011

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

    −3

    1. 1
    Блять, какое же lua говно блять...

    kcalbCube, 06 Июля 2022

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