1. 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)
  2. 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)
  3. Куча / Говнокод #26987

    +1

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

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

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

    Комментарии (17)
  4. 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)
  5. Куча / Говнокод #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)
  6. 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)
  7. Си / Говнокод #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)
  8. Куча / Говнокод #26981

    +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
    Function/method calling convention. Here’s a simple example:
    
    struct Foo { a: i32 }
    impl Foo { fn bar(&mut self, val: i32) { self.a = val + 42; } }
    fn main() {
      let mut foo = Foo { a: 0 };
      foo.bar(foo.a);
    }
    
    For now this won’t compile because of the borrowing but shouldn’t the compiler be smart enough to create a copy of foo.a before call?
    I’m not sure but IIRC current implementation first mutably borrows object for the call and only then tries to borrow the arguments.
    Is it really so and if yes, why?
    Update: I’m told that newer versions of the compiler handle it just fine but the question still stands (was it just a compiler problem or the call definition has been changed?).
    
    The other thing is the old C caveat of function arguments evaluation. Here’s a simple example:
    
    let mut iter = “abc”.chars();
    foo(iter.next().unwrap(), iter.next().unwrap(), iter.next().unwrap());
    
    So would it be foo('a','b','c') or foo('c','b','a') call. In C it’s undefined because it depends on how arguments are passed on the current platform 
    (consider yourself lucky if you don’t remember __pascal or __stdcall). 
    
    In Rust it’s undefined because there’s no formal specification to tell you even that much. 
    And it would be even worse if you consider that you may use the same source for indexing the caller object like 
    handler[iter.next().unwrap() as usize].process(iter.next().unwrap()); in some theoretical bytecode handler 
    (of course it’s a horrible way to write code and you should use named temporary variables but it should illustrate the problem).

    https://codecs.multimedia.cx/2020/09/why-rust-is-not-a-mature-programming-language/

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

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

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    Зачем в базах данных нужны несколько вариаций одного и того же типа?
    Например, "tinyint", "mediumint", "smallint" и "bigint". Зачем они нужны, если
    можно было бы просто сделать один "int", причём равнозначный нынешнему
    "bigint"? Что даёт этот искусственно раздутый выбор целочисленных типов?

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

    Комментарии (64)
  10. Куча / Говнокод #26978

    −1

    1. 1
    https://foren.germany.ru/elecronics/f/20343575.html

    Математики из раш-ки изобрели бесконечные ноутбуки:

    «Если магазин предоставляет опцию возврата, если товар не понравился, то почему мне должно быть стыдно?
    Наоборот приятно - попользовался 3мя разными ноутами в течение месяца, не заплатив ни цента. Если бы им не нравилось это - они такую опцию не ввели бы, т.к. закон не обязывает.
    Я гляжу, на форуме тут мало кто знает о бесплатном 14-дневном прокате техники в Сатурне. :)»

    oaoaoammm, 25 Сентября 2020

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