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

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

    +71

    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
    /**
     * Get the river's access where clause
     *
     * @return string
     * @since 1.8.0
     * @access private
     */
    function elgg_river_get_access_sql() {
    	// rewrite default access where clause to work with river table
    	return str_replace("and enabled='yes'", '',
    		str_replace('owner_guid', 'rv.subject_guid',
    		str_replace('access_id', 'rv.access_id', get_access_sql_suffix())));
    }

    Кусок из ядра фремворка Elgg, Sql запрос подправляется с помощью str_replace

    piromanlynx1, 15 Мая 2012

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

    +71

    1. 1
    2. 2
    $res= (isset($r[0]) and count($r[0]) > 0) ? true : false;
    return $res;

    Классика

    Мартин, 14 Мая 2012

    Комментарии (4)
  4. Java / Говнокод #10257

    +71

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    int buttonState = R.id.power_widget_button_indic; // Зачем-то объявили лишнюю переменную, ссылающуюся на константу
    ImageView indic = (ImageView) mView.findViewById(R.id.power_widget_button_indic); // Но здесь используем константу, а не новую, более короткую переменную!
    if ((Settings.System.getInt(context.getContentResolver(), Settings.System.EXPANDED_HIDE_INDICATOR, 0)) == 1) {
    	indic.setVisibility(8); // Для установки видимости существуют константы View.VISIBLE, View.INVISIBLE и View.GONE, а циферка 8 вообще ни о чем мне не говорит
    } else {
    	indic.setVisibility(0); // И еще раз
    }

    Это - кусок кода из Android 4, вернее, из CyanogenMod 9. Репозиторий frameworks_base, файл packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/PowerButton.java. И такого говнокода в исходниках Android - полно :(

    RankoR, 13 Мая 2012

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

    +71

    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
    <?php
    session_start();
    $uploadName = 'test'; 
    if (isset($_GET['ajax'])) { 
        if (isset($_SESSION["upload_progress_$uploadName"])) { 
            $progress = $_SESSION["upload_progress_$uploadName"];
            $percent = round(100 * $progress['bytes_processed'] / $progress['content_length']);
    $text1 = iconv("CP1251", "UTF-8", "Общий прогресс загрузки: ");
    $text2 = iconv("CP1251", "UTF-8", "Загружается файл: ");
    $text3 = iconv("CP1251", "UTF-8", "Общее время загрузки: ");
    $text4 = iconv("CP1251", "UTF-8", "Скорость загрузки: ");
    $text5 = iconv("CP1251", "UTF-8", " сек. ");
    $text6 = iconv("CP1251", "UTF-8", " Мбайт. ");
    echo '<HTML><HEAD><title>Upload</title><meta name="keywords"><meta name="description" ><meta http-equiv="content-type" content="text/html;charset=windows-1251"></HEAD><BODY>';
    $pos1 = $percent * 4;
    $pos2 = 400 - $pos1;       
      echo '<div style="background: #00ff00; width: '.$pos1.'; height: 10px; border: solid 1px black; "></div><div style="background: #ffe4e1; width: '.$pos2.'px; height: 10px; position: relative; left: '.$pos1.'px; top: -12px; border: solid 1px black;"></div>';     
      echo '<div align="center" style="width: 400;">';       
            echo '<b>'.$text1.$percent.'%<br>';        
            $t3 = time() - $progress[start_time];
            echo $text3.$t3.$text5.'<br>'; 
            if ($t3 < 1 ) { $t3 = 1; } 
    $speed = (($progress[bytes_processed] / $t3) / 1024) / 1024;
            echo $text4.$formatted = sprintf ("%01.2f", $speed).$text6.'</b><br>'; 
    for($i=0;$i<count($progress[files]);$i++){ echo $text2.$progress[files][$i][name].'<br>'; } 
    echo '</div>';
        } else {
            echo '<div align="center" style="width: 400;">no uploading</div>';
        }
        exit;
    } elseif (isset($_GET['frame'])) { ?>
        <div align="center"><form align="center" action="" method="POST" enctype="multipart/form-data">
            <input type="hidden" name="<?=ini_get("session.upload_progress.name")?>"
                    value="<?=$uploadName?>" />
            <input type="file" name="file[]" multiple="true"/><input value="Загрузить" type="submit" /></form></div>
    <?php
    if($_FILES){
    for($i=0;$i<count($_FILES["file"]["name"]);$i++){
    if(is_uploaded_file($_FILES["file"]["tmp_name"][$i])){    
    move_uploaded_file($_FILES["file"]["tmp_name"][$i], "upload/".$_FILES["file"]["name"][$i]);   
    }
    }
    echo '<div align="center">загружено</div>';
    }
    ?>    
    <?php } else { ?>
    <HTML><HEAD><title>Upload</title><meta name="keywords"><meta name="description" ><meta http-equiv="content-type" content="text/html;charset=windows-1251">
    </HEAD><BODY><div align="center" style="width: 400;"><H3>Загрузчик файлоф на сайт</H3>требования: PHP 5.4, Firefox 3,6  и выше</div>
        <iframe src="?frame" height="70" width="400" align="center" frameborder="0" vspace="0" hspace="0" marginwidth="0" marginheight="0" scrolling="no" style="overflow:visible"></iframe>
        <script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
        <script>
            $(function() {
                setInterval(function() { 
                    $.get('?ajax', function(data) { 
                        $('#ajax').html(data); 
                    });
                }, 500);
            });
        </script>
        <div id="ajax"></div>
    <?php }

    ...

    ra0ceq, 05 Мая 2012

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

    +71

    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
    public class ... {
    
    public Double toDoubleValue(String s){
    	Double value;
    	if (s!=""){
    		value = Double.valueOf(s);
    		return value;
    	}
    	else {
    		value = 0.00;
    		return value;
    	}
            ....
            toDoubleValue(row.getColumnValue(col.getId()).toString());
    }

    1. На null не проверяется
    2. Можно было тоже самое написать короче, не объявляя дополнительный метод, с помощью ?:

    -EZ-, 02 Мая 2012

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

    +71

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    $var1 = "Строка";
    $var2 = true;
    
    var_dump($var1);
    var_dump($var2);
    if($var1 != $var2){
         echo "Не равны";
    }else{
         echo "Равны";
    }

    Недавно заметил странное поведение моего кода и вот что выяснилось.
    Исправил сравнением по типу !==.
    Не думал что такая вот хрень всплывет.

    haker, 01 Мая 2012

    Комментарии (25)
  8. Java / Говнокод #9984

    +71

    1. 1
    2. 2
    Calendar calendar = new GregorianCalendar();
    calendar.setTime(new Date(System.currentTimeMillis()));

    Eyeless, 19 Апреля 2012

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

    +71

    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
    public int getLifeWidth() {
    		return cells == null ? 0 : cells.length;
    	}
    
    	public int getLifeHeight() {
    		return cells == null || cells.length == 0 || cells[0] == null ? 0 : cells[0].length;
    	}
    
    	private int _getLifeWidth() {
    		return cells.length;
    	}
    
    	private int _getLifeHeight() {
    		return cells[0].length;
    	}

    есть ли мне оправдание? ))

    Lure Of Chaos, 09 Апреля 2012

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

    +71

    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
    String url = "http://*.*.*.*:*/java/?code=" + sCode + "&request=monitor";
    String LogPass = sName + ":" + sPass;
    String sAuth = "Basic " + encodeBase64(LogPass);
    try
                {
                    con = (HttpConnection)Connector.open(url);
                    con.setRequestMethod("GET");
                    con.setRequestProperty("User-Agent", "Profile/MIDP-2.0 Confirguration/CLDC-1.0");
                    con.setRequestProperty("Accept_Language", "en-US");
                    con.setRequestProperty("Content-Type", "//text plain");
                    con.setRequestProperty("Connection", "close");
                    con.setRequestProperty("Authorization", sAuth);
                    in = con.openInputStream();
                    if(con.getResponseCode() == 200)
                    {
                        StringBuffer sb = new StringBuffer();
                        int chr;
                        while((chr = in.read()) != -1) 
                            sb.append((char)(chr < 192 || chr > 255 ? chr : chr + 848));
                        sBuff = sb.toString();
                    }
    }

    Авторизация в одной из платёжных систем

    dinisoft, 28 Марта 2012

    Комментарии (7)
  11. Java / Говнокод #9763

    +71

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    try
                    {
                        //PI'я капец??
                        realStream.close();
                    }
                    catch (Throwable t)
                    {
                        throw new IOException(t);
                    }

    Примечание: realStream - это обычный java.io.OutputStream

    konsoletyper, 26 Марта 2012

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