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

    +4

    1. 1
    2. 2
    while (st.indexOf(" ") != -1)
            st = st.replace(" ", " ");

    FrontlineReporter, 15 Мая 2016

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

    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
    /**
     * Static Content Helpers
     */
    (function (window, ng, app) {
    
        app.service('$StaticContentHelpers', function () {
    
            var instance = null;
    
            /**
             * Конструктор хелперов
             *
             * @returns {Object} Функции-хелперы
             * @constructor
             */
            function Init () {
    
                /**
                 * Обертка для статического контента,
                 * добавляет static домен, который пришел с бэкенда
                 *
                 * @param {String} url Урл, к которому необходимо добавить домен для статики
                 *
                 * @return {String} Готовый абсолютный url для статического контента
                 */
                function wrapStaticContent (url) {
                    // Проверим, от корня ли путь
                    return window.currentStaticDomain + ((/(^\/)/.test(url)) ? '' : '/') + url;
                }
    
                return {
                    wrapStaticContent: wrapStaticContent
                }
    
            }
    
            function getInstance () {
                if (!instance) {
                    instance = new Init();
                }
                return instance;
            }
    
            return {
                getInstance: getInstance
            };
    
        });
    
    }(window, angular, mainModule));

    гуру паттернов..

    _finico, 13 Мая 2016

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

    +5

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    $(document).on('click', 'a.switcher_link', function(e) {
        e.preventDefault();
        var btn = $(this);
        $.getJSON(btn.attr('href'), {type: 'json'}, function(data) {
          btn.parent().parent().parent().parent().parent().parent().parent().parent().replaceWith(data.data);
        });
      });

    Нашел и ахуел....

    gerasim13, 11 Мая 2016

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

    +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
    $ nodejs
    > var buffer = new ArrayBuffer(2);
    undefined
    > var uint16View = new Uint16Array(buffer);
    undefined
    > var uint8View = new Uint8Array(buffer);
    undefined
    > uint16View[0]=0xff00
    65280
    > uint8View[1]
    255
    > uint8View[0]
    0

    https://developer.mozilla.org/en/docs/Web/JavaScript/Typed_arrays
    endianness - теперь и в жабаскрипте. Почти как union

    j123123, 11 Мая 2016

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

    −2

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    this.params.IsCellEditable = function(rowNumber, cellNumber) {
    	cellNumber == 1;
    	this.params.ButtonList = this.params.ButtonList.filter(b=>b[0] === "OnRefresh");
    
    	let textContr = new CTextArea('textContr');
    	textContr.SourceName = "value";
    	textContr.ViewName = "Params";
    	textContr.ComEdit = true;
    	this.params.arrEditObj[1] = textContr;
    
    }

    Найдено в нашем проекте в старом модуле, в авторстве никто не признаётся.
    Во-первых, строка 2 бессмысленна. Во-вторых, всё последующее имело бы хоть какой-то смысл _вне_ этой функции, а внутри уже на строке 3 выкидывает ошибку, потому что контекст там и есть this.param из первой строчки. В-третьих, строка 3 призвана выкидывать из тулбара виджета this.param все кнопки, кроме OnRefresh, но на самом деле она там только одна и есть. В-четвёртых, строчки 7 и 8 просто лишние (ну, это из логики используемого в проекте движка следует). В-пятых, из названия метода можно предположить (и это действительно так), что он должен бы возвращать булевское значение, но он всегда возвращает только undefined и, таким образом, все ячейки виджета оказываются нередактируемыми — что совсем лишает смысла создание контрола для редактирования в строках 5—9.
    Редкостная бредятина. Кто-то в полном затмении писал, и даже десяти секунд не потратил на тестирование.

    torbasow, 06 Мая 2016

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

    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
    function floatToStringPrec(f, precisionDigits)
    {
        var PRECISION = Math.pow(10, precisionDigits);
        
        var integerPart = Math.floor(f);
        var fractionalPart = f % 1;
        if (fractionalPart == 0)
        {
            return integerPart.toString();
        }
        
        var zeroesInFracPart = -Math.log10(fractionalPart);
        if (Math.floor(zeroesInFracPart) == zeroesInFracPart)
        {
            zeroesInFracPart--;
        }
        else
        {
            zeroesInFracPart = Math.floor(zeroesInFracPart);
        }
        
        fractionalPart = Math.round(fractionalPart * PRECISION);
    
        while (fractionalPart % 10 == 0)
        {
             fractionalPart /= 10;
        }
        
        var zeroes = '';
        
        if (zeroesInFracPart > 0)
        {
            zeroes = Array(zeroesInFracPart + 1).join('0');
        }
        
        return integerPart.toString() + '.' + zeroes + fractionalPart.toString();
    }

    Преобразовать плавающего питуха в строку; сохранить не более precisionDigits цифр после запятой (остальные - округлить).

    gost, 05 Мая 2016

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

    0

    1. 1
    var routers = new (R(views))();

    Чет по другому не придумал как в роутер view передать

    arny, 04 Мая 2016

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

    0

    1. 1
    2. 2
    3. 3
    //- ASAP OR DIE♪
        //   re: ASAP OR DIE♪
        //-   next time, you should die

    mcheguevara2, 04 Мая 2016

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

    +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
    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
    if (aKeqboard[i][j] == 'Пробел') {
                            var sLang = storage.get("language");
                            sContent += '<td width="770" height="78" align="center"><div id="search_btn_' + (id++) + '" class="k_s_' + sLang + ' k_f k_c_b" style="color: transparent;" onclick=\"opacit(' + id + ');\"></div></td>';
                        }
                        else
    
                            if (aKeqboard[i][j] == 'ПробелENG') {
                                var sLang = storage.get("language");
                                sContent += '<td width="703" height="78" align="center"><div id="search_btn_' + (id++) + '" class="k_s_eng_' + sLang + ' k_f k_c_b" style="color: transparent;" onclick=\"opacit_ALE(' + id + ');\"></div></td>';
                            }
                            else
    
                                if (aKeqboard[i][j] == 'Shiftrus' || aKeqboard[i][j] == 'Shiftrusm' || aKeqboard[i][j] == 'Shifteng' || aKeqboard[i][j] == 'Shiftengm')
    
                                    sContent += '<td width="167" height="78" align="center"><div id="search_btn_' + (id++) + '" class="shift_' + sLang + '" style="color: transparent;" onclick=\"opacit(' + id + ');\"></div></td>';
    
                                else
    
                                    if (aKeqboard[i][j] == 'mShiftrus' || aKeqboard[i][j] == 'mShiftrusm' || aKeqboard[i][j] == 'mShifteng' || aKeqboard[i][j] == 'mShiftengm')
    
                                        sContent += '<td width="77" height="78" align="center"><div id="search_btn_' + (id++) + '" class="mshift" style="color: transparent;" onclick=\"opacit(' + id + ');\"></div></td>';
    
                                    else
    
                                        if (aKeqboard[i][j] == 'Eng')
    
                                            sContent += '<td width="123" height="78" align="center"><div id="search_btn_' + (id++) + '" class="eng_button" onclick=\"opacit(' + id + ');\"></div></td>';
    
                                        else
    
                                            if (aKeqboard[i][j] == 'Рус')
    
                                                sContent += '<td width="212" height="78" align="center"><div id="search_btn_' + (id++) + '" class="rus_button" onclick=\"opacit_ALR(' + id + ');\"></div></td>';
    
                                            else
    
                                                if (aKeqboard[i][j] == 'Рус2') {
                                                    if (this._statusEng == true) { sContent += '<td width="167" height="78" align="center"><div id="search_btn_' + (id++) + '" class="rus_button2_eng" onclick=\"opacit_ALABC(' + id + ');\"></div></td>'; }
                                                    else if (this._statusEng == false) { sContent += '<td width="167" height="78" align="center"><div id="search_btn_' + (id++) + '" class="rus_button2" onclick=\"opacit_ALR(' + id + ');\"></div></td>'; }
    
                                                }
    
                                                else
    
                                                    if (aKeqboard[i][j] == '.,?123') {
    
                                                        if (this._statusEng == true) { sContent += '<td width="167" height="78" align="center"><div id="search_btn_' + (id++) + '" class="digit123" onclick=\"opacit_ALDABC(' + id + ');\"></div></td>'; }
                                                        else if (this._statusEng == false) { sContent += '<td width="167" height="78" align="center"><div id="search_btn_' + (id++) + '" class="digit123" onclick=\"opacit_ALD(' + id + ');\"></div></td>'; }
                                                    }
    
                                                    else
    
    
                                                        if (aKeqboard[i][j] == ' ')
                                                            sContent += '<td width="0" height="78" align="center"><div id="search_btn_' + (id++) + '" class="k_s_' + sLang + ' k_f k_c_b" onclick=\"opacit(' + id + ');\" style="display: none;"></div></td>';
    
                                                        else
    
                                                            if (aKeqboard[i][j] == '...')
                                                                sContent += '<td width="75" height="78" align="center"><div id="search_btn_' + (id++) + '" class="k_s_' + sLang + ' k_f k_c_b" onclick=\"opacit(' + id + ');\" style="display: none;"></div></td>';
    
                                                            else
    
                                                                if (aKeqboard[i][j] == 'Стереть') {
                                                                    var sLang = storage.get("language");
                                                                    sContent += '<td width="120" height="78" align="center"><div id="search_btn_' + (id++) + '" class="k_b_' + sLang + ' k_f_del k_c_w" onclick=\"opacit(' + id + ' );\"></div></td>';
                                                                }
                                                                else
    
                                                                    if (aKeqboard[i][j].length > 1) {
                                                                        sContent += '<td width="167" height="70" align="center"><div id="search_btn_' + (id++) + '" class="k_b_green k_f k_c_w" onclick=\"opacit(' + id + ');\"></div></td>';
    
                                                                    }
                                                                    else {
                                                                        sContent += '<td width="80" height="70" align="center"><div id="search_btn_' + (id++) + '" class="k_v k_f k_c_b" onclick=\"opacit(' + id + ');\"></div></td>';
                                                                    }
                    }

    lorines, 29 Апреля 2016

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

    +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
    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
    function captcha_answer (res) {
    	if (res.email == 0) {
    		$('#email').css('border','1px solid #C5C5C5');
    		$(".email").text("");
    		$(".email").hide();
    	}
    	if (res.email == 1) {
    		$('#email').css('border','1px solid red');
    		$(".email").text("E-mail слишком короткий");
    		$(".email").show();
    	}
    	if (res.email == 2) {
    		$('#email').css('border','1px solid red');
    		$(".email").text("E-mail слишком длинный");
    		$(".email").show();
    	}
    	if (res.email == 3) {
    		$('#email').css('border','1px solid red');
    		$(".email").text("Некорректный E-mail");
    		$(".email").show();
    	}
    	if (res.email == 4) {
    		$('#email').css('border','1px solid red');
    		$(".email").text("E-mail занят");
    		$(".email").show();
    	}
    	
    	if (res.nickname == 0) {
    		$('#nickname').css('border','1px solid #C5C5C5');
    		$(".nickname").text("");
    		$(".nickname").hide();
    	}
    	if (res.nickname == 1) {
    		$('#nickname').css('border','1px solid red');
    		$(".nickname").text("Ник слишком короткий");
    		$(".nickname").show();
    	}
    	if (res.nickname == 2) {
    		$('#nickname').css('border','1px solid red');
    		$(".nickname").text("Ник слишком длинный");
    		$(".nickname").show();
    	}
    	if (res.nickname == 3) {
    		$('#nickname').css('border','1px solid red');
    		$(".nickname").text("Ник занят");
    		$(".nickname").show();
    	}
    	
    	if (res.password_1 == 0) {
    		$('#password_1').css('border','1px solid #C5C5C5');
    		$(".password_1").text("");
    		$(".password_1").hide();
    	}
    	if (res.password_1 == 1) {
    		$('#password_1').css('border','1px solid red');
    		$(".password_1").text("Пароль слишком короткий");
    		$(".password_1").show();
    	}
    	if (res.password_1 == 2) {
    		$('#password_1').css('border','1px solid red');
    		$(".password_1").text("Пароль слишком длинный");
    		$(".password_1").show();
    	}
    	
    	if (res.password_2 == 0) {
    		$('#password_2').css('border','1px solid #C5C5C5');
    		$(".password_2").text("");
    		$(".password_2").hide();
    	}
    	if (res.password_2 == 1) {
    		$('#password_2').css('border','1px solid red');
    		$(".password_2").text("");
    		$(".password_2").show();
    	}
    	if (res.password_2 == 2) {
    		$('#password_2').css('border','1px solid red');
    		$(".password_2").text("Пароли не совпадают");
    		$(".password_2").show();
    	}
    };

    Есть скрипт, он аяксом посылает запрос на страницу, скрипт "отвечает" в формате json, ответы типа {"email":"1"} а вот это собственно "расшифровка" ответов :)

    slowpoke59rus, 27 Апреля 2016

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