1. C++ / Говнокод #16556

    +57

    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
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    #include "TrayIcon.h"
    
    // ----------------------------------------------------------------------------
    
    TrayIcon::TrayIcon(QObject* parent) : QSystemTrayIcon(parent),
                                          INTERVAL(1000),
                                          WIDTH_ICON(30), HEIGHT_ICON(30)
    {
        currentDate = QDate(0, 0, 0);
    
        defaultIcon = QPixmap(WIDTH_ICON, HEIGHT_ICON);
        defaultIcon.fill(Qt::black);
    
        reminderIcon = QPixmap(WIDTH_ICON, HEIGHT_ICON);
        reminderIcon.fill(Qt::yellow);
    
        thousandthDayIcon = QPixmap(WIDTH_ICON, HEIGHT_ICON);
        thousandthDayIcon.fill(Qt::green);
    
        dialogBoxIsActive = false;
    
        readSettings();
    
        wasReminder = false;
        wasCongratulation = false;
        wasSetNewDate = false;
    
        slotUpdateDate();
    
        QMenu* contextMenu = new QMenu;
    
        contextMenu->addAction("Set date of birth...",
                                                 this, SLOT(slotSetDateOfBirth()));
    
        QAction* autorunAction = contextMenu->addAction("Autorun",
                                                 this, SLOT(slotSetAutorun(bool)));
        autorunAction->setCheckable(true);
        autorunAction->setChecked(autorun);
    
        contextMenu->addSeparator();
    
        contextMenu->addAction("About...", this, SLOT(slotAboutMyProgram()));
    
        contextMenu->addSeparator();
    
        contextMenu->addAction("Quit", qApp, SLOT(quit()));
    
        setContextMenu(contextMenu);
    
        QTimer* timer = new QTimer(this);
        connect(timer, SIGNAL(timeout()), SLOT(slotUpdateDate()));
        timer->start(500);
    }
    
    // ----------------------------------------------------------------------------
    
    void TrayIcon::slotUpdateDate()
    {
        if((currentDate != QDate::currentDate()) || wasSetNewDate)
        {
            currentDate = QDate::currentDate();
    
            daysToThousandthDay
                           = INTERVAL - dateOfBirth.daysTo(currentDate) % INTERVAL;
    
            wasCongratulation = false;
            wasReminder = false;
            wasSetNewDate = false;
    
            if((daysToThousandthDay != INTERVAL) && (daysToThousandthDay != 1))
            {
                setIcon(QIcon(defaultIcon));
                setToolTip("Until next thousandth day in " +
                                 QString().number(daysToThousandthDay) + " days.");
            }
            else
            {
                if(daysToThousandthDay == 1)
                {
                    if(!wasReminder)
                        reminderBeforeDay();
                }
                else
                {
                    if(!wasCongratulation)
                        congratulation();
                }
            }
        }
    }

    Описание конструктора и одного из методов класса иконки в системном трее из программы, которая должна оповещать пользователя о каждом тысячном дне его жизни. Написано на Qt.

    Полная версия:

    main: http://pastebin.com/DEKiMWdb

    хедер класса иконки трея: http://pastebin.com/rN9NwBPB
    .cpp класса иконки трея: http://pastebin.com/uuyf5uxX

    хедер класса окна ввода даты рождения: http://pastebin.com/bmfAbFwg
    .cpp класса окна ввода даты рождения: http://pastebin.com/3R8BaPFC

    darkKnight, 18 Августа 2014

    Комментарии (19)
  2. Java / Говнокод #16555

    +118

    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
    if (operator instanceof TUOperatorStacker) {
    	dump.put("operator_type", "TUOperatorStacker");
    } else if (operator instanceof TUOperatorDestacker) {
    	dump.put("operator_type", "TUOperatorDestacker");
    } else if (operator instanceof TUOperatorTargetedStacker) {
    	dump.put("operator_type", "TUOperatorTargetedStacker");
    } else if (operator instanceof TUOperatorTargetedDestacker) {
    	dump.put("operator_type", "TUOperatorTargetedDestacker");
    }
    
    
    
    <...>
    
    
    
    String typeString = (String) dump.get("operator_type");
    TUOperator operator = null;
    
    if (typeString.equals("TUOperatorStacker")) {
    	operator = new TUOperatorStacker(simElement);
    } else if (typeString.equals("TUOperatorDestacker")) {
    	operator = new TUOperatorDestacker(simElement);
    } else if (typeString.equals("TUOperatorTargetedStacker")) {
    	operator = new TUOperatorTargetedStacker(simElement);
    } else if (typeString.equals("TUOperatorTargetedDestacker")) {
    	operator = new TUOperatorTargetedDestacker(simElement);
    }

    someone, 18 Августа 2014

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

    +154

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    if (d_min < 0) {
                                // push out by normal * |d_min|
                                x = x - d_min * T[t_min];
                                y = y - d_min * T[t_min + 1];
                                y = z - d_min * T[t_min + 2];

    Сука, блядь, пиздец, два часа убил.

    makc3d, 18 Августа 2014

    Комментарии (13)
  4. Java / Говнокод #16553

    +70

    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
    *  Calculates the minimum number of bits necessary to represent the given number.  The
         *      number should be given in its unsigned form with the starting bits equal to 1 if it is
         *      signed.  Repeatedly compares number to another unsigned int called x.
         *      x is initialized to 1.  The value of x is shifted left i times until x is greater
         *      than number.  Now i is equal to the number of bits the UNSIGNED value of number needs.
         *      The signed value will need one more bit for the sign so i+1 is returned if the number
         *      is signed, and i is returned if the number is unsigned.
     * @param number the number to compute the size of
     * @param bits 1 if number is signed, 0 if unsigned
     */
        public static int minBits(int number, int bits)
        {
        int val = 1;
        for (int x = 1; val <= number && !(bits > 32); x <<= 1) 
        {
            val = val | x;
            bits++;
        }
    
        if (bits > 32)
                {
                        assert false : ("minBits " + bits + " must not exceed 32");
                }
        return bits;
    }

    Адоб, как обычно, порадовал (условие окончания цикла).
    [color=blue]https://git-wip-us.apache.org/repos/asf/flex-sdk/repo?p=flex-sdk.git;a=blob;f=modules/swfutils/src/java/flash/swf/SwfEncoder.java;h=03a100dda92989d537b00b 96033d614c73c47801;hb=HEAD#l320[/code]

    wvxvw, 17 Августа 2014

    Комментарии (8)
  5. C++ / Говнокод #16552

    +63

    1. 1
    renderer->SetBackground(.0, .0, .0); // Background color green

    Abbath, 16 Августа 2014

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

    +124

    1. 1
    2. 2
    quicksort [] = []
    quicksort (h:t) = (quicksort(filter (=h) t))

    quicksort на хаскель. лаба. масло. 2014

    kegdan, 16 Августа 2014

    Комментарии (39)
  7. PHP / Говнокод #16550

    +153

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    public function indexAction()
        {
            if (Zend_Auth::getInstance()->hasIdentity()) {
                Zend_Auth::getInstance()->getIdentity();
            }
        }

    __proto__, 16 Августа 2014

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

    +128

    1. 1
    2. 2
    isParallel :: Integer -> Integer -> Integer -> Integer -> Integer -> Integer -> Integer -> Integer -> Bool
    isParallel x1 y1 x2 y2 x3 y3 x4 y4 = if (((x1-x2)*(y3-y4)-(y1-y2)*(x3-x4)) == 0) then True else False

    лаба по хаски
    параллельны ли 2 прямые?

    kegdan, 16 Августа 2014

    Комментарии (143)
  9. 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)
  10. 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)