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

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

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    // https://habr.com/ru/post/490222/
    
    Почему мы должны сломать ABI
    
    Прежде всего, есть несколько полезных изменений в реализации стандартной библиотеки, которые можно внедрить, если нарушить текущий ABI:
    
    ...
    
    * Ускорить работу std::regex (На данный момент быстрее запустить PHP и выполнить на нем поиск по регулярному выражению, чем использовать стандартный std::regex)

    Какой багор! Именно поэтому я за PHP

    j123123, 28 Февраля 2020

    Комментарии (362)
  3. C++ / Говнокод #26453

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    Задачка с собеседования.
    
    Удалить из неупорядоченного массива чисел представленного как std::vector<int> элемент за O(1).
    
    А я тупил, и дошел до ответа только с подсказками.

    OlegUP, 27 Февраля 2020

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

    +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
    #include <array>
    #include <iostream>
    using namespace std;
    
    
    int main() {
        ::array arr {1, 2, 3};
        int a, b, c;
        ::tie(a, b, c) = arr;
        printf("%d %d %d",a,b,c);
        return 0;
    }

    https://godbolt.org/z/RRmruC

    3.14159265, 25 Февраля 2020

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

    +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
    function isVowel(char){
        return "аоэиуыеёюя".indexOf(char.toLocaleLowerCase())>=0 ? 1 : 0;
    }
    
    function vorefy(text)
    {
        // Г => C 0.85
        // Г => Г 0.15
        // С => С 0.30
        // С => Г 0.70   
        var markov = [[0.3,0.7],[0.85,0.15]]; 
        var mCorr = [ 1/Math.sqrt(0.3*0.7), 1/Math.sqrt(0.85*0.15) ];
        //степень влияния марковских вореантностей
        var pow = x => Math.pow(x,2);
        
        var prev=null;
        return text.replace(/./g,(char,offset,text) => 
        {
            if (E2R[char]){
                var replace = Object.entries(E2R[char]);
                if (1==replace.length) {
                    prev = replace[0][0];
                    return prev;
                }
                var r = Math.random()*200, probability=0;
                for (const [k, v] of replace) {
                    vowel = isVowel(k);
                    probability += v * ((null==prev) ? 1 
                        : pow( 
                            mCorr[vowel]*2*markov[isVowel(prev)][vowel]
                        ));
                    if (r<=probability) {
                        prev = k;
                        return prev;
                    }
                }
            }
            prev=null;
            return char;
        });        
    }

    Марковым отмечена еще одна устойчивая закономерность открытых текстов, связанная с чередованием гласных и согласных букв. Им были подсчитаны частоты встречаемости биграмм вида гласная-гласная (г, г), гласная-согласная (г, с), согласная-гласная (с, г), согласная-согласная (с, с)

    [color=blur]https://ideone.com/VpkwXT[/color]

    3.14159265, 22 Февраля 2020

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

    +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
    #include <iostream>
    #include <map>
    
    std::map<std::string, int> get_map()
    {
        return {
            { "hello", 1 },
            { "world", 2 },
            { "it's",  3 },
            { "me",    4 },
        };
    }
    
    int main()
    {
        for (auto&& [ k, v ] : get_map())
            std::cout << "k=" << k << " v=" << v << '\n';
    
        return 0;
    }

    govnokod3r, 15 Февраля 2020

    Комментарии (244)
  7. Си / Говнокод #26430

    +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
    // https://www.linux.org.ru/forum/development/15520475
    // *Какой #define макрит for в while?
    
    #include <stdio.h>
    #include <stdlib.h>
    
    #define FOR(a, b, c, ...) {a;while(b){__VA_ARGS__ c;}}
    
    int main(void)
    {
      for(int i = 0; i < 10; i++)
      {
        printf("test %d\n", i);
      }
      
      printf("\n");
      
      FOR(int i = 0, i < 10, i++,
      {
        printf("test %d\n", i);
      }   
      )
        
      return EXIT_SUCCESS;
    }

    j123123, 10 Февраля 2020

    Комментарии (3)
  8. JavaScript / Говнокод #26429

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    //Use this to convert OffSet to postive:
    
    var offset = new Date().getTimezoneOffset();
    console.log(offset);
    this.timeOffSet = offset + (-2*offset);
    console.log(this.timeOffSet);

    Это такой особый JS way, или я чего-то не понимаю?

    eukaryote, 10 Февраля 2020

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

    +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
    template <typename function_type, typename vector_type>
    function_type read_memory(HANDLE hProcess, function_type base_address, std::vector< vector_type >&& offsets) {
        function_type tmp = base_address;
        for (function_type i : **reinterpret_cast< vector_type** >( &offsets )) {
            ReadProcessMemory(hProcess, reinterpret_cast< PBYTE* >( tmp + i ), &tmp, sizeof(function_type), nullptr);
        }
        return tmp;
    }
    
    int main() {
        std::vector< DWORD > offset = {
            0x10,
            0x14,
            0x158
        };
        auto buffer = read_memory< DWORD, DWORD >(hProcess, base_address, std::move(offset));
    }

    Полуговнокодер читает память чужого процесса...

    bcaoo, 10 Февраля 2020

    Комментарии (39)
  10. SQL / Говнокод #26417

    +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
    SET @from = 11836;
    SET @to = 11840;
    
    INSERT INTO `sprinter_catalog_tree` (
        `sprinter_catalog_tree`.`level`,
        `sprinter_catalog_tree`.`position`,
        `sprinter_catalog_tree`.`parent_id`,
        `sprinter_catalog_tree`.`catalog`,
        `sprinter_catalog_tree`.`info_id`,
    --  ...
    )
    SELECT
        `sprinter_catalog_tree`.`level`,
        `sprinter_catalog_tree`.`position`,
        @to,
        `sprinter_catalog_tree`.`catalog`,
        `sprinter_catalog_tree`.`info_id`,
        `sprinter_catalog_tree`.`format_id`,
        `sprinter_catalog_tree`.`linked_id`,
        `sprinter_catalog_tree`.`linked_shablon_id`,
    --  ...
    FROM `sprinter_catalog_tree` where parent_id = @from order by id;
    
    INSERT INTO `sprinter_catalog_tree` (
        `sprinter_catalog_tree`.`level`,
        `sprinter_catalog_tree`.`position`,
        `sprinter_catalog_tree`.`parent_id`,
        `sprinter_catalog_tree`.`catalog`,
        `sprinter_catalog_tree`.`info_id`,
    --  ...
    )
    SELECT
        a.`level`,
        a.`position`,
        (SELECT id from sprinter_catalog_tree as b where b.parent_id = @to and b.name like (SELECT name from sprinter_catalog_tree where id = a.parent_id)),
        a.`catalog`,
        a.`info_id`,
        a.`format_id`,
        a.`linked_id`,
        a.`linked_shablon_id`,
    --  ...
    FROM `sprinter_catalog_tree` as a where parent_id in (SELECT id FROM sprinter_catalog_tree where parent_id = @from) order by id;
    
    INSERT INTO `sprinter_catalog_info`
    (`name`,
    `eng_name`,
    `text`,
    --  ..
    )
    SELECT
        `sprinter_catalog_info`.`name`,
        `sprinter_catalog_info`.`eng_name`,
        `sprinter_catalog_info`.`text`,
        `sprinter_catalog_info`.`short_text`,
    --  ...
    FROM `sprinter_catalog_info` where id in (SELECT info_id from `sprinter_catalog_tree` where parent_id = @from or parent_id in (SELECT id from `sprinter_catalog_tree` where parent_id = @from));
    
    CREATE temporary table if not exists ids
    SELECT id from `sprinter_catalog_tree` where parent_id = @to or parent_id in (SELECT id from `sprinter_catalog_tree` where parent_id = @to);
    
    UPDATE sprinter_catalog_tree as a SET info_id = (SELECT id from sprinter_catalog_info as b where a.name like b.name order by id desc limit 1) where a.id in (SELECT id from ids);
    
    DROP table ids;

    Высрал вот такое говно в качестве write-n-throw скрипта.

    Дано: есть элементы дерева, хранящиеся в таблице sprinter_catalog_tree, связаны друг с другом через parent_id. Каждому из них соответствует указанный в info_id элемент таблицы sprinter_catalog_info.

    Задача: скопировать все вложенные в раздел @from каталога элементы и его подразделы (вложенность не более 1 уровня) в раздел @to, так чтобы у них были новые id, и также скопировать соответствующие им sprinter_catalog_info. Скопированные sprinter_catalog_tree должны указывать на корректные sprinter_catalog_info, id которых заранее не известны.

    Вот такое говно получилось, расскажите как надо было?

    vistefan, 05 Февраля 2020

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

    +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
    define method display (i :: <integer>)
      do-display-integer(i);
    end;
    
    define method display (s :: <string>)
      do-display-string(s);
    end;
    
    define method display (f :: <float>)
      do-display-float(f);
    end;
    
    define method display (c :: <collection>)
      for (item in c)
        display(item);  // runtime dispatch
      end;
    end;

    В закромах истории нашёлся язык с runtime dispatch/multimethods.

    Desktop, 03 Февраля 2020

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