1. PHP / Говнокод #7811

    +162

    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
    function validemail($email){
    
     if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email))
    
     return false;
    
    
    
     $email_array = explode("@", $email);
    
     $local_array = explode(".", $email_array[0]);
    
     for ($i = 0; $i < sizeof($local_array); $i++) {
    
      if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i]))
    
      return false;
    
     }

    jQuery, 08 Сентября 2011

    Комментарии (42)
  2. PHP / Говнокод #7810

    +173

    1. 1
    define("RANDOM_NUM", rand(0, 10000000));

    поясню: кодер думал, что каждый раз будет вызываться функция и генерить новое число, т.к. в коде далее идет ее использование как уникального идентификатора. Скорее всего, это один из первых скриптов того, кто писал.

    jokz, 08 Сентября 2011

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

    +176

    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
    <a id="hide" href ="javascript:
    var text = $('#ccc').html();
    function hide(){
        $('#ccc').html('');
        $('#hide').attr('href', 'javascript: show(); ');
    }
    function show(){
        $('#ccc').html(text);
        $('#hide').attr('href', 'javascript: hide(); ');
    }
    hide();
    ">Скрыть/Показать</a>
    
    <div id="ccc">скрываемвый текст</div>

    Я думаю комментарии излишни. Я считаю что это идеальный говнокод. И отличная замена $('#ccc').toggle();

    taral, 08 Сентября 2011

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

    +161

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    <?
    if($page!='/volga' && $page!='/volga/index.php'){
    // Тут всякий код
    } if($page=='/volga' or $page=='/volga/index.php'){?>
    // И тут тоже	
    <?}?>

    Tairesh, 08 Сентября 2011

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

    +66

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    Integer obj = (Integer)dump.get("size");
            if(obj == null) {
                return;
            }
            int size = obj;
            for(int i=0; i<size; i++) {

    Самое странное, что автор явно знает, что такое автобоксинг, но всё равно использовал его коряво.

    lucidfox, 08 Сентября 2011

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

    +77

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    public abstract class Data {
    		// The tone of Commander Riker's voice makes me suspect that
    		// he is not serious about finding Ambassador T'Pel charming.
    		// My experience suggests that in fact he may mean the exact
    		// opposite of what he says. Irony is a form of expression
    		// I have not yet been able to master.

    lucidfox, 08 Сентября 2011

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

    +84

    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
    Query q;
          //для хэширования
    
          q =
             session.createQuery("select idElType from " + LinkToAtributeValue.class.getName()
             + " where idEl=" + idObject.toString());
    
          Vector<Integer> vec = new Vector<Integer>(q.list());
          int t;
          for(int i = 0; i < vec.size() - 1; i++) {
             t = vec.get(i);
             for(int j = i + 1; j < vec.size(); j++) {
                if(t == vec.get(j)) {
                   vec.remove(j);
                }
             }
          }

    "DISTINCT для трусов"
    или
    "Хорошего кода должно быть много"

    maxt, 08 Сентября 2011

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

    −85

    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
    def captions_and_translations_to_srt(captions_and_translations):
        output = StringIO.StringIO()
        for i in range(len(captions_and_translations)):
            translation_to_srt(captions_and_translations[i][1],
                               captions_and_translations[i][0],
                               i, output)
        srt = output.getvalue()
        output.close()
        return srt
    
    def translation_to_srt(translation, video_caption, index, output):
        subtitle_to_srt_impl(video_caption.caption_text if translation is None \
                             else translation.translation_text, 
                             video_caption, index, output)
    
    def subtitle_to_srt_impl(text, video_caption, index, output):
        output.write(str(index + 1))
        output.write("\n")
        write_srt_time_line(video_caption, output)
        output.write(text)
        output.write("\n\n")
    
    def write_srt_time_line(video_caption, output):
        write_srt_time(video_caption.start_time, output)
        output.write(" --> ")
        write_srt_time(video_caption.end_time, output)
        output.write("\n")
    
    def write_srt_time(seconds, output):
        seconds_int = int(seconds)
        write_padded_num((seconds_int / 3600) % 60, 2, output)
        output.write(":")
        write_padded_num((seconds_int / 60) % 60, 2, output)
        output.write(":")
        write_padded_num(seconds_int % 60, 2, output)
        output.write(",")
        write_padded_num(int(seconds * 1000) % 1000, 3, output)
    
    def write_padded_num(num, numchars, output):
        strnum = str(num)
        numzeros = numchars - len(strnum)
        for i in range(numzeros):
            output.write("0")
        output.write(strnum)

    Генератор SRT субтитров.

    alerion, 08 Сентября 2011

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

    +79

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    public void restore(HashMap<String, Object> dump) {
    		if(dump != null) {
    			if(isInitialized()) {
    				if(isInitialized()) {
    					clear();

    "Проинициализировано? Точно-точно?"

    lucidfox, 08 Сентября 2011

    Комментарии (8)
  10. JavaScript / Говнокод #7802

    +172

    1. 1
    2. 2
    3. 3
    4. 4
    days = (days < 10) ? days : days;
    hours = (hours < 10) ? hours : hours;
    minutes = (minutes < 10) ? minutes : minutes;
    seconds = (seconds < 10) ? seconds : seconds;

    Загадочная русская душа. Лежало в коде таймера обратного отсчета.

    ckald, 08 Сентября 2011

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