1. Java / Говнокод #7331

    +147

    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
    public class Matrix {
    
        private float matrix[][];
        private int dim;
    
        public Matrix(int dim) {
            this.dim = dim;
            this.matrix = new float[dim][dim];
        }
    
        public void productOfTwo(Matrix src, Matrix dest) {
            if (src.dim == this.dim) {
                dest.dim = this.dim;
    
                Matrix[] temp = new Matrix[this.dim];
                for (int i = 0; i < this.dim; i++) {
                    temp[i] = new Matrix(this.dim);
                }
    
                for (int i = 0; i < this.dim; i++) {
                    for (int j = 0; j < this.dim; j++) {
                        for (int k = 0; k < this.dim; k++) {
                            temp[k].matrix[i][j] = this.matrix[i][k] * src.matrix[k][j];
                        }
                    }
                }
              
                for (int i = 0; i < this.dim; i++) {
                    dest.sum(temp[i]);
                }
            } else {
                System.out.println("  An error occured: Dimensions of matrices do not match");
            }
        }
    
        public float findDet() {
            if (this.dim == 1) {
                return this.matrix[0][0];
            } else if (this.dim == 2) {
                return this.matrix[0][0] * this.matrix[1][1] - this.matrix[0][1] * this.matrix[1][0];
            } else {
                float result = 0;
                Matrix minor = new Matrix(this.dim - 1);
                for (int i = 0; i < this.dim; i++) {
                    for (int j = 1; j < this.dim; j++) {
                        System.arraycopy(this.matrix[j], 0, minor.matrix[j - 1], 0, i);
                        System.arraycopy(this.matrix[j], i + 1, minor.matrix[j - 1], i, this.dim - (i + 1));
                    }
                    result += Math.pow(-1, i) * this.matrix[0][i] * minor.findDet();
                }
                return result;
            }
        }

    Всем доброго времени суток! Прошу к Вашему вниманию алгоритм нахождения произведения двух матриц(умножаем слева направо) и нахождения детерминанта разложением по столбцу(рекурсия). Прошу оценить, по всей строгости.
    Заранее спасибо!

    kaspvar, 24 Июля 2011

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

    +958

    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
    namespace sortFiles
    {
        public partial class Form1 : Form
        {
            private void listBox1_DragDrop(object sender, DragEventArgs e)
            {
                this.listBox1.Items.AddRange((string[])e.Data.GetData(DataFormats.FileDrop, false));
            }
    
            private void listBox1_DragEnter(object sender, DragEventArgs e)
            {
                e.Effect = (e.Data.GetDataPresent(DataFormats.FileDrop) ? DragDropEffects.Copy : DragDropEffects.None);
            }
    
            private void listBox1_MouseDown(object sender, MouseEventArgs e)
            {
                var files = new List<OrderByMyCamera>();
                foreach (string i in listBox1.Items)
                    files.Add(new OrderByMyCamera(i));
                if(files.Count==0)
                    return;
                files.Sort();
                var filesArray = files.Select(item=>item.ToString()).ToArray();
                DoDragDrop(new DataObject(DataFormats.FileDrop, filesArray), DragDropEffects.Copy);
            }
        }
    
        internal class OrderByMyCamera : IComparable<OrderByMyCamera>
        {
            private readonly string _filePath;
            private readonly int _fileNumber;
    
            public OrderByMyCamera(string filePath)
            {
                _filePath = filePath;
                var fileName = Path.GetFileNameWithoutExtension(filePath);
                if(fileName.Count()!=6)
                    throw new Exception("Имя файла должно быть 6+4 символов вида MOVXXX.mpg. Возможно вы попытались вставить не те файлы в программу");
                if (!filePath.Trim().ToLower().EndsWith(".mpg"))
                    throw new Exception("Файлы должны заканчиваться на расширение .mpg. Сконвертируете файлы в mpeg, прежде чем вставите их в программу");
                int fileNumber = int.Parse(fileName.Substring(3), NumberStyles.HexNumber);
                _fileNumber = fileNumber;
            }
    
           public override string ToString()
            {
                return _filePath;
            }
    
            public int CompareTo(OrderByMyCamera other)
            {
                if (_fileNumber == other._fileNumber)
                    return 0;
                return (_fileNumber > other._fileNumber ? 1 : -1);
            }
        }
    }

    Говногость, 24 Июля 2011

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

    +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
    jQuery.each(elems, function(i, elem) {
                    if (typeof elem === "number") {
                        elem += "";
                    }
                    if (!elem) {
                        return;
                    }
                    if (typeof elem === "string" && !rhtml.test(elem)) {
                        elem = context.createTextNode(elem);
                    } else if (typeof elem === "string") {
                        elem = elem.replace(rxhtmlTag, fcloseTag);
                        var tag = (rtagName.exec(elem) || ["", ""])[1].toLowerCase(),
                            wrap = wrapMap[tag] || wrapMap._default,
                            depth = wrap[0],
                            div = context.createElement("div");
                        div.innerHTML = wrap[1] + elem + wrap[2];
                        while (depth--) {
                            div = div.lastChild;
                        }
                        if (!jQuery.support.tbody) {
                            var hasBody = rtbody.test(elem),
                                tbody = tag === "table" && !hasBody ? div.firstChild && div.firstChild.childNodes : wrap[1] === "<table>" && !hasBody ? div.childNodes : [];
                            for (var j = tbody.length - 1; j >= 0; --j) {
                                if (jQuery.nodeName(tbody[j], "tbody") && !tbody[j].childNodes.length) {
                                    tbody[j].parentNode.removeChild(tbody[j]);
                                }
                            }
                        }
                        if (!jQuery.support.leadingWhitespace && rleadingWhitespace.test(elem)) {
                            div.insertBefore(context.createTextNode(rleadingWhitespace.exec(elem)[0]), div.firstChild);
                        }
                        elem = jQuery.makeArray(div.childNodes);
                    }
                    if (elem.nodeType) {
                        ret.push(elem);
                    } else {
                        ret = jQuery.merge(ret, elem);
                    }
                });

    mark, 24 Июля 2011

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

    +975

    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
    switch (Game1.mus)
                {
                    case false: sb.Draw(disabled, new Vector2(ScrW - 256, 90), Color.White); break;
                    case true: sb.Draw(enabled, new Vector2(ScrW - 256, 90), Color.White); break;
                }
                
                switch (Game1.bloooom)
                {
                    case false: sb.Draw(disabled, new Vector2(ScrW - 256, 180), Color.White); break;
                    case true: sb.Draw(enabled, new Vector2(ScrW - 256, 180), Color.White); break;
                }
                
                switch (Game1.part)
                {
                    case false: sb.Draw(disabled, new Vector2(ScrW - 256, 270), Color.White); break; //420
                    case true: sb.Draw(enabled, new Vector2(ScrW - 256, 270), Color.White); break;
                }
                
                switch (Game1.eff)
                {
                    case false: sb.Draw(disabled, new Vector2(ScrW - 256, 360), Color.White); break; //510
                    case true: sb.Draw(enabled, new Vector2(ScrW - 256, 360), Color.White); break;
                }
                switch (Game1.shad)
                {
                    case false: sb.Draw(disabled, new Vector2(ScrW - 256, 450), Color.White); break; 
                    case true: sb.Draw(enabled, new Vector2(ScrW - 256, 450), Color.White); break;
                }

    Оттуда же, откуда и #5199. Случайно обнаружил...

    RaZeR, 24 Июля 2011

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

    +161

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    if (window.ActiveXObject) window.ie = window[window.XMLHttpRequest ? 'ie7' : 'ie6'] = true;
    else if (document.childNodes && !document.all && !navigator.taintEnabled) window.webkit = window[window.xpath ? 'webkit420' : 'webkit419'] = true;
    else if (document.getBoxObjectFor != null) window.gecko = true;
    var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
    var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
    var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;

    mark, 24 Июля 2011

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

    +164

    1. 1
    2. 2
    3. 3
    <a href="?page=news" <?php if (isset($_GET['page'])) if ($_GET['page']=='news') echo 'class="active"' ?> >Новости</a>
    <a href="?page=photo" <?php if (isset($_GET['page'])) if ($_GET['page']=='photo') echo 'class="active"' ?> >Фото</a>
    <a href="/" <?php if (isset($_GET['page'])); else echo ' class="active"'?> >Главная</a>

    Подсветка той ссылки, на которой сейчас находишься (присвоение класса active).
    Проверка if (isset($_GET['page'])) сделана для того, чтобы PHP не ругался на то, что page не передан (такое происходит при переходе на главную).

    opex_jr, 23 Июля 2011

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

    +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
    $sections = array_chunk($items, $this->item_limit, true);
    $k = 0;
    foreach($sections as $key => $items) {
    	/*.........*/	
    	$name = 'sitemap' . $k . '.xml';
    	$index['sitemap%'.$k] = array(
    	    'loc' => BASE_URL . $name,
    	    'lastmod' => date('c')
    	);
    	/*.........*/	
    	$k++;
    }

    Видимо я чем-то здорово накидался кода писал это T_T

    DrFreez, 23 Июля 2011

    Комментарии (28)
  8. Python / Говнокод #7323

    −86

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    {% if field.help_text %}
    <tr>
    <td></td>
    <td colspan="2" style="padding-top: 0px; padding-bottom: 10px;">{{ field.help_text|safe }}</td>
    <td>
    <img id="captcha_img" src="<?php echo $absolute_page_path; ?>captcha/captcha.php?ref=register"/>
    </td>
    {% endif %}

    Вот такую веселую хрень встретил в джанговских темплейтах =)

    de_orion, 23 Июля 2011

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

    +166

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    for($i=0,$n=count($vars);$i<$n;$i++){
    
        eval(' $'.$vars[$i].'=isset($_POST["'.$vars[$i].'"])? addslashes(trim($_POST["'.$vars[$i].'"])) : ""; ');
    
      }

    В недрах самописной crm)

    antongorodezkiy, 23 Июля 2011

    Комментарии (11)
  10. Куча / Говнокод #7321

    +147

    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
    Рефакторинг всего сайта. 
    
    В html:
    <a class="gal" href="ссылка">
    	<p><img width="96" height="63" alt="" src="image.jpg"></p>
    	<p>Название</p>
        </a>
    
    В админке уже сделал ресайс изображений! 
    
    И вдруг оказывается  в CSS:
    .gal img {
      border: 1px solid #F4EDDC;
      display: block;
      height: 100px;
      margin: 0 auto;
      width: 160px;
    }

    Изменить дело 5 сек.. Но зло берет.

    De-Luxis, 23 Июля 2011

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