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

    +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
    function isEven(a) {
      a = a. toString(). replace(/[^0-9.]/g, "");
      var stack = [];
      var rev = a. split(''). reverse();
      for (var ix = 0; ix < rev. length; ix++) {
        if (rev[ix] == ".") stack. push("dot")
        else if (rev[ix] == "1" || rev[ix] == "3" || rev[ix] =="5" || rev[ix] == "7" || rev[ix] == "9")
          stack. push ("odd")
        else
          stack. push('even')
      }
      var wholenumber = stack. splice(stack. indexof("dot") + 1)
      return wholenumber[0] == "even";
    }

    Определение чётности числа.

    IIIuMnAH3E, 08 Марта 2020

    Комментарии (5)
  2. 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)
  3. JavaScript / Говнокод #26472

    +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
    var buf = Buffer.allocUnsafe(kexInitSize);
        var p = 17;
    
        buf[0] = MESSAGE.KEXINIT;
    
        if (myCookie !== false)
          myCookie.copy(buf, 1);
    
        writeUInt32BE(buf, kexBuf.length, p);
        p += 4;
        kexBuf.copy(buf, p);
        p += kexBuf.length;
    
        writeUInt32BE(buf, hostKeyBuf.length, p);
        p += 4;
        hostKeyBuf.copy(buf, p);
        p += hostKeyBuf.length;
    
        writeUInt32BE(buf, algos.cipherBuf.length, p);
        p += 4;
        algos.cipherBuf.copy(buf, p);
        p += algos.cipherBuf.length;
    
        writeUInt32BE(buf, algos.cipherBuf.length, p);
        p += 4;
        algos.cipherBuf.copy(buf, p);
        p += algos.cipherBuf.length;
    
        writeUInt32BE(buf, algos.hmacBuf.length, p);
        p += 4;
        algos.hmacBuf.copy(buf, p);
        p += algos.hmacBuf.length;
    
        writeUInt32BE(buf, algos.hmacBuf.length, p);
        p += 4;
        algos.hmacBuf.copy(buf, p);
        p += algos.hmacBuf.length;
    
        writeUInt32BE(buf, algos.compressBuf.length, p);
        p += 4;
        algos.compressBuf.copy(buf, p);
        p += algos.compressBuf.length;
    
        writeUInt32BE(buf, algos.compressBuf.length, p);
        p += 4;
        algos.compressBuf.copy(buf, p);
        p += algos.compressBuf.length;
    
        // Skip language lists, first_kex_packet_follows, and reserved bytes
        buf.fill(0, buf.length - 13);

    Мечтают ли скриптухи об Электросишке?

    https://github.com/mscdex/ssh2-streams/blob/master/lib/ssh.js

    3.14159265, 07 Марта 2020

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

    +2

    1. 1
    2. 2
    3. 3
    Global Install
    Installing Yarn 2.x globally is discouraged as we're moving to a per-project install strategy. 
    We advise you to keep Yarn 1.x (Classic) as your global binary by installing it via the instructions you can find here.

    https://yarnpkg.com/getting-started/install

    Мы выпустили вторую версию приложеньки, в которой исправили все недочёты первой.
    Именно поэтому запускать вы её будете через первую версию, которая с вами навсегда.
    Мы проработали другие варианты и пришли к решению, что они все неправильные.

    Сердечно ваши,
    джаваскриптеры.

    Fike, 07 Марта 2020

    Комментарии (20)
  5. JavaScript / Говнокод #26446

    +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
    function isVowel(char){
        return "аоэиуыеёюя".indexOf(char.toLocaleLowerCase())>=0 ? 1 : 0;
    }
    
    function vorefy(text)
    {
        // Г => C 0.85
        // Г => Г 0.15
        // С => С 0.30
        // С => Г 0.70   
        var markov = [[0.3,0.7],[0.85,0.15]]; 
        var mCorr = [ 1/Math.sqrt(0.3*0.7), 1/Math.sqrt(0.85*0.15) ];
        //степень влияния марковских вореантностей
        var pow = x => Math.pow(x,2);
        
        var prev=null;
        return text.replace(/./g,(char,offset,text) => 
        {
            if (E2R[char]){
                var replace = Object.entries(E2R[char]);
                if (1==replace.length) {
                    prev = replace[0][0];
                    return prev;
                }
                var r = Math.random()*200, probability=0;
                for (const [k, v] of replace) {
                    vowel = isVowel(k);
                    probability += v * ((null==prev) ? 1 
                        : pow( 
                            mCorr[vowel]*2*markov[isVowel(prev)][vowel]
                        ));
                    if (r<=probability) {
                        prev = k;
                        return prev;
                    }
                }
            }
            prev=null;
            return char;
        });        
    }

    Марковым отмечена еще одна устойчивая закономерность открытых текстов, связанная с чередованием гласных и согласных букв. Им были подсчитаны частоты встречаемости биграмм вида гласная-гласная (г, г), гласная-согласная (г, с), согласная-гласная (с, г), согласная-согласная (с, с)

    [color=blur]https://ideone.com/VpkwXT[/color]

    3.14159265, 22 Февраля 2020

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

    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
    // sorry, I don't want to use any JS templater
    // so I'll concatenate html as strings, which is the worst practice
    // but my IntelliJ IDEA highlights html in strings well :)
    // and I write this code just4fun
    //
    // but to respect production I'll leave here something that will never be fixed
    // TODO: rewrite in Angular.js
    //
    // done!
    
    // ...
    
    // u still read this spaghetti?
    
    let evaluate = (s) => {
        completion = [];
        hist = [];
    
        let tokens = s.split(' ').filter((s) => s !== '');
    
        if (!tokens[0]) return;
        histfile.push(s);
    
        if (tokens[0] === 'clear') clear();
        else if (tokens[0] === 'aplay') aplay();
        else if (tokens[0] === 'man') try {
            template(tokens.slice(0, 2).join('_'))();
        } catch {
            stdout('No manual entry for <span class="red">' + tokens[1] + '</span>')
        }

    Сайт-визитка на plain js для подкаста в виде эмулятора терминала с пасхалками
    https://deveeps.prost.host/

    vistefan, 19 Февраля 2020

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

    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
    $('#search-map').on('click', '.v-card-prev', function () {
                var v_next = $(this)
                    .parent()
                    .find('.v-card-img-block .v-card-img-hidden.active')
                    .prev();
                if ($(v_next).length == 0) {
                    $(this)
                        .parent()
                        .find('.v-card-img-hidden.active')
                        .removeClass('active');
                    $(this)
                        .parent()
                        .find('.v-card-img-hidden:last')
                        .addClass('active');
                } else {
                    $(this)
                        .parent()
                        .find('.v-card-img-hidden.active')
                        .removeClass('active');
                    $(this)
                        .parent()
                        .find(v_next)
                        .addClass('active');
                }
                $(this)
                    .parent()
                    .find('.v-card-img-hidden.active')
                    .click();
            });
    
            $('#search-map').on('click', '.offers-favorite', function () {
                var favorID = $(this)
                    .closest('.js__product')
                    .attr('data-item');
                if ($(this).hasClass('active')) var doAction = 'delete';
                else var doAction = 'add';
                updateFavorite(favorID, doAction);
                return false;
            });

    phpBidlokoder2, 18 Февраля 2020

    Комментарии (1)
  8. JavaScript / Говнокод #26429

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    //Use this to convert OffSet to postive:
    
    var offset = new Date().getTimezoneOffset();
    console.log(offset);
    this.timeOffSet = offset + (-2*offset);
    console.log(this.timeOffSet);

    Это такой особый JS way, или я чего-то не понимаю?

    eukaryote, 10 Февраля 2020

    Комментарии (8)
  9. JavaScript / Говнокод #26427

    0

    1. 1
    let randomHexColor = (g = () => (a => (a < 16 ? '0' : '') + a.toString(16))(~~(Math.random() * 255)))() + g() + g();

    fuckyounoob, 09 Февраля 2020

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

    +3

    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
    onst addAdjacencies = (
      nodes,
    ) => (
      nodes
      .map(({
        colorId,
        id,
        x,
        y,
      }) => ({
        color: colors[colorId],
        eastId: (
          getNodeAtLocation({
            nodes,
            x: x + 1,
            y,
          })
        ),
        id,
        northId: (
          getNodeAtLocation({
            nodes,
            x,
            y: y - 1,
          })
        ),
        southId: (
          getNodeAtLocation({
            nodes,
            x,
            y: y + 1,
          })
        ),
        westId: (
          getNodeAtLocation({
            nodes,
            x: x - 1,
            y,
          })
        ),
      }))
      .map(({
        color,
        id,
        eastId,
        northId,
        southId,
        westId,
      }) => ({
        adjacentIds: (
          [
            eastId,
            northId,
            southId,
            westId,
          ]
          .filter((
            adjacentId,
          ) => (
            adjacentId !== undefined
          ))
        ),
        color,
        id,
      }))
    )

    https://medium.com/free-code-camp/bet-you-cant-solve-this-google-interview-question-4a6e5a4dc8ee

    джаваскриптер натужно пытается решить простейшую задачу "гугл уровня" с обходом, для увеличения кринжа прилагается поехавший кодстайл и решение на RxJS

    Fike, 08 Февраля 2020

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