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

    +155

    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
    const WCT_SYMBOLS = new Buffer('ABCDEFGO'); /*задаём строку для поиска
     в ней символов*/
    const WCT_LENGTH = 3;
    const fs = require('fs');
     
    /*функция для перевода целой части числа из 10-й в любую сс*/
    function Cel(number, c, out, offset, length){
      var pos = offset + length - 1;
    
      number |= 0; /*берём целую часть от числа*/
      
      do {
        out[pos--] = WCT_SYMBOLS[number % c | 0]; /*повторяем пока число не будет равно нулю берём целую часть при
        делении числа на основание и берём остаток + 1 от деления целой части на 16, записываем
        результат посимвольно в строку out*/
        number = number / c | 0;
      } while (number != 0);
      
      while(pos >= offset)
        out[pos--] = WCT_SYMBOLS[0];
    }
    
    (function wctEditor() {
      const argv = process.argv;
      
      if(argv.length < 4) {
        console.log('Not enough parameters!');
        process.exit(1);
      }
      
      const input = argv[2], output = argv[3];
    
      if(!fs.existsSync(input)) {
        console.log('File not exist!');
        process.exit(2);
      }
      
      const BUFFER_SIZE = 1024;
      const f1 = fs.openSync(input, 'r');
      const f2 = fs.openSync(output, 'w');
      const I = new Buffer(BUFFER_SIZE);
      const O = new Buffer(WCT_LENGTH * BUFFER_SIZE);
      
      while(1) {
        var readBytes = fs.readSync(f1, I, 0, I.length, null);
        if(!readBytes) break;
        
        for(var i=0; i<readBytes; ++i)
          Cel(I[0], WCT_SYMBOLS.length, O, i * WCT_LENGTH, WCT_LENGTH);
        
        fs.writeSync(f2, O, 0, readBytes * WCT_LENGTH, null);
      }
    
      fs.closeSync(f1);
      fs.closeSync(f2);
      
    })();
    
      /* TODO -oUser -cConsole Main : Insert code here */

    По следам http://programmersforum.ru/showthread.php?t=264223. Ну тормозит же!
    Я долго боролся с собой, и всё же от авторского стиля остались только комментарии и имена f1, f2 и I...
    WCT editor: теперь и под Node.

    1024--, 16 Августа 2014

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

    +154

    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
    //Показывать или убирать шапку
        var shapka = $('.shapka');
        $(window).scroll(function(){
            if($(window).scrollTop() > 800){
                shapka.fadeIn();
            } else {
                shapka.fadeOut();
            }
        });
    
    
        //Scrolling up function
        $(function(){
            $.fn.scrollToTop = function(){$(this).hide().removeAttr("href");
            if($(window).scrollTop()!="0"){
                $(this).fadeIn("slow")
            }
            var scrollDiv=$(this);$(window).scroll(function(){
                if($(window).scrollTop()=="0"){
                    $(scrollDiv).fadeOut("slow")
                }
                    else{
                        $(scrollDiv).fadeIn("slow")
                    }
                });
            $(this).click(function(){$("html, body").animate({scrollTop:0},"slow")})}
        });
    
        $(function() {     
                $("#toTop").scrollToTop();  
        }); 
    
        //Динамическое изменения title страницы
        function dynamicTitle(d){
            var t = new Array(
                    "Курс 'Основы программирования'",
                    "Внимание! Сегодня скидка!"
                );
    
            if(typeof d === 'number'){
                document.title = t[d];
            } else {
                for(var i=0; i<t.length; i++){
                    if(t[i] === document.title){
                        continue;
                    } else {
                        document.title = t[i];
                        break;
                    }
                }
            }
        }
        dynamicTitle(0);
        setInterval(dynamicTitle, 2000);

    http://progbasics.ru

    Советую почитать весь сайт и код, такого эпичного говнеца я еще не видел. Особенно в отзывах и программе курса.

    gost, 16 Августа 2014

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

    +152

    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
    app.service('CarService', function () {
        this.dealer = "Bad";
        this.numCylinder = 4;
    });
    app.factory('CarFactory', function () {
        return function (numCylinder) {
            this.dealer = "Bad";
            this.numCylinder = numCylinder
        };
    });
    app.provider('CarProvider', function () {
        this.dealerName = 'Bad';
        this.$get = function () {
            return function (numCylinder) {
                this.numCylinder = numCylinder;
                this.dealer = this.dealerName;
            }
        };
        this.setDealerName = function (str) {
            this.dealerName = str;
        }
    });

    http://habrahabr.ru/post/220631/

    gost, 15 Августа 2014

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

    +156

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    var day = new Date(values.date_b.substring(0, 10));
                var days = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
                var curDay = day.getDay();
                for(var i = 0; i < days.length; i++) {
                    if (days[i] == days[ day.getDay() ]) {
                        curDay = i;
                        break;
                    }
                }
                curDay = (curDay == 0) ? 7 : curDay;

    dr_Lev, 15 Августа 2014

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

    +159

    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
    недавно на хабре была статья "Платформер на Three.js"
    
    так вот автор уверяет, что
    "Читателям с нешкольным образованием или ветеранам игростроя этот псевдокод известен под названием «метод Эйлера», а также известно что этот метод — просто отстой."
    и приводит картинки из википедии, где им решают достаточно сложный дифур
    а вот свой "школьный" дифур он решил вот так
    
    if( в воздухе ) playerVelocity.y -= gravity * time;
    playerPosition += playerVelocity * time;
    
    "Как видим, запустив игру в firefox, мы получим одну динамику, а запустив её в chrome — совершенно иную. Поведение персонажа будет «плавать» в зависимости от интенсивности фоновых задач и расположения звёзд. Что же делать?"
    ответ-учиться программировать
    
    void update(float dt) {
    	pos += (velocity + force * dt * 0.5f) * dt;
    	velocity += force * dt;
    }
    
    оп-ля! все встало на свои места. теперь эйлер с  не фиксированным шагом НЕ ПЛАВАЕТ!

    FadeToBlack, 15 Августа 2014

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

    +149

    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
    (function(G, U) {
        "use strict";
        var $ = G.jQuery,
            string = "string",
            number = "number",
            bool   = "boolean",
            object = "object";
    
        function hasStr(obj, prop) {
            return obj.hasOwnProperty(prop) && typeof obj[prop] === string;
        }
    
        function hasNum(obj, prop) {
            return obj.hasOwnProperty(prop) && typeof obj[prop] === number;
        }
    
        function hasArr(obj, prop) {
            return obj.hasOwnProperty(prop) && $.isArray(obj[prop]);
        }
    
        function hasFn(obj, prop) {
            return obj.hasOwnProperty(prop) && $.isFunction(obj[prop]);
        }
    
        function hasBool(obj, prop) {
            return obj.hasOwnProperty(prop) && typeof obj[prop] === bool;
        }
    
        function copyProps(source, target, fields) {
            var i,
                count,
                fieldType,
                fieldTypes = {
                    str : hasStr,
                    bool: hasBool,
                    arr : hasArr,
                    fn  : hasFn,
                    num : hasNum
                };
                
            if (arguments.length < 2){
                return;
            }
            
            if (arguments.length === 2){
                target = {};
            }
    
            if ($.isPlainObject(source) && $.isPlainObject(target) && $.isPlainObject(fields)) {
                for (fieldType in fieldTypes) {
                    if (fieldTypes.hasOwnProperty(fieldType)) {
                        if (hasArr(fields, fieldType)) {
                            for (i = 0, count = fields[fieldType].length; i < count; i += 1) {
                                if (fieldTypes[fieldType](source, fields[fieldType][i])) {
                                    target[fields[fieldType][i]] = source[fields[fieldType][i]];
                                }
                            }
                        }
                    }
                }
            }
            return target;
        }
    
        G.copyProps = copyProps; //Export into global namespace
    }(this, undefined));

    Здравствуйте! Написал функцию, которая безопасно копирует свойства из одного объекта в другой, выполняя проверку типа каждого копируемого поля. Скажите, какие недостатки и насколько оправдано её применение по сравнению со стандартной функцией jQuery extend()? Работает только с простыми объектами, для вложенных объектов нужно ещё раз вызывать эту функцию.

    dunmaksim, 14 Августа 2014

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

    +159

    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
    81. 81
    var get_day = function(day_name_or_number, return_type) {
    
            var day_name = '';
            var day_number = '';
    
            switch (day_name_or_number) {
                case 0: //sunday
                case 'sun':
                case 'sunday':
    
                    day_name = 'sun';
                    day_number = 0;
                    break;
    
                case 1: //monday
                case 'mon':
                case 'monday':
    
                    day_name = 'mon';
                    day_number = 1;
                    break;
    
                case 2: //tuesday
                case 'tue':
                case 'tuesday':
    
                    day_name = 'tue';
                    day_number = 2;
                    break;
    
                case 3: //wednesday
                case 'wed':
                case 'wednesday':
    
                    day_name = 'wed';
                    day_number = 3;
                    break;
    
                case 4: //thursday
                case 'thu':
                case 'thursday':
    
                    day_name = 'thu';
                    day_number = 4;
                    break;
    
                case 5: //friday
                case 'fri':
                case 'friday':
    
                    day_name = 'fri';
                    day_number = 5;
                    break;
    
                case 6: //saturday
                case 'sat':
                case 'saturday':
    
                    day_name = 'sat';
                    day_number = 6;
                    break;
            }
    
    
            switch (return_type) {
                case 'number':
    
                    return day_number;
                    break;
    
                case 'name':
    
                    return day_name;
                    break;
    
                default:
    
                    return day_name;
                    break;
            }
        };

    Что и кому я сделал, что с таким работать приходиться?

    monstrodev, 08 Августа 2014

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

    +159

    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
    function get_recaptcha(id)
        {
            var id;
            if(id==1)
            {
                $.ajax({
                    type: "POST",
            		url: "classes/get_captcha.php",
            		cache: false,
                    data: "recaptcha=1",
            		success: function(html)
                    {
                        $('#captcha_reg').html(html);
                    }
               });
            }
            else if (id==2)
            {
                $.ajax({
                    type: "POST",
            		url: "classes/get_captcha.php",
            		cache: false,
                    data: "recaptcha=1",
            		success: function(html)
                    {
                        $('#captcha_forget').html(html);
                    }
               });
            }
        }

    История одного проекта.. Часть 3

    reilag, 07 Августа 2014

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

    +159

    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
    $timeout(function(){
                    $rootScope.presentation_details = { 
                        "name" : $rootScope.presentationDetails.name,
                        "description" : $rootScope.presentationDetails.description,
                        "lastUpdatedView" : $rootScope.presentationDetails.lastUpdatedView,
                        "projectId" : $rootScope.presentationDetails.projectId,
                        "presentationId" : $rootScope.presentationDetails.presentationId,
                        "reimbursementRate" : $rootScope.presentationDetails.reimbursementRate,
                        "isTemplate" : $rootScope.presentationDetails.isTemplate,
                        "authorId" : $rootScope.presentationDetails.authorId,
                        "authorName" : $rootScope.presentationDetails.authorName,
                        "IsNewPresentation" : false,
                        "gDocsId" : $rootScope.presentationDetails.gDocsId,
                        "parameters" : {
                          "widgetURL" : $rootScope.presentationDetails.parameters.widgetURL,
                          "widgetIFrameUrl" : $rootScope.presentationDetails.parameters.widgetIFrameUrl,
                          "widgetTextareaContent": $rootScope.presentationDetails.parameters.widgetTextareaContent,
                          "widgetTotalEGinGasSaved" : $rootScope.presentationDetails.parameters.widgetTotalEGinGasSaved,
                          "widgetTotalEGinFewerVehicles" : $rootScope.presentationDetails.parameters.widgetTotalEGinFewerVehicles,
                          "widgetHowDoesSolarWorkStepFourDuration" : $rootScope.presentationDetails.parameters.widgetHowDoesSolarWorkStepFourDuration,
                          "widgetHowDoesSolarWorkOverallDuration" : $rootScope.presentationDetails.parameters.widgetHowDoesSolarWorkOverallDuration,
                          "widgetGraphWeather" : $rootScope.presentationDetails.parameters.widgetGraphWeather,
                          "wIdgetGraphTemperatureChartType" : $rootScope.presentationDetails.parameters.wIdgetGraphTemperatureChartType,
                          "widgetGraphTemperature" : $rootScope.presentationDetails.parameters.widgetGraphTemperature,                  
                          "widgetWeatherType" : $rootScope.presentationDetails.parameters.widgetWeatherType,
                          "transitionOut" : $rootScope.presentationDetails.parameters.transitionOut,
                          "transitionIn" : $rootScope.presentationDetails.parameters.transitionIn,
                          "parametersId" : $rootScope.presentationDetails.parameters.parametersId,
                          "subheaderFont" : {
                            "fontId" : $rootScope.presentationDetails.parameters.subheaderFont.fontId,
                            "size" : $rootScope.presentationDetails.parameters.subheaderFont.size,
                            "name" : $rootScope.presentationDetails.parameters.subheaderFont.name,
                            "color" : $rootScope.presentationDetails.parameters.subheaderFont.color,
                            "visible" : $rootScope.presentationDetails.parameters.subheaderFont.visible,
                            "label" : $rootScope.presentationDetails.parameters.subheaderFont.label,
                            "content" : $rootScope.presentationDetails.parameters.subheaderFont.content,
                          },
                          "normal2Font" : {
                            "fontId" : $rootScope.presentationDetails.parameters.normal2Font.fontId,
                            "size" : $rootScope.presentationDetails.parameters.normal2Font.size,
                            "name" : $rootScope.presentationDetails.parameters.normal2Font.name,
                            "color" : $rootScope.presentationDetails.parameters.normal2Font.color,
                            "visible" : $rootScope.presentationDetails.parameters.normal2Font.visible,
                            "label" : $rootScope.presentationDetails.parameters.normal2Font.label,
                          },
                          "backgroundImage" : $rootScope.presentationDetails.parameters.backgroundImage,
                          "backgroundImageVisible" : $rootScope.presentationDetails.parameters.backgroundImageVisible,
                          "backgroundImageLabel" : $rootScope.presentationDetails.parameters.backgroundImageLabel,
                          "backgroundColor" : $rootScope.presentationDetails.parameters.backgroundColor,
                          "backgroundColorVisible" : $rootScope.presentationDetails.parameters.backgroundColorVisible,
                          "backgroundColorLabel" : $rootScope.presentationDetails.parameters.backgroundColorLabel,
                          "widgetIndex" : $rootScope.presentationDetails.parameters.widgetIndex,
                          "rowPosition" : $rootScope.presentationDetails.parameters.rowPosition,
                          "colPosition" : $rootScope.presentationDetails.parameters.colPosition,
                          "rowCount" : $rootScope.presentationDetails.parameters.rowCount,
                          "colCount" : $rootScope.presentationDetails.parameters.colCount,
                          "duration" : $rootScope.presentationDetails.parameters.duration,
                          "startDate" : $rootScope.presentationDetails.parameters.startDate,
                          "endDate" : $rootScope.presentationDetails.parameters.endDate,
                        },
                    };
                }, 10);

    Заглянул в код текущего проекта... Зря тимлид не проводит кодревью... У кого есть идеи нахеряки?

    jenezis, 06 Августа 2014

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

    +163

    1. 1
    2. 2
    3. 3
    4. 4
    if( window == top ){
    	document.cookie = "st=0; path=/; expires=100";
    	window.location = window.location;
    }

    sa-kirich, 05 Августа 2014

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