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

    В номинации:
    За время:
  2. Куча / Говнокод #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)
  3. 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)
  4. 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)
  5. 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)
  6. 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)
  7. 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)
  8. 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)
  9. C# / Говнокод #6783

    +115

    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
    private object[] select ( string tablename, Type type, string addict ) 
            {
                object[] returned_objects = new object[0];
                string sql = "SELECT ";
                sql += this.buildFieldNames( type );
                sql += " FROM `" + tablename + "`" + addict;
                MySqlDataReader reader = this.TryQueryReader( sql );
                while (reader.Read( ))
                {
                    var obj = Activator.CreateInstance( type );
                    FieldInfo[] fields = type.GetFields( );
                    foreach (FieldInfo finfo in fields)
                    {
                        if (finfo.FieldType == typeof( int ))
                        {
                            finfo.SetValue( obj, reader.GetInt32( finfo.Name ) );
                        }
                        else if (finfo.FieldType == typeof( bool ))
                        {
                            if (reader.GetString( finfo.Name ).Equals( "true" ))
                            {
                                finfo.SetValue( obj, true );
                            }
                            else
                            {
                                finfo.SetValue( obj, false );
                            }
                        }
                        else if (finfo.FieldType == typeof( float ))
                        {
                            finfo.SetValue( obj, reader.GetFloat( finfo.Name ) );
                        }
                        else if (finfo.FieldType == typeof( double ))
                        {
                            finfo.SetValue( obj, reader.GetDouble( finfo.Name ) );
                        }
                        else if (finfo.FieldType == typeof( string ))
                        {
                            finfo.SetValue( obj, reader.GetString( finfo.Name ) );
                        }
                    }
                    provider.IncreaseLength( ref returned_objects, 1 );
                    returned_objects.SetValue( obj, returned_objects.Length - 1 );
    
                }
                reader.Close( );
                return returned_objects;
            }

    самопальный орм, нот комментс

    glilya, 30 Мая 2011

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

    +165

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    // создает массив с заданным кол-вом ячеек
    function array_from_int($count,$val=true,$start=0)
    {
    	$fcount = $count+$start;
    	for($i=$start;$i<$fcount;$i++)
    	{
    		$arr[$i] = $val;
    	}
    	return $arr;
    }

    _tL, 20 Мая 2011

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

    +131

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    <tr> <td width="209" valign="top"><font color="#1674b5">Русский язык</font></td> <td width="244" valign="top"><font color="#1674b5">История России</font></td> <td width="218" valign="top"><font color="#1674b5">Биология</font></td> </tr>
                 
                  <tr> <td width="209" valign="top"><font color="#1674b5">Литература</font></td> <td width="244" valign="top"><font color="#1674b5">Обществознание</font></td> <td width="218" valign="top"><font color="#1674b5">Химия</font></td> </tr>
    
                 
                  <tr> <td width="209" valign="top"><font color="#1674b5">Математика</font></td> <td width="244" valign="top"><font color="#1674b5">Физика</font></td> <td width="218" valign="top"><font color="#1674b5">География</font></td> </tr>
                 
                  <tr> <td width="209" valign="top"><font color="#1674b5">Информатика и ИКТ</font></td> <td width="244" valign="top"><font color="#1674b5">Иностранный язык</font></td> <td width="218" valign="top">

    Вёрстка сайта на Битриксе.

    RaZeR, 09 Мая 2011

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