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

    +153

    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
    function Recalc(index) {
                var url = window.location.pathname + "?";
                var data = "DepartureDate=" + $("#AvailabilityList_" + index + "__DepartureDate").val()
    				 + "&DepartureTime=" + $("#AvailabilityList_" + index + "__DepartureTime").val()
                + "&ArrivalDate=" + $("#AvailabilityList_" + index + "__ArrivalDate").val()
                + "&ArrivalTime=" + $("#AvailabilityList_" + index + "__ArrivalTime").val()
                + "&FromCode=" + $("#AvailabilityList_" + index + "__FromCode").val()
                + "&ToCode=" + $("#AvailabilityList_" + index + "__ToCode").val()
                + "&ShipCode=" + $("#AvailabilityList_" + index + "__ShipCode").val()
                + "&ProviderCode=" + $("#AvailabilityList_" + index + "__ProviderCode").val()
                + "&Duration=" + $("#AvailabilityList_" + index + "__Duration").val()
                + "&AdultCount=" + $("#AvailabilityList_" + index + "__AdultCount").val()
                + "&ChildCount=" + $("#AvailabilityList_" + index + "__ChildCount").val()
                + "&FerryID=" + $("#AvailabilityList_" + index + "__FerryID").val()
                + "&Auto=" + $("#AvailabilityList_" + index + "__Auto").val()
                + "&FareCode=" + $("#AvailabilityList_" + index + "__FareCode").val()
                + "&Years[0]=" + $("#AvailabilityList_" + index + "__Years_0_").val()
                + "&Years[1]=" + $("#AvailabilityList_" + index + "__Years_1_").val()
                + "&Years[2]=" + $("#AvailabilityList_" + index + "__Years_2_").val()
                + "&Years[3]=" + $("#AvailabilityList_" + index + "__Years_3_").val()
                + "&Years[4]=" + $("#AvailabilityList_" + index + "__Years_4_").val()
                + "&Years[5]=" + $("#AvailabilityList_" + index + "__Years_5_").val()
                + "&Years[6]=" + $("#AvailabilityList_" + index + "__Years_6_").val()
                + "&Years[7]=" + $("#AvailabilityList_" + index + "__Years_7_").val()
                + "&Years[8]=" + $("#AvailabilityList_" + index + "__Years_8_").val()
                + "&Index=" + index;
                return data;
            }

    Back-end asp.net mvc, кому интересно

    sladkijBubaleh, 16 Октября 2013

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

    +151

    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
    function recalcMeal() {
                jQuery('.recalc2').bind("click", function () {
                    pusto = '';
                    jQuery.each(jQuery('.vuborka input'), function (index) {
                        var allInputValueMeal = parseInt(jQuery(this).val());
                        if (allInputValueMeal != 0 && $.browser.msie) {
                            for (var i = 0; i < allInputValueMeal; i++) {
                                pusto = pusto + jQuery(this).parent().parent().parent().next().find('.boxtypecode').val() + ';';
                            }
                        }
                        else if (allInputValueMeal != 0 && !($.browser.msie)) {
                            for (var i = 0; i < allInputValueMeal; i++) {
                                pusto = pusto + jQuery(this).parent().parent().parent().next().val() + ';';
                            }
                        }
                    });
    
                    jQuery('.selectedcabins').val(pusto);
                });
            }

    Код который я поддерживаю от старого работника.

    sladkijBubaleh, 16 Октября 2013

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

    +134

    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
    private void FormBackUpFlash_Load(object sender, EventArgs e)
      {
       DriveInfo[] allDrives = DriveInfo.GetDrives();
       foreach (DriveInfo d in allDrives)
       {
        if (d.DriveType == DriveType.Removable)
        {
         bool thisIsDisketa = false;
         if (d.Name.Contains("A:")) thisIsDisketa = true;
         if (d.Name.Contains("B:")) thisIsDisketa = true;
    
         if (thisIsDisketa)
          continue;
         else
          listBoxDevice.Items.Add(d);
        }
       }
       if (listBoxDevice.Items.Count > 0)
       {
        StatusLabel.ForeColor = Color.Blue;
        StatusLabel.Text = "Готово!";
        listBoxDevice.SelectedIndex = 0;
       }
       else
       {
        buttonWrite.Enabled = false;
        StatusLabel.ForeColor = Color.Red;
        StatusLabel.Text = "Подходящих устройств нет!";
       }
      }
    
      private void buttonWrite_Click(object sender, EventArgs e)
      {
       try
       {
        DriveInfo drv = (DriveInfo)listBoxDevice.SelectedItem;
        pathDst = Path.Combine(drv.Name, "PROJECTNAME_Backup");
        if (!Directory.Exists(Path.Combine(drv.Name, "PROJECTNAME_Backup")))
        {
         Directory.CreateDirectory(pathDst);
        }
        this.Cursor = Cursors.WaitCursor;
        DBMSSQL dbm = new DBMSSQL();
        int i;
        for (i = 0; i < 10; i++)
        {
         if (dbm.BackupDB(Path.Combine(Path.Combine(drv.Name, "PROJECTNAME_Backup"), "DataPROJECTNAMEDataContext.bak"), true))
         {
          MessageBox.Show("Резервная копия создана успешно!", "OK!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
          break;
         }
         Thread.Sleep(1000);
        }
        if (i == 10)
        {
         MessageBox.Show("Ошибка при создании резервной копии!!!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
       }
       catch (Exception e1)
       {
        MessageBox.Show(e1.Message + "\r\nЭкспорт отменен!");
        this.DialogResult = DialogResult.Cancel;
       }
       finally { this.Cursor = Cursors.Default; }
      }
    
      private void listBoxDevice_SelectedIndexChanged(object sender, EventArgs e)
      {
       try
       {
        DriveInfo drv = (DriveInfo)listBoxDevice.SelectedItem;
        labelSizeDevice.Text = drv.AvailableFreeSpace < 1000000000 ?
            string.Format("{0}MB", drv.AvailableFreeSpace / 1000000) :
            string.Format("{0:F2}GB", (float)drv.AvailableFreeSpace / 1000000000.0);
       }
       catch (Exception e1)
       {
        MessageBox.Show(e1.Message);
       }
      }

    Три в одном.
    Исключаем флоппи из списка дисков, 10 раз пытаемся создать бэкап и 1000000 байт в мегабайте.

    just_nameless, 15 Октября 2013

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

    +8

    1. 1
    2. 2
    3. 3
    QRegExp re("<cite>‎(.*)</cite>");
    re.setMinimal(true);
    qDebug() << re.indexIn("<cite>http://test.com/</cite>");

    Ошибка, на фикс которой мы с другом убили почти час.

    bormand, 15 Октября 2013

    Комментарии (76)
  5. 1C / Говнокод #13951

    −167

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    Попытка
    	ДокументВозврата.Записать(РежимЗаписиДокумента.Проведение,РежимПроведенияДокумента.Неоперативный);
    Исключение
    	Попытка
    		ДокументВозврата.Записать(РежимЗаписиДокумента.Проведение,РежимПроведенияДокумента.Неоперативный);
    	Исключение
    		Сообщить("Не удалось записать/провести документ возврата в ИБ " + ДокументВозврата, СтатусСообщения.ОченьВажное);
    	КонецПопытки;
    	ДокументВозврата.Записать(РежимЗаписиДокумента.Запись);
    КонецПопытки;

    Что делать, если не получилось провести документ? Правильно! Попробовать еще раз!
    А потом еще и записать.
    Для надежности.

    zfilin, 15 Октября 2013

    Комментарии (22)
  6. PHP / Говнокод #13950

    +145

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    $packages = array(
        1 => array(
            1 => 'HTML_AJAX',
            2 => 'HTML_Common2',
            3 => 'HTML_QuickForm2'
        ),
        2 => array(
            1 => 'HTTP_Download',
            2 => 'HTTP_Request2'
        )
    );

    Ребята пошли против системы

    kindofbear, 15 Октября 2013

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

    +131

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    private unsafe bool IsOptionalOutParamSet(out Guid param)
    {
        fixed (Guid* guidPtr = &param)
            return (IntPtr) guidPtr != IntPtr.Zero;
    }

    Ccik, 15 Октября 2013

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

    +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
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    int DataBase::garbageCollector(string filename){ 
        fstream from(filename.c_str());
        fstream from0((filename+".index").c_str());
        Index x;
        Data d;
        char *a/*,*b*/;
        int oldpos = 0 ;
        bool done = false;
        from.seekg(0,ios::end);
        int dbend = static_cast<int>(from.tellp());
        from0.seekg(0,ios::end);
        int indexend = static_cast<int>(from0.tellp());
        if(dbend == BlockSize || indexend == IndexSize){
    	from.close();
    	from0.close();
    	return 0;
        }
        from.seekg(0,ios::beg);
        from0.seekg(0,ios::beg);
        while(true){ 
            from0 >> x;
            if(from0.eof())break;
            if(!x.Num()){ 
                int count = dbend - x.Pointer() - BlockSize;
                int count0 = indexend - (static_cast<int>(from0.tellp())+1);
                from.seekg(x.Pointer()+BlockSize);
                a = new char[count]; 
                from.read(a,count);
                from.seekp(x.Pointer());
                from.write(a,count);
                delete a;
                a = new char[count0];
                from0.seekp(1,ios::cur);
                int test = from0.tellp();
                from0.read(a,count0);
                from0.clear();
                from0.seekp(indexend - count0 - IndexSize,ios::beg);
                test = from0.tellp();
                from0.write(a,count0);
                test = from0.tellp();
                delete a;
                ofstream to("tmp.base",ios::trunc),to0("tmp.index",ios::trunc);
                a = new char[dbend - BlockSize];
                from.seekg(0,ios::beg);
                from.read(a,dbend - BlockSize);
                to.write(a,dbend - BlockSize);
                delete a;
                a = new char[indexend - IndexSize];
                from0.seekg(0,ios::beg);
                test = from0.tellp();
                from0.read(a,indexend - IndexSize);
                to0.write(a,indexend - IndexSize);
                delete a;
                from.close();
                from0.close();
                if(remove(filename.c_str()) || rename("tmp.base",filename.c_str())) return -1;
                if(remove((filename+".index").c_str()) || rename("tmp.index",(filename+".index").c_str())) return -1;
                oldpos = indexend - count0 - IndexSize;
                done = true;
                break;
            }
        }
        if(done){
            from0.open((filename+".index").c_str());
            while(true){ 
                from0 >> x;
                if(from0.eof())break;
                if(x.Pointer() > static_cast<unsigned>((oldpos/23)*BlockSize) ){ 
                    x.Pointer(x.Pointer()-BlockSize);
                    from0.seekp(-(IndexSize-1),ios::cur);
                    from0 << x;
                    int test = from0.tellp();
                }
                else{ 
                    from0.seekp(-(IndexSize-1),ios::cur);
                    from0 << x;
                    int test = from0.tellp();
                    from0.clear();
                }
            }
        }
        return 0;
    }

    Собираем пустые блоки

    Abbath, 15 Октября 2013

    Комментарии (14)
  9. C++ / Говнокод #13947

    +6

    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
    int DataBase::split(fstream& from,fstream& from0,unsigned int p){
        int pos0 = static_cast<int>(from.tellp());
        char *a,*b;
        Data d,d0;
        Index x,x0;
        from.clear();
        from.seekp(0,ios::end);
        int PosEnd = static_cast<int>(from.tellp());
        PosEnd -=static_cast<int>(p);
        a = new char[PosEnd];
        from.seekp(p,ios::beg);
        from.read(a,PosEnd); 
        from.seekp(p+BlockSize,ios::beg);
        from.write(a,PosEnd); 
        from.seekp(p+BlockSize,ios::beg);
        b = a+5*RecordSize;
        from.write(b,RecordSize*5);
        for (int i = 0; i < 5; ++i){ 
            from << d;
        }
        from.seekp(p+RecordSize*5,ios::beg);
        for (int i = 0; i < 5; ++i){ 
            from << d;
        }
        from.seekg(p+RecordSize*4);
        from >> d;
        int newmax = d.Id(); 
        from0.seekp(0,ios::end);
        int indexend =static_cast<int>(from0.tellp());
        from0.seekg(0,ios::beg);
        while(true){ 
            from0 >> x;
            if(from0.eof())break;
            if(x.Pointer() == p){ 
                int oldpos = static_cast<int>(from0.tellp());
                oldpos++;
                int count = indexend - oldpos;
                char *c = new char[count];
                from0.seekg(1,ios::cur);
                from0.read(c,count);
                from0.seekp(oldpos,ios::beg);
                x0.Max(x.Max()); 
                x0.Num(5);
                x0.Pointer(p + BlockSize);
                from0 << x0;
                from0.write(c,count);
                from0.seekp(oldpos - IndexSize,ios::beg);
                x.Max(newmax); 
                x.Num(5);
                from0 << x;
                delete c;
                from.clear();
                from0.seekp(0,ios::beg);
                break;
            }
        }
        from.clear();
        bool first = false;
        while(true){ 
            from0 >> x;
            if(from0.eof())break;
            if(x.Pointer() > p ){
                if(!first){ 
                    from0.seekp(-(IndexSize-1),ios::cur);
                    from0 << x;
                    int test = from0.tellp();
                    from0.clear();
                    first = true;
                    continue;
                }
                x.Pointer(x.Pointer()+BlockSize);
                from0.seekp(-(IndexSize-1),ios::cur);
                from0 << x;
                int test = from0.tellp();
            }
            else{ 
                from0.seekp(-(IndexSize-1),ios::cur);
                from0 << x;
                int test = from0.tellp();
                from0.clear();
            }
        }
        from.clear();
        from.seekp(pos0);
        delete a;
        //delete b;
        return 0;
    }

    Нарезаем

    Abbath, 15 Октября 2013

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

    +81

    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
    public boolean hasNext() {
            if (vectorIndex  == vector.size()) 
                return false;
            return true;
        }
        
        public Object next() {
            try {
                return new Double(vector.getElement(vectorIndex));
            }
            catch(OutOfBoundsException e) {
                throw new RuntimeException(e);
            }
            finally {
                vectorIndex++ ;
            }
        }

    Такой вот итератор у начинающего жавера...

    d3m0n1c, 14 Октября 2013

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