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

    +1001

    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
    Matrix Matrix::inverse ()
    {
    	Matrix Temp;
    
    
    	Matrix A;
    
    	Matrix AL(4,4);
    
    	int c1,c2;
    
    
    
    	for (int i = 0; i < 5; i++)
    	for (int j = 0; j < 5; j++)
    	{
    		c1 = 0;
    
    		for (int k = 0; k < 5; k++)
    		{
    			if (k == i) continue;
    			c2 = 0;
    			for (int l = 0; l < 5; l++)
    			{
    				if (l == j) continue;
    				AL[c1][c2] = array[k][l];
    				c2++;
    			}
    			c1++;
    		}
    
    		A[i][j] = pow(-1,static_cast<double>(i + j + 2))*AL.determinant();
    	}
    	
    	for (int i = 0; i < 5; i++)
    	for (int j = 0; j < 5; j++)
    	{
    		Temp[i][j] = 1/determinant()*A[i][j];
    	}
    
    
    	return Temp;
    }

    цените, алгоритм обратной матрицы

    bartimeus33nt10, 11 Ноября 2011

    Комментарии (124)
  2. Python / Говнокод #8476

    −92

    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
    #! /usr/bin/python3.1
    import tarfile, os, datetime, time
    tudate = datetime.datetime.now()
    tud_date = list(tudate.timetuple())
    day = tud_date[2]; month = tud_date[1]; year = tud_date[0]; dyear = tud_date[7]
    tar_pwd = '/home/fess/Desktop/Server/arch/%d.%d.%d.tar.gz' % (day,month,year)
    pwd_bases = '/home/fess/Desktop/Server/arch'; archives = os.listdir(pwd_bases) # получаем список всех файлов в дирректории
    os.chdir(pwd_bases) # move arround the directory with the bases
    if os.path.exists(tar_pwd): pass # если архив с именем сегоднешней даты есть в папке, то ничего не делает
    else: # в противном случае создает архив            
            tar = tarfile.open(tar_pwd,'w:gz')
            tar.add('/home/fess/Desktop/Server/base/','bases')
            tar.close()
    for archive in archives: # Проверка каждого архива в папке с архивами
            stf = os.stat(archive); dayy = time.localtime(stf.st_mtime).tm_yday; m = dyear-dayy # узнаем дату создания арх и узнаем сколько ему дней (m)
            if m >= 50: # если архиву больше или 50 дней
                    os.remove(archive); print(archive,'was removed')# тогда удаляем архив которому больше 50 дней 
            if dyear < dayy: # Если сегодняшний день меньше чем дата создания файла(т.е. наступил новый год)
                    os.remove(archive); print(archive,'was removed')# удалить 49 оставшихся архивов с прошлого года

    зачетная катяшенция по моему вышла, бэкапчеГ ;)

    fess, 10 Ноября 2011

    Комментарии (16)
  3. Си / Говнокод #8475

    +139

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    for ( i = 0; i <= n; i++ )
    {
    
        k = 0;
    
        for ( j = ( 2 * n - i - 1 ); k == 0; k++ )
        {
            a1 = a1 & ~ ( 1 << ( j ) );
            a1 = a1 | ( ( ( a1 >> ( i ) ) & 1 ) << ( j ) );
        };
    }

    по условию задачи (реверсирование битов числа) студентам нельзя было юзать if.

    bieber, 10 Ноября 2011

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

    +168

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    QTime time;
    
    QString name =  (time.currentTime()).toString();
    
    for (int i = 2; i <= 5; i = i+3)
    {
    	name.remove(i,1);
    	name.insert(i,".");
    }

    вот так вот, ребятишки.

    bartimeus33nt10, 10 Ноября 2011

    Комментарии (9)
  5. bash / Говнокод #8473

    −125

    1. 1
    2. 2
    3. 3
    4. 4
    {  
       (cd "$DIR"; ls -1);
       {  xml2 < $XML | grep '/list/files/@path=' | cut -d = -f 2 | cut -d / -f 2 | sort | uniq; }   
    } | sort | uniq --count | grep '^ *1' | awk '{print $2}' | (cd "$DIR"; xargs --no-run-if-empty rm -v)

    Удаляет из "$DIR" всё, что не описано в files.xml.

    x28cnp, 10 Ноября 2011

    Комментарии (33)
  6. Python / Говнокод #8472

    −87

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    # bad, bad SQLAlchemy!        
        def assemble(self, message):
            mdict = message.__dict__.copy()
            self.__dict__.update(mdict)
            
        def disassemble(self, message):
            mdict = message.__dict__.copy()
            instance_state = self.__dict__.get('_sa_instance_state')
            self.__dict__.update(mdict)
            self.__dict__['_sa_instance_state'] = instance_state
        # /bad, bad SQLAlchemy!

    Вот что приходится делать, если надо привязать класс к нескольким таблицам в SQLAlchemy

    Enchantner, 10 Ноября 2011

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

    +121

    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
    private void textBox1_TextChanged(object sender, EventArgs e)
    {
    	if ((textBox1.Text + textBox2.Text).Length + 1 > 255)
    	{
    		textBox1.BackColor = Color.LightPink;
    		textBox2.BackColor = Color.LightPink;
    	}
    	else
    	{
    		textBox1.BackColor = Color.White;
    		textBox2.BackColor = Color.White;
    	}
    
    	if ((textBox3.Text + textBox6.Text).Length + 1 > 255)
    	{
    		textBox3.BackColor = Color.LightPink;
    		textBox6.BackColor = Color.LightPink;
    	}
    	else
    	{
    		textBox3.BackColor = Color.White;
    		textBox6.BackColor = Color.White;
    	}
    }
    
    private void bntSave_Click(object sender, EventArgs e)
    {
    	if (textBox1.BackColor == Color.LightPink)
    	{
    		MessageBox.Show("Длинна полей От и Адрес в сумме не должна превышать 255");
    		return;
    	}
    	if (textBox3.BackColor == Color.LightPink)
    	{
    		MessageBox.Show("Длинна полей Кому и Адрес в сумме не должна превышать 255");
    		return;
    	}
    
    	Properties.Settings.Default.Save();
    	Navigator.Navigate(new ConfigMenuPage());
    }

    ТЗ: "Суммарная длина полей X и Y не должна превышать 255 символов"
    Решение шедеврально как по вычислению длинны суммы строк, так и по цветовой идентификации :)

    ddv_demon, 10 Ноября 2011

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

    +116

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    IGridCell IGridControl.this[int columnIndex, int rowIndex]
            {
                get { return Cells.Single(c => c.OwningRow.Index == rowIndex && c.OwningColumn.Index == columnIndex); }
                set
                {
                    cells.Remove(cells.Single(c => c.OwningRow.Index == rowIndex && c.OwningColumn.Index == columnIndex));
                    cells.Add(value);
                }
            }

    вот такие вот индексаторы

    Ccik, 10 Ноября 2011

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

    +161

    1. 1
    2. 2
    3. 3
    4. 4
    if ($_POST["SAVE"]!="OK")
            $this->IncludeComponentTemplate();
    else
            $_POST=Array()

    оп оп

    atarix12, 10 Ноября 2011

    Комментарии (16)
  10. PHP / Говнокод #8468

    +158

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    public function addOffer($type='vendor.model', $values) {
        switch ($type) {
          case 'vendor.model': $offer = new yml_type_vendor_model(); break;
          }
        // Заполняем значениями
        $offer->setValues($values);
       ......

    jonnywalker, 10 Ноября 2011

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