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

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

    +1

    1. 1
    2. 2
    const regExp = new RegExp(filterValue.toLowerCase())
    return templates.filter((tmpl) => regExp.test(tmpl.title.toLowerCase()))

    Высрал "синьор", "тимлид" с большим опытом и головой.

    NickPepper, 25 Июля 2020

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

    +1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    var ER={}, x=new TextDecoder('KOI8-R').decode(Uint8Array.from( Array.apply(0,new Uint8Array(64).map( (_,b)=>b&1 ? 128+0x61+b/2 : 65+b/2 ))))
    for (var i=0;i<64;i+=2){
       if (i<52)
       ER[x[ i ]] = x[i+1], ER[ x[i].toLowerCase() ] = x[i+1].toLowerCase()
       ER[x[i+1]] = x[ i ], ER[x[i+1].toLowerCase()] = x[ i ].toLowerCase();
    }
    text=`<Налог>
        <Наименование>НДС</Наименование>
        <УчтеноВСумме>false</УчтеноВСумме>
    </Налог>`
    text.replace(/./g,(char,offset,text) =>  ER[char] || char);

    Из юзерскрипта для транслитерации в обоих направлениях.

    3.14159265, 07 Марта 2020

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

    +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
    // Задача: Рисовать в консоли прогресс бар, на сколько дней текущий год завершился
    
    static void ProgressBarOfElapsedDays(DateTime dateTime, bool isRefreshebleat = false)   // рефрешеБЛЕАТ! :))
    {
        int daysOfYear = DateTime.IsLeapYear(dateTime.Year) ? 366 : 365;
        int dayInProcents = daysOfYear * 100 / 100;     // WAT?
        int currentDay = dateTime.DayOfYear * 100;
        int daysOfYearNotElapsed = daysOfYear * 100 - currentDay;  // Сложный матан
        int procent = 100 - (daysOfYear * 100 - currentDay) / dayInProcents; 
        int buffer = 0;
    
        if (isRefreshebleat)
        {
            if (Console.CursorTop >= 1 || Console.CursorLeft >= 1)
            {
                Console.SetCursorPosition(Console.CursorLeft - Console.CursorLeft, Console.CursorTop - Console.CursorTop); // когда Console.SetCursorPosition(0, 0) недостаточно
            }
        }
    
        // остальной код
    }

    isRefreshebleat и всё остальное :))

    adoconnection, 06 Марта 2020

    Комментарии (59)
  5. C++ / Говнокод #26041

    +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
    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
    case Type::Instruction:
            {
              if (o == "movzwl") return OpCode::movzwl;
              if (o == "movzbl") return OpCode::movzbl;
              if (o == "shrb") return OpCode::shrb;
              if (o == "shrl") return OpCode::shrl;
              if (o == "xorl") return OpCode::xorl;
              if (o == "andl") return OpCode::andl;
              if (o == "ret") return OpCode::ret;
              if (o == "movb") return OpCode::movb;
              if (o == "cmpb") return OpCode::cmpb;
              if (o == "movl") return OpCode::movl;
              if (o == "jmp") return OpCode::jmp;
              if (o == "testb") return OpCode::testb;
              if (o == "incl") return OpCode::incl;
              if (o == "sarl") return OpCode::sarl;
              if (o == "decl") return OpCode::decl;
              if (o == "jne") return OpCode::jne;
              if (o == "je") return OpCode::je;
              if (o == "js") return OpCode::js;
              if (o == "subl") return OpCode::subl;
              if (o == "subb") return OpCode::subb;
              if (o == "addl") return OpCode::addl;
              if (o == "addb") return OpCode::addb;
              if (o == "sall") return OpCode::sall;
              if (o == "orl") return OpCode::orl;
              if (o == "andb") return OpCode::andb;
              if (o == "orb") return OpCode::orb;
              if (o == "decb") return OpCode::decb;
              if (o == "incb") return OpCode::incb;
              if (o == "rep") return OpCode::rep;
              if (o == "notb") return OpCode::notb;
              if (o == "negb") return OpCode::negb;
              if (o == "sbbb") return OpCode::sbbb;
              if (o == "pushl") return OpCode::pushl;
              if (o == "retl") return OpCode::retl;
            }

    Фрагмент транслятора из ассемблера в ассемблер.

    https://github.com/lefticus/x86-to-6502

    XYPO3BO3, 24 Ноября 2019

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

    +1

    1. 1
    "Performance is easy. All you need to know is everything" (c) S. Kuksenko (@kuksenk0)

    Умеете профилировать программы?
    Знаете, что такое flame diagram? Умеете посмотреть стектрейс от входа в тред до какого-нить спинлока в ядре? Смотрите асм своего компилятора или джита? Знаете, какая инструкция сколько занимает?
    Умеете по vmstat/iostat или xperf/perf counters увидать проблему и соотнести ее с программой? Используете dtrace голый или с instruments? yourkit? vTune? valgrind? bpf?
    Или такие же дебилы, как я?

    MAKAKA, 20 Октября 2019

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

    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
    #include <stdlib.h>
    
    #define printf() print()
    
    int main(void) 
    {
        int a = 0;
    
        a = a++ + ++a;
    
        print("I'm using macro that redefine printf() function (%d).", a);
    
        return 0;
    }

    Ыыыыыыыы
    суть говнокода же чтоб он собрал максимум красных цифр?
    это не мой код честно!!!

    Ksyrx, 31 Июля 2019

    Комментарии (59)
  8. Куча / Говнокод #25604

    −102

    1. 1
    Всё. Петухи закончились. Всем спасибо, все свободны.

    nocJlegHuu_nemyx, 16 Мая 2019

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

    +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
    template < typename T >
    T shit (void)
    {
      return 0;
    }
    
    int main()
    {
      int crap = shit();
    // Почему дедукция аргумента шаблона в данном случае не работает?
      return crap;
    }
    
    //-------------------------------------
    
    int shit (void)
    {
      return 0;
    }
    
    // Почему functions that differ only in their return type cannot be overloaded 
    double shit (void)
    {
      return 0;
    }
    
    int main()
    {
      int crap = shit();
      return crap;
    }

    Почему плюсы такое говно?

    j123123, 22 Января 2018

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

    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
    89. 89
    90. 90
    91. 91
    #include <algorithm>
    #include <exception>
    #include <iostream>
    #include <memory>
    #include <string>
    #include <vector>
    #include <random>
    #include <chrono>
    #define __CL_ENABLE_EXCEPTIONS
    #include "cl.hpp"
    
    using namespace std::string_literals;
    
    
    int main(int argc, char * argv[]) {
      
      
      size_t data_len = (1024 * 1024 * strtoul(argv[1], nullptr, 10)) / sizeof(uint32_t),
             out_len = strtoul(argv[2], nullptr, 10),
             iter = strtoul(argv[3], nullptr, 10),
             block_size = strtoul(argv[4], nullptr, 10);
      
      std::string src = R"(
        typedef unsigned int uint32_t;
    __kernel void bench(global const uint32_t * data, global uint32_t * out) {
        
        uint32_t res = 0, id = get_global_id(0), next = id;
        for(uint32_t i = 0; i < )"s + std::to_string(iter) + R"(; ++i) {
            for(uint32_t j = 0; j < )" + std::to_string(block_size / sizeof(uint32_t)) +  R"(; ++j)
                res ^= data[next + j];
            next = data[next];
        }
        out[id] = res;
        
    }
      
      )"s;
      
      cl::Program::Sources sources = {{src.data(), src.size()}};
    
    
      std::vector<cl::Platform> platforms;
      cl::Platform::get(&platforms);
      
      std::vector<uint32_t> data(data_len);
      std::vector<uint32_t> out(out_len);
      
      std::generate(std::begin(data), std::end(data), [=,gen = std::mt19937{}]() mutable {
        return gen() % (data_len - (block_size / sizeof(uint32_t)));
      });
      
      for(auto & platform : platforms) {
        std::cout << "Using platform: " << platform.getInfo<CL_PLATFORM_NAME>() << "\n";
        std::vector<cl::Device> devices;
        platform.getDevices(CL_DEVICE_TYPE_GPU, &devices);
        for(auto & device : devices) {
          try {
            std::cout << "Using device: " << device.getInfo<CL_DEVICE_NAME>() << "\n";
            cl::Context ctx({device});
            cl::Program program(ctx, sources);
            program.build({device});
            
            cl::Buffer data_buffer(ctx, CL_MEM_READ_WRITE, data.size() * sizeof(uint32_t));
            cl::Buffer out_buffer(ctx, CL_MEM_READ_WRITE, out.size() * sizeof(uint32_t));
            cl::CommandQueue queue(ctx, device);
            queue.enqueueWriteBuffer(data_buffer, CL_TRUE, 0, data.size() * sizeof(uint32_t), data.data());
            
            cl::make_kernel<cl::Buffer &, cl::Buffer &> bench(program, "bench");
            cl::EnqueueArgs eargs(queue,cl::NullRange,cl::NDRange(out.size()),cl::NullRange);
            
            auto start = std::chrono::high_resolution_clock::now();
            bench(eargs, data_buffer, out_buffer).wait();
            auto time = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::high_resolution_clock::now() - start).count();
            
            size_t ops = out_len * iter;
            size_t total_tp = ops * block_size;
            double miops = (ops / time) / (1000 * 1000);
            double tpgbps = (total_tp / time) / (1024 * 1024 * 1024);
            fprintf(stderr, "Result: %.2fMIOPS, %.2fGB/s, %.2fsec\n", miops, tpgbps, time);
            
            
            queue.enqueueReadBuffer(out_buffer, CL_TRUE, 0, out.size() * sizeof(uint32_t), out.data());   
          
          } catch(cl::Error e) {
            std::cout << e.what() << " : " << e.err() << std::endl;
            std::terminate();
          }
        }
        
      }
    }

    Код Царя
    https://www.linux.org.ru/forum/development/13489159
    https://github.com/superhackkiller1997/gpu_mem_benchmark/blob/master/main.cpp

    j123123, 12 Июля 2017

    Комментарии (59)
  11. Си / Говнокод #20900

    +2000

    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
    unsigned int get_spoofed() {
        char spa[21];
        int a, b, c, d;
    
        srand(time(0));
    
        random_ct = rand();
        random_num = ((random_ct % 254) + 1);
        a = random_num;
    
        random_ct = rand();
        random_num = ((random_ct % 254) + 1);
        b = random_num;
    
        random_ct = rand();
        random_num = ((random_ct % 254) + 1);
        c = random_num;
    
        random_ct = rand();
        random_num = ((random_ct % 254) + 1);
        d = random_num;
    
        snprintf(spa, sizeof(spa), "%d.%d.%d.%d", a, b, c, d);
    
        return ((unsigned int)host2ip(spa));
    }

    Ддосбот для роутеров https://github.com/eurialo/lightaidra/blob/master/source/utils.c

    nyaknyan, 20 Августа 2016

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