1. JavaScript / Говнокод #26992

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    const breakpointChecker = function() {
        if ( breakpoint.matches === true ) {
            //...
            return;
        } else if ( breakpoint.matches === false ) {
            //...
        }
    };

    Источник: https://medium.com/@networkaaron/swiper-how-to-destroy-swiper-on-min-width-breakpoints-a947491ddec8

    denistrator, 01 Октября 2020

    Комментарии (5)
  2. Java / Говнокод #26991

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    public static <T> Comparator<T> reverseOrder(Comparator<T> cmp) {
        if (cmp == null)
            return reverseOrder();
    
        if (cmp instanceof ReverseComparator2)
            return ((ReverseComparator2<T>)cmp).cmp;
    
        return new ReverseComparator2<>(cmp);
    }

    кишки стандартной библиотеки йажи продолжают радовать, хорошо хоть нет ReverseComparatorFinal или ReverseComparatorBassBoostedByKirillXXL

    Fike, 30 Сентября 2020

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

    −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
    using System;
    
    namespace c_2
    {
        class Program
        {
            static void Main(string[] args)
            {
            start: 
            Console.WriteLine("введите первое число");
            var a = Convert.ToDouble(Console.ReadLine());;
            Console.WriteLine("введите второе число");
            var b = Convert.ToDouble(Console.ReadLine());;
            Console.WriteLine("Введите действие(+ - * /)");
            string act=Console.ReadLine();
            if (act == "+") 
            {
                Console.WriteLine(a+b);
            } 
            else
            {
                if (act == "-")
                {
                    Console.WriteLine(a - b); 
                }
                else
                {
                    if(act=="*")
                    {
                        Console.WriteLine(a*b);
                    }
                    else
                    {
                        if (act == "/")
                        {
                            Console.WriteLine(a/b); 
                        }
                    }
            }
            Console.WriteLine("Выйти?(y/n)");
            string exit = Console.ReadLine();
            if (exit == "y" )
            {
                Environment.Exit(0);
    
            }
            else
            {
                if (exit == "n")
                {
                    goto start;
                }
                
                {
                    
                }
            }
            }
            }
            
        }
    }

    Калькулятор(моя первая прога на шарпе)

    abrewbrew, 30 Сентября 2020

    Комментарии (28)
  4. PHP / Говнокод #26989

    +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
    $userId = getUser(); //получаем список всех пользователей 
    
        $valueArray = array(); 
        $keyArray = array(); 
        $valueArray1 = array();
        $keyArray1 = array();
        $resultArray = array();
        $resultArray1 = array();
        for($i=0;$i<count($userId);$i++){
            array_push($valueArray,$userId[$i]['user_id']);
            array_push($keyArray,$userId[$i]['status']);
        }
        for ($i = 0; $i<count($keyArray); $i++) {
            $resultArray[$valueArray[$i]] = $keyArray[$i];
        }
        for($i=0;$i<count($userId);$i++){
            array_push($valueArray1,$userId[$i]['user_id']);
            array_push($keyArray1,$userId[$i]['active']);
        }
        for ($i = 0; $i<count($keyArray1); $i++) {
            $resultArray1[$valueArray1[$i]] = $keyArray1[$i];
        }
        $array = array();
        foreach ($resultArray as $key => $value){
            if($value==="finish"){
                if($resultArray1[$key]==='Y'){
                    array_push($array,$key);
                }
            }
        }

    Получаем массив пользователей у которых завершен звонок.

    Антон, 30 Сентября 2020

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

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    class std::unordered_map<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,
    enum REG,struct std::hash<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >,
    struct std::equal_to<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >,
    class std::allocator<struct std::pair<class std::basic_string<char,struct std::char_traits<char>,
    class std::allocator<char> > const ,enum REG> > > registers" 
    (?registers@@3V?$unordered_map@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@W4REG@@U?$hash@V?$
    basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@U?$equal_to@V?$basic_string@DU?$char_traits@D@std@@V?
    $allocator@D@2@@std@@@2@V?$allocator@U?$pair@$$CBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@W4
    REG@@@std@@@2@@std@@A) уже определен в decoder.obj	PVC-16	C:\Users\Люда\source\repos\PVC-16\PVC-16\interrupt.obj	1

    Похлопаем visual c++ за понятный лог.

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

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

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    Я вот смотрю на Ричарда Столлмана... Вижу, как он всю жизнь рвёт на себе жопчик за халявное ПО...
    И думаю: а что сделал ОН? Он написал "Photoshop"? Создал "Windows"? Разработал хоть что-то?
    Знает ли он, что такое многочасовой, многодневный, многомесячный, а иногда и многолетний труд разработки?
    Всё его достижение - это ТЕКСТ лицензии "GNU". Всё.
    В чём смысл Ричарда Столлмана?

    И, кстати, нахуй вообще нужны лицензии на халявное ПО?

    rotoeb, 30 Сентября 2020

    Комментарии (17)
  7. Go / Говнокод #26985

    0

    1. 1
    2. 2
    func verbMatches(p abac.Policy, a authorizer.Attributes) bool {
    	// TODO: match on verb

    серёга, задолбал, давай уже в прод катить, потом свою авторизацию сделаешь

    https://github.com/kubernetes/kubernetes/blob/master/pkg/auth/authorizer/abac/abac.go#L178

    Fike, 28 Сентября 2020

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

    +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
    pub struct Vec { x: u32, y: u32, z: u32, }
    
    pub extern "C" fn sum_c(a: &Vec, b: &Vec) -> Vec {
        return Vec {x: a.x + b.x, y: a.y + b.y, z: a.z + b.z };
    }
    
    pub fn sum_rust(a: &Vec, b: &Vec) -> Vec {
        return Vec {x: a.x + b.x, y: a.y + b.y, z: a.z + b.z };
    }
    
    Выхлоп:
    
    example::sum_c:
            mov     eax, dword ptr [rsi]
            add     eax, dword ptr [rdi]
            mov     ecx, dword ptr [rsi + 4]
            add     ecx, dword ptr [rdi + 4]
            mov     edx, dword ptr [rsi + 8]
            add     edx, dword ptr [rdi + 8]
            shl     rcx, 32
            or      rax, rcx
            ret
    
    example::sum_rust:
            mov     ecx, dword ptr [rdx]
            mov     r8d, dword ptr [rdx + 4]
            add     ecx, dword ptr [rsi]
            add     r8d, dword ptr [rsi + 4]
            mov     edx, dword ptr [rdx + 8]
            add     edx, dword ptr [rsi + 8]
            mov     rax, rdi
            mov     dword ptr [rdi], ecx
            mov     dword ptr [rdi + 4], r8d
            mov     dword ptr [rdi + 8], edx
            ret

    «Дак йаже как Сишка!», «Даёшь пuтушатню в Ядро!»
    https://godbolt.org/z/Tcnz75
    rustc 1.46 (latest)

    3.14159265, 28 Сентября 2020

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

    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
    #include <cstdlib>
    #include <chrono>
    #include <iostream>
    #include <thread>
    
    int p = 0;
    int *q = nullptr;
    
    void g()
    {
        using namespace std::chrono_literals;
    
        std::cout << "g()" << std::endl;
    
        std::cout << "g(): p = 1" << std::endl;
        p = 1;
    
        std::this_thread::sleep_for(1s);
    
        
        if (q != nullptr) {
            std::cout << "g(): *q = 1" << std::endl;
            *q = 1;
        } else {
            std::cout << "g(): q == nullptr" << std::endl;
        }
    }
    
    void f()
    {
        using namespace std::chrono_literals;
    
        std::cout << "f()" << std::endl;
    
        if (p == 0) {
            std::cout << "f(): first loop start" << std::endl;
            while (p == 0) { }  // Потенциально конечный
            std::cout << "f(): first loop end" << std::endl;
        }
    
        int i = 0;
        q = &i;
        std::cout << "f(): second loop start" << std::endl;
        while (i == 0) { }  // Потенциально конечный, хотя в условии только автоматическая пельменная
        std::cout << "f(): second loop end" << std::endl;
    }
    
    int main()
    {
        using namespace std::chrono_literals;
    
        std::cout << "f() thread start" << std::endl;
        auto thr1 = std::thread(f);
        thr1.detach();
        std::this_thread::sleep_for(1s);
    
        std::cout << "g() thread start" << std::endl;
        auto thr2 = std::thread(g);
        thr2.detach();
        std::this_thread::sleep_for(2s);
    
        std::cout << "Done" << std::endl;
        
        std::_Exit(EXIT_SUCCESS);
    }

    Ожидание:

    f() thread start
    f()
    f(): first loop start
    g() thread start
    g()
    g(): p = 1
    f(): first loop end
    f(): second loop start
    g(): *q = 1
    f(): second loop end
    Done

    gost, 28 Сентября 2020

    Комментарии (75)
  10. Си / Говнокод #26982

    +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
    /* https://habr.com/ru/company/piter/blog/491996/
    
    Пусть в Python такая штука и называется генератором, в языке C++ она
    называлась бы корутиной. Пример взят с этого сайта: https://masnun.com/2015/11/13/python-generators-coroutines-native-coroutines-and-async-await.html
    
    def generate_nums():
         num = 0
         while True:
              yield num
              num = num + 1	
    
    nums = generate_nums()
    	
    for x in nums:
         print(x)
    	
         if x > 9:
    */
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <stdint.h>
    #include <stdbool.h>
    
    #define START 0
    #define YIELD 1
    
    typedef struct 
    {
      uint8_t jmpto;
      int num;
    } coroutine_state;
    
    
    int generate_nums(coroutine_state *state)
    {
      switch(state->jmpto)
      {
        case START: break;
        case YIELD: goto yield;
      }
      while (true)
      {
        state->jmpto = YIELD; return state->num; yield: // какая питушня
    
        state->num = state->num + 1;
      }
    }
    
    
    
    
    int main(void)
    {
      int x;
      coroutine_state st = {START, 0};
      while(true)
      {
        x = generate_nums(&st);
        printf("%d\n", x);
    
        if (x > 9)
        {
          break;
        }
      }
      return EXIT_SUCCESS;
    }

    Попробовал переписать эту ко-ко-корутину c питуха на Си - получилась какая-то херня нечитаемая. что еще раз доказывает, что корутины нахуй не нужны

    К тому же в крестопарашном говне они требуют хип, а это нахуй не нужно на самом-то деле.

    j123123, 28 Сентября 2020

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