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

    В номинации:
    За время:
  2. Куча / Говнокод #28121

    +1

    1. 1
    2. 2
    3. 3
    https://hr.cetera.ru/tests-developers/
    
    Какой мяуздец )))

    Внимание, кандидаты в стажёры!

    Тестовое задание (поле анкеты «Ссылку на выполненное тестовое задание (ТОЛЬКО ДЛЯ СТАЖЁРОВ).») требуется выполнять сразу. Анкеты без тестового задания не рассматриваем, отказываем сразу. Этот тест — первое, на что смотрит проверяющий анкеты. Если поле пустое или там написано что-то вроде «сделаю потом» — «потом» не будет.

    KoWe4Ka_l7porpaMMep, 17 Апреля 2022

    Комментарии (30)
  3. Си / Говнокод #27516

    +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
    while (1) {
        uint16_t state = in(USB_BASE + USB_ISTR);
        if (state & 0x8000) {
            uint16_t epstat = in(USB_BASE + USB_EP0R);
            if (epstat & 0x8000) {
                // RX done
                if (epstat & 0x0800) {
                    // setup
                    if ((usbRead(0x180) == 0x80) && (usbRead(0x181) == 0x06)) {
                        uint16_t maxlen = (usbRead(0x187) << 8) | usbRead(0x186);
                        if (usbRead(0x183) == 0x01) {
                            // send device descriptor
                            copyToUsb(0x0100, deviceDescriptor, sizeof(deviceDescriptor));
                            if (sizeof(deviceDescriptor) < maxlen)
                                maxlen = sizeof(deviceDescriptor);
                            out(USB_SRAM_BASE + 0x04, 0x9000 + maxlen); // TX count
                            // STAT_TX=11 (valid)
                            if ((in(USB_BASE + USB_EP0R) & 0x0010) != 0x0010)
                                out(USB_BASE + USB_EP0R, 0x0210);
                            if ((in(USB_BASE + USB_EP0R) & 0x0020) != 0x0020)
                                out(USB_BASE + USB_EP0R, 0x0220);
                        } else if (usbRead(0x183) == 0x02) {
                            // send config descriptor
                            copyToUsb(0x0100, configDescriptor, sizeof(configDescriptor));
                            if (sizeof(configDescriptor) < maxlen)
                                maxlen = sizeof(configDescriptor);
                            out(USB_SRAM_BASE + 0x04, 0x9000 + maxlen); // TX count
                            // STAT_TX=11 (valid)
                            if ((in(USB_BASE + USB_EP0R) & 0x0010) != 0x0010)
                                out(USB_BASE + USB_EP0R, 0x0210);
                            if ((in(USB_BASE + USB_EP0R) & 0x0020) != 0x0020)
                                out(USB_BASE + USB_EP0R, 0x0220);
                        } else {
    
    // ... и ещё сотня строк в том же духе ...

    Иногда в меня вселяется дух PHP...

    bormand, 13 Июля 2021

    Комментарии (30)
  4. JavaScript / Говнокод #27434

    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
    function t_undef(s?: string)
    {
    	assert((s == undefined) == true, "is not undefined")
    	assert((s != undefined) == false, "is undefined")
    	assert((s >  undefined) == false, "not >");
    	assert((s <  undefined) == false, "not <");
    	assert((s >= undefined) == true, "not >=");
    	assert((s <= undefined) == true, "not <=");
    }
    
    function t_val(s?: string)
    {
    	assert((s == undefined) == false, "is undefined")
    	assert((s != undefined) == true, "is not undefined")
    	assert((s >  undefined) == true, ">");
    	assert((s <  undefined) == false, "<");
    	assert((s >= undefined) == true, ">=");
    	assert((s <= undefined) == false, "<=");
    }
    
    function f(s?: string)
    {
    	print(s == undefined, s != undefined, s > undefined, s < undefined, s >= undefined, s <= undefined);
    }
    
    function main() {
    	f();
    	t_undef();
    	f("asd");
    	t_val("asd");
    }

    внеочередной говнокод для работы с андефами. А ваш говно-компилятор умеет так (особенно С и С++)

    гы гы

    ASD_77, 21 Мая 2021

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

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    vector<int> res;
    ...
    for (int i = 0; i < res.size(); i++) {
        printf("%d%c", res[i], " \n"[i + 1 == res.size()]);
    }

    Решил вспомнить как олимпиадные задачки решать.

    3_dar, 07 Мая 2021

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

    +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
    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
    function main()
    {
    	f1();
    }
    
    function f1(a = 10)
    {    
        return a;
    }
    
    // code for 1
    
    module @"1.ts"  {
      func @main() {
        %c0_i32 = constant 0 : i32
        %0 = typescript.undef : i32
        %1 = call @f1(%c0_i32, %0) : (i32, i32) -> i32
        return
      }
      func private @f1(%arg0: i32, %arg1: i32) -> i32 attributes {OptionalFrom = 1 : i8} {
        %c10_i32 = constant 10 : i32
        %c1_i32 = constant 1 : i32
        %0 = alloca() : memref<i32>
        %1 = cmpi ult, %arg0, %c1_i32 : i32
        %2 = scf.if %1 -> (i32) {
          scf.yield %c10_i32 : i32
        } else {
          scf.yield %arg1 : i32
        }
        store %2, %0[] : memref<i32>
        %3 = load %0[] : memref<i32>
        return %3 : i32
      }
    }
    
    // code for 2
    
    ; ModuleID = 'LLVMDialectModule'
    source_filename = "LLVMDialectModule"
    target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
    target triple = "x86_64-pc-windows-msvc"
    
    declare i8* @malloc(i64)
    
    declare void @free(i8*)
    
    define void @main() !dbg !3 {
      %1 = call i32 @f1(i32 0, i32 undef), !dbg !7
      ret void, !dbg !9
    }
    
    define i32 @f1(i32 %0, i32 %1) !dbg !10 {
      %3 = alloca i32, i64 ptrtoint (i32* getelementptr (i32, i32* null, i64 1) to i64), align 4, !dbg !11
      %4 = insertvalue { i32*, i32*, i64 } undef, i32* %3, 0, !dbg !11
      %5 = insertvalue { i32*, i32*, i64 } %4, i32* %3, 1, !dbg !11
      %6 = insertvalue { i32*, i32*, i64 } %5, i64 0, 2, !dbg !11
      %7 = icmp ult i32 %0, 1, !dbg !11
      br i1 %7, label %8, label %9, !dbg !11
    
    8:                                                ; preds = %2
      br label %10, !dbg !11
    
    9:                                                ; preds = %2
      br label %10, !dbg !11
    
    10:                                               ; preds = %8, %9
      %11 = phi i32 [ %1, %9 ], [ 10, %8 ]
      br label %12, !dbg !11
    
    12:                                               ; preds = %10
      %13 = extractvalue { i32*, i32*, i64 } %6, 1, !dbg !11
      store i32 %11, i32* %13, align 4, !dbg !11
      %14 = extractvalue { i32*, i32*, i64 } %6, 1, !dbg !11
      %15 = load i32, i32* %14, align 4, !dbg !11
      ret i32 %15, !dbg !13
    }

    История о том как я компайлер писал. (предисторию знают думаю все). Посмотрите на код и сравните с ужасным кодом на С. Это простенький javascript который тоже може быть скомпиленным в исполняемый год. а что для этого надо. просто несколько шагов.

    1) компилим код через чудо компилятор tsc.exe --emit=mlir-affine c:\1.ts



    а дальше может получить LLVM IL который можно компилировать

    2) компилим код через чудо компилятор tsc.exe --emit=mlir-llvm c:\1.ts



    а далее компилим код

    llc.exe --filetype=obj -o=out.o 1.ll


    запускаем a.exe

    и оно работает :)

    ASD_77, 19 Февраля 2021

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

    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
    # ------------------- fUnicodeToUTF8----------------------
    :global fUnicodeToUTF8
    :if (!any $fUnicodeToUTF8) do={ :global fUnicodeToUTF8 do={
      :global fByteToEscapeChar
    #  :local Ubytes [:tonum $1]
      :local Nbyte
      :local EscapeStr ""
    
      :if ($1 < 0x80) do={
        :set EscapeStr [$fByteToEscapeChar $1]
      } else={
        :if ($1 < 0x800) do={
          :set Nbyte 2
        } else={  
          :if ($1 < 0x10000) do={
            :set Nbyte 3
          } else={
            :if ($1 < 0x20000) do={
              :set Nbyte 4
            } else={
              :if ($1 < 0x4000000) do={
                :set Nbyte 5
              } else={
                :if ($1 < 0x80000000) do={
                  :set Nbyte 6
                }
              }
            }
          }
        }
        :for i from=2 to=$Nbyte do={
          :set EscapeStr ([$fByteToEscapeChar ($1 & 0x3F | 0x80)] . $EscapeStr)
          :set $1 ($1 >> 6)
        }
        :set EscapeStr ([$fByteToEscapeChar (((0xFF00 >> $Nbyte) & 0xFF) | $1)] . $EscapeStr)
      }
      :return $EscapeStr
    }}

    угадай язык

    MAKAKA, 12 Января 2021

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

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    void tick(void)
    {
    	for (auto&& x : registry.objects)
    		(x? std::function<void(void)>([&](void) {((IObject*)(x))->tick(); }) : [&]() {})();
    }

    Мозг сказал что "((IObject*)(x))->tick();" написать слишком сложно и повелел написать вот это.

    digitalEugene, 03 Сентября 2020

    Комментарии (30)
  9. Куча / Говнокод #26473

    +3

    1. 1
    2. 2
    3. 3
    function strEqual(string a, string b) private returns (bool) {
        return sha3(a) == sha3(b);
    }

    Как проверить идентичность строк, если ты криптовалютчик?

    https://github.com/axic/mango/blob/83ef808eba1571097fecd8d8e08303a82f69d68c/MangoRepo.sol#L83-L85

    Fike, 07 Марта 2020

    Комментарии (30)
  10. JavaScript / Говнокод #26314

    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
    // ==UserScript==
    // @name     Unnamed Script 230178
    // @version  1
    // @grant    none
    // @include  https://www.instagram.com/*
    // ==/UserScript==
    
    window.addEventListener('load', function(){
      console.log("my script starting...");
      const body = document.querySelector('body');
      const config = {
        attributes: true,
        attributeFilter: ["style"]
      };
      const callback = function(mutationsList, observer) {
        console.log("mutation aaargh-aaarghrghrhg");
        for (let mutation of mutationsList) {
            console.log('zaloop');
            // if (mutation.type === 'attributes' && mutation.attributeName === 'style') {
            try {
              body.setAttribute('style', '');
              document.querySelector('.RnEpo').setAttribute('style', 'display: none;');
              observer.disconnect();
              console.log("#hide");
            } catch (e) {
              console.log(e);
            }
            // }
        }
      };
      const observer = new MutationObserver(callback);
      observer.observe(body, config);
      console.log("my script stop");
    });

    Ночью не спал
    Инстаграм листал
    Чтобы баннер не мешал
    Такой скрипт написал.

    hanapi, 05 Января 2020

    Комментарии (30)
  11. PHP / Говнокод #25770

    +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
    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
    <?php
    
    namespace App\Http\Controllers\Admin;
    
    use App\Command\Admin\User\Create\Command as UserCreateCommand;
    use App\Command\Admin\User\Update\Command as UserUpdateCommand;
    use App\Command\Admin\User\Remove\Command as UserRemoveCommand;
    use App\Command\User\Auth\Verify\Command as UserVerifyCommand;
    use App\Command\Admin\User\Draft\Command as UserDraftCommand;
    use App\Command\CommandBus;
    use App\Entity\User\User;
    use App\Http\Controllers\Controller;
    use App\Http\Requests\Admin\Users\CreateRequest;
    use App\Http\Requests\Admin\Users\UpdateRequest;
    use App\Query\Admin\User\FindUsersByDescQuery;
    use App\Query\Admin\User\Role\GetUserRolesQuery;
    use App\Query\Admin\User\Status\GetUserStatusesQuery;
    use App\Query\QueryBus;
    use Illuminate\Database\Eloquent\Builder;
    use Illuminate\Http\Request;
    
    class UsersController extends Controller
    {
        private $commandBus;
        private $queryBus;
    
        public function __construct(CommandBus $commandBus, QueryBus $queryBus)
        {
            $this->commandBus = $commandBus;
            $this->queryBus = $queryBus;
        }
    
        public function index()
        {
            $query = $this->queryBus->query(new FindUsersByDescQuery());
            $users = $query->paginate(20);
    
            $statuses = $this->queryBus->query(new GetUserStatusesQuery());
            $roles = $this->queryBus->query(new GetUserRolesQuery());
    
            return view('admin.users.index', compact('users', 'statuses', 'roles'));
        }
    
        public function create()
        {
            return view('admin.users.create');
        }
    
        public function store(CreateRequest $request)
        {
            $this->commandBus->handle(new UserCreateCommand($request));
    
            return redirect()->route('admin.users.index');
        }
    
        public function show(User $user)
        {
            return view('admin.users.show', compact('user'));
        }
    
        public function edit(User $user)
        {
            $roles = $this->queryBus->query(new GetUserRolesQuery());
    
            return view('admin.users.edit', compact('user', 'roles'));
        }
    
        public function update(UpdateRequest $request, User $user)
        {
            $this->commandBus->handle(new UserUpdateCommand($request, $user));
    
            return redirect()->route('admin.users.index');
        }
    
        public function destroy(User $user)
        {
            $this->commandBus->handle(new UserRemoveCommand($user));
    
            return redirect()->route('admin.users.index');
        }
    
        public function verify(User $user)
        {
            $this->commandBus->handle(new UserVerifyCommand($user));
    
            return redirect()->route('admin.users.show', $user);
        }
    
        public function draft(User $user)
        {
            $this->commandBus->handle(new UserDraftCommand($user));
    
            return redirect()->route('admin.users.show', $user);
        }
    }

    kartoshka, 20 Августа 2019

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