1. Лучший говнокод

    В номинации:
    За время:
  2. C++ / Говнокод #7560

    +169

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    void some_func(ptrdiff_t value)
    {
      register double cos_v=cos(static_cast<double>(value));
      ptrdiff_t pt=static_cast<ptrdiff_t>(cos_v);
      {... working with pt ...}
    }

    Более того есть функция матричного умножения, элементами этих матриц являются ptrdiff_t'ы (там уже нет перевода в double при вычислениях).
    Мне одному кажется что автор наркоман?

    J0hnny, 17 Августа 2011

    Комментарии (18)
  3. PHP / Говнокод #7543

    +163

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    $firstName = $_POST['firstname'];
    $secondName=$_POST['secondname'];
    $email = $_POST['email'];
    $query="insert into sportsmans values('$secondName','$firstName','$email',null)";
    $conn = mysql_connect('localhost','root','VCh3005');
    mysql_select_db('Competition');
    mysql_query("SET NAMES 'utf8'");
    mysql_query("SET CHARACTER SET 'utf8'");
    mysql_query($query);
    mysql_error();
    mysql_close();

    Классика...

    Sulik78, 14 Августа 2011

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

    −179

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    #count pages
    	my $counter; my $pagescount = 0; my $pagesstr;
    	for (my $i = 0; $i <= $count; $i++)
    	{
    		if ($counter == POSTS_PER_PAGE)
    		{
    		    my $a,$b; if ($pagescount == $pagenum) { $a = "["; $b = "]"; } else { $a = ""; $b = ""; }
    			$pagesstr = $pagesstr."$a<a href=\"wakaba.pl?task=mpanel&admin=$admin&page=$pagescount\">".($pagescount +1)."</a>$b" if ($pagescount == 0);
    			$pagesstr = $pagesstr.", $a<a href=\"wakaba.pl?task=mpanel&admin=$admin&page=$pagescount\">".($pagescount +1)."</a>$b" if ($pagescount != 0);
    			$pagescount++; $counter = 0;
    		} else { $counter++; }
    	}

    Вот такой веселый код пишут программисты дватиреча и на этом этот самый имиджборд и работает.

    7ion, 05 Августа 2011

    Комментарии (18)
  5. Куча / Говнокод #7424

    +126

    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
    <div id="scroller">
      <a href="javascript:scroll(0,0)">Наверх</a>
    </div>
    
    <style type="text/css">
    #scroller {
    position:fixed;
    left:0px;
    top:100%;}
    
    #scroller a {
    position:relative;
    top:-47px;
    padding:5000px 10px 30px 10px;}
    
    #scroller a:hover {background:#d8e3f0;}
    </style>

    Скролл страницы наверх, прикреплённый к левой границе экрана. Надпись "Наверх" -- внизу экрана. Опускаю блок под экран -- "top:100%", а потом поднимаю ссылочку наверх -- "top:-47px".

    opex_jr, 02 Августа 2011

    Комментарии (18)
  6. Java / Говнокод #7410

    +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
    20. 20
    21. 21
    22. 22
    protected IOException copyRange(InputStream istream, ServletOutputStream ostream) {
    
            // Copy the input stream to the output stream
            IOException exception = null;
            byte buffer[] = new byte[input];
            int len = buffer.length;
            while (true) {
                try {
                    len = istream.read(buffer);
                    if (len == -1) {
                        break;
                    }
                    ostream.write(buffer, 0, len);
                } catch (IOException e) {
                    exception = e;
                    len = -1;
                    break;
                }
            }
            return exception;
    
        }

    Си-стайл в исходниках Tomcat. Зачем кидать исключения, если их можно возвращать вместо кода ошибки?

    Eyeless, 01 Августа 2011

    Комментарии (18)
  7. Assembler / Говнокод #7378

    +240

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    db $8F, $AE, $A7, $A4, $E0, $A0, $A2, $AB, $EF, $EE, $20, $E3, $EE, $E2, $AD, $A5
    db $AD, $EC, $AA, $A8, $A9, $20, $A3, $AE, $A2, $AD, $AE, $AA, $AE, $A4, $A8, $AA
    db $20, $E1, $20, $A4, $AD, $F1, $AC, $20, $E1, $A8, $E1, $E2, $A5, $AC, $AD, $AE
    db $A3, $AE, $20, $A0, $A4, $AC, $A8, $AD, $A8, $E1, $E2, $E0, $A0, $E2, $AE, $E0
    db $A0, $21

    TarasB, 29 Июля 2011

    Комментарии (18)
  8. 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)
  9. PHP / Говнокод #7304

    +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
    function footer_menu()
    {
        global $tbl_lng;
        $result_str = '';
        $first = true;
        
        $sql = mysql_query('SELECT section_id, section_name, section_level, section_url FROM '.$tbl_lng.' WHERE section_level = 1 ORDER BY section_order')
          or die("Invalid query: " . mysql_error()); 
        while($row = mysql_fetch_array($sql))  
        {
            if ($row['section_url'] != '')
            {
                if ($first)
                {
                  $first = false;
                  $result_str = $result_str.'<a class="header_menu2_txt" href="' . $row["section_url"] . '">' . $row["section_name"] . '</a>';
                }
                else
                {
                    $result_str = $result_str.'<img src="images/footer_s.png" width="26" height="20" alt="" /><a class="header_menu2_txt" href="' . $row["section_url"] . '">' . $row["section_name"] . '</a>';
                }
            }
            else
            {
                if ($first)
                {
                  $first = false;
                  $result_str = $result_str.'<a class="header_menu2_txt" href="index.php?section_id=' . $row["section_id"] . '">' . $row["section_name"] . '</a>';
                }
                else
                {
                    $result_str = $result_str.'<img src="images/footer_s.png" width="26" height="20" alt="" /><a class="header_menu2_txt" href="index.php?section_id=' . $row["section_id"] . '">' . $row["section_name"] . '</a>';
                }
                
            }
        }
        
        mysql_free_result($sql);
       
        return $result_str;
    }

    Реализация нижнего меню.

    enemis, 21 Июля 2011

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

    +157

    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 parse_req($value) 
    {
        global $log_conf;
        if(!is_array($value)) 
        {
            if(preg_match("#UNION|OUTFILE|SELECT|ALTER|INSERT|DROP|TRUNCATE#i", base64_decode($value))) 
            {
                if($log_conf['queryError'] == 1) writeInLog('Попытка произвести SQL-Inj текст: '.$value, 'sql');
                //fatal_error(_ERROR, _UNKNOWN_ERROR);	
    			die();
            }
        }
        else
        {
            foreach($value as $val) 
            {
                parse_req($val);
            }
        }
    }

    Баян конечно, но всегда удивляюсь на что они рассчитывают?
    Как-бы борится с SQL-Injection...

    nethak, 20 Июля 2011

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

    +168

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    function randlogo(){
    arr=new Array('<img src="http://site.com/logo-pomegranate.png" border="0" width="677" height="345">','<img src="http://site.com/logo-leaves.png" border="0" width="677" height="345">','<img src="http://site.com/logo-lime.png" border="0" width="677" height="345">','<img src="http://site.com/logo-coffee.png" border="0" width="677" height="345">','<img src="http://site.com/logo-lime.png" border="0" width="677" height="345">','<img src="http://site.com/logo-peach.png" border="0" width="677" height="345">','<img src="http://site.com/logo-lemon.png" border="0" width="677" height="345">','<img src="http://site.com/logo-leaf.png" border="0" width="677" height="345">','<img src="http://site.com/logo-apples.png" border="0" width="677" height="345">','<img src="http://site.com/logo-grapes.png" border="0" width="677" height="345">','<img src="http://site.com/logo-autumn.png" border="0" width="677" height="345">','<img src="http://site.com/logo-strawberry.png" border="0" width="677" height="345">')
    rand=Math.floor(Math.random()*arr.length)
    document.getElementById('randlogo').innerHTML=arr[rand]
    }
    randlogo()

    Код для генерации случайного логотипа.

    undiscovered, 02 Июня 2011

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