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

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

    −4

    1. 1
    Зачем простенькие проги, написанные на MASM коннектятся к ip адресу Microsoft 20.99.133.109:443?

    BelCodeMonkey, 01 Января 2023

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

    −2

    1. 1
    2. 2
    cli
    a: jmp a

    DartPower, 02 Июля 2022

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

    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
    int main() {
    
      ifstream input_file;
    
      input_file.open("DATA");
      
      string line;
      while (getline(input_file, line)) {
        size_t i = 0, j = 0;
        string fname, sname;
        float score;
    
        char c = line[0];
        while((c != ' ') && (j < line.size())) {
          c = line[j];
          j++;
        }
        fname = line.substr(i, j - i - 1);
        i = j;
        j += 1;
    
        c = line[i];
        while((c != ' ') && (j < line.size())) {
          c = line[j];
          j++;
        }
        sname = line.substr(i, j - i - 1);
        i = j;
        j += 1;
    
        score = stof(line.substr(i, line.size()));
    
        Data dat;
        dat.fname = fname;
        dat.sname = sname;
        dat.score = score;
    
        vec.push_back(dat);
      }
      
      const auto comp_fname = [](Data a, Data b){return a.fname >= b.fname;};
      const auto comp_sname = [](Data a, Data b){return a.sname >= b.sname;};
      const auto comp_score = [](Data a, Data b){return a.score >= b.score;};
    
      const auto dcomp_fname = [](Data a, Data b){return a.fname < b.fname;};
      const auto dcomp_sname = [](Data a, Data b){return a.sname < b.sname;};
      const auto dcomp_score = [](Data a, Data b){return a.score < b.score;};
    
      print(vec);
      char choice = 0, order = 0;
      cout << "Как сортировать (0 - Fфмилия, 1 - Iмя, 2 - CpegHuu_6aJlJl): ";
      cin >> choice;
      cout << "А в какмо порядке?7? (0 - по убыванию, 1 - по возрастанию)Ж ";
      cin >> order;
      
      if (choice == '0') {
        if (order == '0') {
          sort(vec.begin(), vec.end(), comp_fname);
        } else {
          sort(vec.begin(), vec.end(), dcomp_fname);
        }
      } else if (choice == '1') {
        if (order == '0') {
          sort(vec.begin(), vec.end(), comp_sname);
        } else {
          sort(vec.begin(), vec.end(), dcomp_sname);
        }
      } else if (choice == '2') {
        if (order == '0') {
          sort(vec.begin(), vec.end(), comp_score);
        } else {
          sort(vec.begin(), vec.end(), dcomp_score);
        }
      }
    
    // и т.д. ...

    Как вам? Зачёт? Незачёт? Удовлетворительно?

    JloJle4Ka, 12 Марта 2022

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

    −1

    1. 001
    2. 002
    3. 003
    4. 004
    5. 005
    6. 006
    7. 007
    8. 008
    9. 009
    10. 010
    11. 011
    12. 012
    13. 013
    14. 014
    15. 015
    16. 016
    17. 017
    18. 018
    19. 019
    20. 020
    21. 021
    22. 022
    23. 023
    24. 024
    25. 025
    26. 026
    27. 027
    28. 028
    29. 029
    30. 030
    31. 031
    32. 032
    33. 033
    34. 034
    35. 035
    36. 036
    37. 037
    38. 038
    39. 039
    40. 040
    41. 041
    42. 042
    43. 043
    44. 044
    45. 045
    46. 046
    47. 047
    48. 048
    49. 049
    50. 050
    51. 051
    52. 052
    53. 053
    54. 054
    55. 055
    56. 056
    57. 057
    58. 058
    59. 059
    60. 060
    61. 061
    62. 062
    63. 063
    64. 064
    65. 065
    66. 066
    67. 067
    68. 068
    69. 069
    70. 070
    71. 071
    72. 072
    73. 073
    74. 074
    75. 075
    76. 076
    77. 077
    78. 078
    79. 079
    80. 080
    81. 081
    82. 082
    83. 083
    84. 084
    85. 085
    86. 086
    87. 087
    88. 088
    89. 089
    90. 090
    91. 091
    92. 092
    93. 093
    94. 094
    95. 095
    96. 096
    97. 097
    98. 098
    99. 099
    100. 100
    class Node<T> {
        v: T;
        k: string;
        next: Node<T>;
    }
    
    class Map<T> {
        head: Node<T>;
    
        getElt(k: string): T {
            return mapGet(this, k)
        }
    
        setElt(k: string, v: T) {
            mapSet(this, k, v)
        }
    }
    
    function mapSet<T>(m: Map<T>, k: string, v: T) {
        for (let p = m.head; p != null; p = p.next) {
            if (p.k == k) {
                p.v = v
                return
            }
        }
        let n = new Node<T>()
        n.next = m.head
        n.k = k
        n.v = v
        m.head = n
    }
    
    function mapGet<T>(m: Map<T>, k: string): T {
        for (let p = m.head; p != null; p = p.next) {
            if (p.k == k) {
                return p.v
            }
        }
        return null
    }
    
    
    function search_array<T>(a: T[], item: T): number {
        for (let i = 0; i < a.length; i++) {
            if (a[i] == item) {
                return i
            }
        }
        return -1 // NOT FOUND
    }
    
    class MyMap<K, V> {
    
        keys: K[]
        values: V[]
    
        constructor() {
            this.keys = []
            this.values = []
        }
    
        push(key: K, value: V) {
            this.keys.push(key)
            this.values.push(value)
        }
    
        value_for(key: K): V {
            let i = search_array(this.keys, key)
            if (i == -1) {
                return null
            }
            return this.values[i]
        }
    
        key_for(value: V): K {
            let i = search_array(this.values, value)
            if (i == -1) {
                return null
            }
            return this.keys[i]
        }
        set(key: K, value: V): void {
            let i = search_array(this.keys, key)
            if (i == -1) {
                this.keys.push(key)
                this.values.push(value)
            } else {
                this.values[i] = value
            }
        }
    
        has_key(key: K): boolean {
            return search_array(this.keys, key) != -1
        }
    
        has_value(value: V): boolean {
            return search_array(this.values, value) != -1
        }
    
    }

    Срочно нужна помощь... не могу решить что делать с функцией mapGet .. когда T - number я не могу использовать "null" .. должен я хакнуть компилятор или изменить тестовый пример?

    ASD_77, 13 Января 2022

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

    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
    class Node<T> {
        v: T;
        k: string;
        next: Node<T>;
    }
    
    function main()
    {
        let n = new Node<number>()
        n.next = n
        n.k = "Hello";
        n.v = 10.0;
        print("done.");
    }

    Вы не поверите как сложно сделать простые вещи в LLVM. встречаем рекурсивные типы :)

    ASD_77, 06 Января 2022

    Комментарии (31)
  7. C++ / Говнокод #27785

    +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
    template<typename T>
    static ALWAYS_INLINE void FormatLogMessageAndPrintW(
                                                 const char* channelName, 
                                                 const char* functionName, 
                                                 LOGLEVEL level,
                                                 const char* message, 
                                                 bool timestamp, 
                                                 bool ansi_color_code,
                                                 bool newline, 
                                                 const T& callback)
    {
      char buf[512];
      char* message_buf = buf;
      int message_len;
      if ((message_len = FormatLogMessageForDisplay(message_buf,
                           sizeof(buf), channelName, functionName,
                           level, 
                           message, timestamp,
                           ansi_color_code, newline)) > (sizeof(buf) - 1))
      {
        message_buf = static_cast<char*>(std::malloc(message_len + 1));
        message_len = FormatLogMessageForDisplay(message_buf, 
                     message_len + 1, channelName, functionName, 
                     level, message, timestamp, ansi_color_code, newline);
      }
      if (message_len <= 0)
        return;
    
      // Convert to UTF-16 first so unicode characters display correctly.
      // NT is going to do it anyway...
      wchar_t wbuf[512];
      wchar_t* wmessage_buf = wbuf;
      int wmessage_buflen = countof(wbuf) - 1;
      if (message_len >= countof(wbuf))
      {
        wmessage_buflen = message_len;
        wmessage_buf = static_cast<wchar_t*>
                   (std::malloc((wmessage_buflen + 1) * sizeof(wchar_t)));
      }
    
      wmessage_buflen = MultiByteToWideChar(CP_UTF8, 0, message_buf,
                        message_len, wmessage_buf, wmessage_buflen);
    
      if (wmessage_buflen <= 0)
        return;
    
      wmessage_buf[wmessage_buflen] = '\0';
      callback(wmessage_buf, wmessage_buflen);
    
      if (wmessage_buf != wbuf)
      {
        std::free(wbuf);                        // <=
      }
    
      if (message_buf != buf)
      {
        std::free(message_buf);
      }
    }

    Отсюда:
    https://pvs-studio.com/ru/blog/posts/cpp/0880/

    HO9I6PbCKuu_neTyx, 03 Ноября 2021

    Комментарии (31)
  8. Java / Говнокод #27313

    +5

    1. 1
    2. 2
    3. 3
    private static String getMargin(final int size) {
            return "                                                                                                                             ".substring(0, 6 * size);
        }

    Как создать пустую строку с заданной длиной...

    nekkiy, 24 Марта 2021

    Комментарии (31)
  9. Си / Говнокод #27255

    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
    #include <stdio.h>
    #include <stdlib.h>
    #include <inttypes.h>
    
    int main(void)
    {
      uint32_t uint32max = UINT32_MAX;
      int32_t int32_minus_one = -1;
      printf("uint32_max = %" PRIu32 "\n", uint32max);
      printf("int32_minus_one = %" PRIi32 "\n", int32_minus_one);
      if (uint32max > int32_minus_one)
      {
        puts("uint32max > int32_minus_one");
      }
      else if (uint32max < int32_minus_one)
      {
        puts("uint32max < int32_minus_one");
      }
      else
      {
        puts("uint32max == int32_minus_one");
      }
      return EXIT_SUCCESS;
    }

    Почему в Си нет особого правила при сравнении signed и unsigned типов, ну типа если значение в signed типе отрицательно, то он полюбасу будет меньше любого unsigned значения? А то говно какое-то.

    (нет, я понимаю почему так происходит, но все равно говно)

    j123123, 15 Февраля 2021

    Комментарии (31)
  10. C# / Говнокод #27146

    +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
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    namespace test
    {
    
        //public record P(double D);
        class Program1
        {
            static void Main(string[] args)
            {
    
                //The differences between Double.Equals and Double==
                Console.WriteLine(double.NaN.Equals(double.NaN)); //True
                Console.WriteLine(double.NaN == double.NaN); // False  
    
                //The same is true for tuples!
                Console.WriteLine((double.NaN, 1).Equals((double.NaN, 1))); // True
                Console.WriteLine((double.NaN, 1) == (double.NaN, 1)); // False
    
                //But records in C# 9 behave differently!
                Console.WriteLine(new P(double.NaN).Equals(new P(double.NaN))); // True
                Console.WriteLine(new P(double.NaN) == new P(double.NaN)); // True
            }
        }
    }

    https://twitter.com/STeplyakov/status/1333831742134779904

    nihau, 01 Декабря 2020

    Комментарии (31)
  11. Python / Говнокод #27063

    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
    def neuro_anec():
        group_id = '85443458'
        random.seed()
        _vk_session = vk_api.VkApi(token=config.service)
        _vk = _vk_session.get_api()
        max_num = _vk.wall.get(owner_id=-int(group_id), count=0)['count']
        try:
            anec_base = ''
            while len(anec_base.split('\n')) < 1 or anec_base == '':
                num = random.randint(1, max_num)
                anec_base = '\n'.join(
                    _vk.wall.get(owner_id=-int(group_id), count=1, offset=num)['items'][0]['text'].split('\n')[:-1])
            num = random.randint(1, max_num)
            anec_booter = _vk.wall.get(owner_id=-int(group_id), count=1, offset=num)['items'][0]['text'].split('\n')[-1]
            return anec_base + '\n' + anec_booter
        except:
            return 'А хуй тебе'

    Представляю вашему вниманию: ней(гей)росеть, генерирующая анеки категории Б

    lpjakewolfskin, 27 Октября 2020

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