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

    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
    let users = [
      user_1 = {
        user_name: 'Первый',
        user_login: 'l1',
        user_password: 'p1'
      },
      user_2 = {
        user_name: 'Второй',
        user_login: 'l2',
        user_password: 'p2'
      },
      user_3 = {
        user_name: 'Третий',
        user_login: 'l3',
        user_password: 'p3'
      }
    ]
    
    function authorisation(guest_login, guest_password) {
      for (let key in users) {
        if(guest_login == users[key].user_login && guest_password == users[key].user_password) {
          return alert('Хай ' + users[key].user_name);
        } else {
          alert('Чёт не то'); continue;
        }
      }
    }
    
    authorisation(prompt('Введите логин'), prompt('введите пароль'))

    Вот казалось бы, ну чего тут сложного? А чёт сложно. Всего-то и нужно - пробегаться по массиву объектов, сверять логины и пароли и либо здороваться с пользователем, либо выдавать сообщение об ошибке. Находить пользователя у меня получается, проблема в том, что если он не первый по счёту, то сообщение об ошибке выпадает на каждого предыдущего. Ну и если крутить вертеть последовательность, то просто на каждого с кем данные не совпадают. Как бы мне этого избежать?

    shuric, 18 Сентября 2021

    Комментарии (27)
  2. Куча / Говнокод #27671

    0

    1. 1
    IT Оффтоп #116

    #86: https://govnokod.ru/27405 https://govnokod.xyz/_27405
    #87: https://govnokod.ru/27429 https://govnokod.xyz/_27429
    #88: https://govnokod.ru/27432 https://govnokod.xyz/_27432
    #89: https://govnokod.ru/27435 https://govnokod.xyz/_27435
    #90: https://govnokod.ru/27439 https://govnokod.xyz/_27439
    #91: https://govnokod.ru/27449 https://govnokod.xyz/_27449
    #92: https://govnokod.ru/27460 https://govnokod.xyz/_27460
    #93: https://govnokod.ru/27463 https://govnokod.xyz/_27463
    #94: https://govnokod.ru/27466 https://govnokod.xyz/_27466
    #95: https://govnokod.ru/27473 https://govnokod.xyz/_27473
    #96: https://govnokod.ru/27478 https://govnokod.xyz/_27478
    #97: https://govnokod.ru/27484 https://govnokod.xyz/_27484
    #98: https://govnokod.ru/27495 https://govnokod.xyz/_27495
    #99: https://govnokod.ru/27504 https://govnokod.xyz/_27504
    #100: https://govnokod.ru/27508 https://govnokod.xyz/_27508
    #101: https://govnokod.ru/27511 https://govnokod.xyz/_27511
    #102: https://govnokod.ru/27518 https://govnokod.xyz/_27518
    #103: https://govnokod.ru/27526 https://govnokod.xyz/_27526
    #104: https://govnokod.ru/27534 https://govnokod.xyz/_27534
    #105: https://govnokod.ru/27544 https://govnokod.xyz/_27544
    #106: https://govnokod.ru/27552 https://govnokod.xyz/_27552
    #107: https://govnokod.ru/27554 https://govnokod.xyz/_27554
    #108: https://govnokod.ru/27557 https://govnokod.xyz/_27557
    #109: https://govnokod.ru/27581 https://govnokod.xyz/_27581
    #110: https://govnokod.ru/27610 https://govnokod.xyz/_27610
    #111: https://govnokod.ru/27644 https://govnokod.xyz/_27644
    #112: https://govnokod.ru/27648 https://govnokod.xyz/_27648
    #113: https://govnokod.ru/27652 https://govnokod.xyz/_27652
    #114: https://govnokod.ru/27659 https://govnokod.xyz/_27659
    #115: https://govnokod.ru/27665 https://govnokod.xyz/_27665

    nepeKamHblu_nemyx, 17 Сентября 2021

    Комментарии (471)
  3. PHP / Говнокод #27670

    +2

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    if($response == null){
        echo "<pre>";
        var_dump($response);
        echo "</pre>";
        die();
    }

    Таким способом выводится на экран надпись NULL

    govnokoder2, 17 Сентября 2021

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

    +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
    private void LoadControlFile()
    {
        this.OFD2.Title = "Open an ORYZA Run Control File";
        this.OFD2.Filter = "Text Files|*.*";
        this.OFD2.ShowDialog();
        string path = this.OFD2.FileName.Trim();
        if (Path.GetExtension(path).ToUpper() != ".EXE")
        {
            this.TextBox2.Text = path;
        }
        else
        {
            string text = "Loading file is not a text file, RETRY!";
            MessageBox.Show(text, "Important Note", MessageBoxButtons.OK);
        }
    }

    Филипинская прога на Win Forms. Проверка на то что входной файл не исполняемый, а текстовый.

    contemporary_rapist, 17 Сентября 2021

    Комментарии (38)
  5. Куча / Говнокод #27668

    +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
    (* https://coq.inria.fr/library/Coq.Init.Datatypes.html *)
    
    (* Basic boolean operators *)
    
    Definition andb (b1 b2:bool) : bool := if b1 then b2 else false.
    
    Definition orb (b1 b2:bool) : bool := if b1 then true else b2.
    
    Definition implb (b1 b2:bool) : bool := if b1 then b2 else true.
    
    Definition xorb (b1 b2:bool) : bool :=
      match b1, b2 with
        | true, true => false
        | true, false => true
        | false, true => true
        | false, false => false
      end.
    
    Definition negb (b:bool) := if b then false else true.
    
    Infix "||" := orb : bool_scope.
    Infix "&&" := andb : bool_scope.

    На первый взгляд этот ваш Coq (питух) выглядит как очередной ML-язычок.

    j123123, 16 Сентября 2021

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

    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
    type int = 1;
    function main() {
        print("try/catch");
    
        let t = 1;
    
        try {
            throw 1;
        } catch (v: int) {
            print("Hello ", v);
            v = t;
        }
    
        assert(v == t);
    
        print("done.");
    }

    Ура ура.. новый говнокод подоспел... это гавно теперь параметры в тело "catch"-а передает

    ASD_77, 14 Сентября 2021

    Комментарии (32)
  7. JavaScript / Говнокод #27666

    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
    let randomNum = Math.floor(Math.random() * 10) + 1;
    let inputNum
    
    do {
      inputNum = prompt('Угадай циферку!')
      if (inputNum < randomNum) {
        alert('Недобор');
      } else if (inputNum > randomNum) {
        alert('Перебор');
      } else if (typeof inputNum === "string") {
        alert('ну не, циферку же!');
      } else if (inputNum == null || inputNum == '') {
        alert('Покасики!');
      } else if (inputNum === randomNum) { 
        alert('Угадал!!!'); break;
        }
    } while (inputNum != randomNum);

    Оно сначала совсем не работало. Потом вдруг заработало. Потом я ему дал полежать, настояться, и оно работать перестало опять О_о моя нипанимать

    shuric, 14 Сентября 2021

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

    0

    1. 1
    IT Оффтоп #115

    #85: https://govnokod.ru/27381 https://govnokod.xyz/_27381
    #86: https://govnokod.ru/27405 https://govnokod.xyz/_27405
    #87: https://govnokod.ru/27429 https://govnokod.xyz/_27429
    #88: https://govnokod.ru/27432 https://govnokod.xyz/_27432
    #89: https://govnokod.ru/27435 https://govnokod.xyz/_27435
    #90: https://govnokod.ru/27439 https://govnokod.xyz/_27439
    #91: https://govnokod.ru/27449 https://govnokod.xyz/_27449
    #92: https://govnokod.ru/27460 https://govnokod.xyz/_27460
    #93: https://govnokod.ru/27463 https://govnokod.xyz/_27463
    #94: https://govnokod.ru/27466 https://govnokod.xyz/_27466
    #95: https://govnokod.ru/27473 https://govnokod.xyz/_27473
    #96: https://govnokod.ru/27478 https://govnokod.xyz/_27478
    #97: https://govnokod.ru/27484 https://govnokod.xyz/_27484
    #98: https://govnokod.ru/27495 https://govnokod.xyz/_27495
    #99: https://govnokod.ru/27504 https://govnokod.xyz/_27504
    #100: https://govnokod.ru/27508 https://govnokod.xyz/_27508
    #101: https://govnokod.ru/27511 https://govnokod.xyz/_27511
    #102: https://govnokod.ru/27518 https://govnokod.xyz/_27518
    #103: https://govnokod.ru/27526 https://govnokod.xyz/_27526
    #104: https://govnokod.ru/27534 https://govnokod.xyz/_27534
    #105: https://govnokod.ru/27544 https://govnokod.xyz/_27544
    #106: https://govnokod.ru/27552 https://govnokod.xyz/_27552
    #107: https://govnokod.ru/27554 https://govnokod.xyz/_27554
    #108: https://govnokod.ru/27557 https://govnokod.xyz/_27557
    #109: https://govnokod.ru/27581 https://govnokod.xyz/_27581
    #110: https://govnokod.ru/27610 https://govnokod.xyz/_27610
    #111: https://govnokod.ru/27644 https://govnokod.xyz/_27644
    #112: https://govnokod.ru/27648 https://govnokod.xyz/_27648
    #113: https://govnokod.ru/27652 https://govnokod.xyz/_27652
    #114: https://govnokod.ru/27659 https://govnokod.xyz/_27659

    nepeKamHblu_nemyx, 14 Сентября 2021

    Комментарии (585)
  9. Java / Говнокод #27664

    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
    import java.util.Arrays;
    import java.util.Optional;
    
    public class AntiVirus{
      
      private int scanIntensity = 0;
      
      //this method is ready for you.
      public void setScanIntensity(int level){
        scanIntensity = level;
      }
      
      //write this method.
      public String scanFile(File file,VirusDB database){
        String[] signature = database.getSignatures(scanIntensity);
        String fileData = file.getData().toLowerCase();
        
         Optional<String> res = Arrays.stream(signature)
             .map(s -> s.toLowerCase())
             .filter(fileData::contains).findAny();
        
         String scan = " is safe";
        
         if(res.isPresent()) {
            System.out.println(res.get());
            System.out.println("scan: " + scan);
            scan = " is not safe";
            System.out.println("scan after: " + scan);
         }
        
        return file.getName() + scan;
      }
    }

    Не понимаю, почему не работает.

    Задача
    https://www.codewars.com/kata/5b13027eedd62c5216000001

    Test Results:
    AVTest
    checkRandomFiles
    Log
    dos
    scan: is safe
    scan after: is not safe
    dos
    scan: is safe
    scan after: is not safe
    dos
    scan: is safe
    scan after: is not safe
    dos
    scan: is safe
    scan after: is not safe
    dos
    scan: is safe
    scan after: is not safe
    dos
    scan: is safe
    scan after: is not safe
    dos
    scan: is safe
    scan after: is not safe
    dos
    scan: is safe
    scan after: is not safe
    dos
    scan: is safe
    scan after: is not safe
    expected:<f4wpzFoQD is [not ]safe> but was:<f4wpzFoQD is []safe>
    Stack Trace
    Completed in 476ms
    checkSameFilesWithDifferentIntensitySett ings
    Log
    virus
    scan: is safe
    scan after: is not safe
    expected:<file1 is [not ]safe> but was:<file1 is []safe>
    Stack Trace
    Completed in 1ms
    Completed in 496ms

    imrnccc, 14 Сентября 2021

    Комментарии (23)
  10. Java / Говнокод #27663

    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
    private static final Map<Integer, FieldInfo> HEAD_FIELDS = new ImmutableMap.Builder<Integer, FieldInfo>()
    			.put(5, new FieldInfo("DOC.CODEOKATO", FieldInfoType.STRING))
    //			.put(7, new FieldInfo("DOC.NAMECMO", FieldInfoType.STRING))
    			.put(8, new FieldInfo("DOC.CODECMO", FieldInfoType.STRING))
    //			.put(9, new FieldInfo("DOC.NAMEMEDORG", FieldInfoType.STRING))
    			.put(10, new FieldInfo("DOC.CODEMO", FieldInfoType.STRING))
    			.put(14, new FieldInfo("DOC.INFINSPERSON_BIRTHDAY", FieldInfoType.DATE))
    			.put(12, new FieldInfo("DOC.INFINSPERSON_NUMHEALINS", FieldInfoType.STRING))
    			.put(15, new FieldInfo("DOC.INFINSPERSON_GENDER", FieldInfoType.STRING))
    			.put(16, new FieldInfo("DOC.INFINSPERSON_DATESTRMED", FieldInfoType.DATE))
    			.put(17, new FieldInfo("DOC.INFINSPERSON_DATEFINMED", FieldInfoType.DATE))
    			.put(13, new FieldInfo("DOC.INFINSPERSON_NMEDICCARD", FieldInfoType.STRING))
    			.put(18, new FieldInfo("DOC.INFINSPERSON_CODEMKB", FieldInfoType.STRING))
    			.put(23 - 1, new FieldInfo("DOC.INFINSPERSON_SEVCOVID19", FieldInfoType.STRING))
    			.put(24 - 1, new FieldInfo("DOC.INFINSPERSON_SEVCOVID191", FieldInfoType.STRING))
    			.put(25 - 1, new FieldInfo("DOC.INFINSPERSON_SEVCOVID192", FieldInfoType.STRING))
    			.build();

    Коллега изменил мой код, пока я болел.

    zloer, 14 Сентября 2021

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