1. 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)
  2. 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)
  3. 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)
  4. Ruby / Говнокод #7801

    −99

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    case klass
        when "Subject"
          case attr.to_sym
          when :screening_num then :screening_num
          when :subject_num then :subject_num
          end
        end

    это чО на всякий пожарный чтоли ?
    обратите внимание что klass это объект ActiveRecord а проверяется как стринг

    писал русский паренёк Дима ) а вы говорите индусы )

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

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

    +173

    1. 1
    $lib = $app['memcache.wrapper'] === false ? false : $app['memcache.wrapper'];

    я туплю????? или кто-то получает за количество символов ????

    AlexanderC, 07 Сентября 2011

    Комментарии (8)
  6. Куча / Говнокод #7799

    +137

    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
    62. 62
    63. 63
    64. 64
    <table border="0" cellpadding="0" cellspacing="0" width="1000">
                    <tr>
                        <td width="1000" height="160" background="images/up.gif" align="center" valign="middle">
    <ul>
    
                                <ul>
                                    <ul>
                                        <ul>
                                            <ul>
                                                <ul>
                                                    <ul>
                                                        <ul>
                                                            <ul>
                                                                <ul>
    
                                                                    <ul>
                                                                        <ul>
                                                                            <ul>
                                                                                <p align="center">
                                                                                <form action="http://www.google.com/cse" id="cse-search-box" target="_blank">
      <div>
                                                                                            <ul>
                                                                                            <ul>
                                                                                                <ul>
    
                                                                                                    <ul>
                                                                                                        <ul>
                                                                                                            <p><input type="hidden" name="cx" value="partner-pub-6721689618919481:ttrzumsg220" />
        <input type="hidden" name="ie" value="windows-1252" />
        <input type="text" name="q" size="25" />
        <input type="submit" name="sa" value="Search" />
    </p>
                                                                                                        </ul>
                                                                                                    </ul>
    
                                                                                                </ul>
                                                                                            </ul>
                                                                                        </ul>
      </div>
                                                                                </form>
                                                                                <script type="text/javascript" src="http://www.google.com/cse/brand?form=cse-search-box&amp;lang=en">
                                                                                </script>
                                                                                </p>
    
                                                                                <p align="center">
    
                                                                                
    </p>
                                                                            </ul>
                                                                        </ul>
                                                                    </ul>
                                                                </ul>
                                                            </ul>
                                                        </ul>
                                                    </ul>
    
                                                </ul>
                                            </ul>
                                        </ul>
                                    </ul>
                                </ul>
    </ul>
                        </td>                </tr>
                </table>

    из хтмла http://www.izarc.org/

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

    Dummy00001, 07 Сентября 2011

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

    +165

    1. 1
    2. 2
    3. 3
    4. 4
    $transaction_number = (int)$this->security->xss_clean(trim(htmlspecialchars(substr($transaction_number, 0, 50))));
    
    if(!$transaction_number OR $transaction_number < 0)
    			$transaction_number = 0;

    один из наших программистов пишет.
    CodeIgniter.

    themars, 07 Сентября 2011

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

    +75

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    try {
        Method m = this.getClass().getMethod("setLayerType", int.class, Paint.class);
        if (m != null) {
            m.invoke(this, View.LAYER_TYPE_SOFTWARE, (Object)null);
        }
    } catch (NoSuchMethodException e) {
    } catch (IllegalAccessException e) {
    } catch (InvocationTargetException e) {
    }

    Моему коллеге пришлось писать _такое_ только потому, что заказчик не захотел форкнуть проект на две отдельных ветки, для Android 2.3 и для 3.2.

    wildscliss, 07 Сентября 2011

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

    +167

    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
    // Проверка на спам
    $Spam = false;
    if ( substr_count( GetParam( 'info', true ), '[url' ) > 0 )
    {
    	$Spam = true;
    };
    if ( substr_count( GetParam( 'info', true ), 'viagra' ) > 0 )
    {
    	$Spam = true;
    };
    if ( substr_count( GetParam( 'info', true ), 'cialis' ) > 0 )
    {
    	$Spam = true;
    };
    if ( substr_count( GetParam( 'info', true ), 'casino' ) > 0 )
    {
    	$Spam = true;
    };
    if ( strlen( GetParam( 'info', true ) ) < 10 )
    {
    	$Spam = true;
    };
    
    if ( $Spam )
    {
    	$Message = "В тексте сообщения находятся спам-подобные слова.";
    }

    кусок кода одного скрипта, гордо именуемого CMS

    forkhammer, 07 Сентября 2011

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

    +146

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    if ( city_name(5) = 'город' or city_name(5) = 'ГОРОД' or
        city_name(5) = 'Город' or city_name(5) = 'ГоРоД' or
        city_name(5) = 'гороД' or city_name(5) = 'гОрОд' or
         city_name(6) = 'город.' or city_name(6) = 'ГОРОД.'
      or city_name(6) = 'Город.' or city_name(6) = 'ГоРоД.'
      or city_name(6) = 'гороД.' or city_name(6) = 'гОрОд.' )
          and city_name <> 'Городец'.
        shift city_name by 5 places.
      endif.

    Чистим лишнее из имени города.

    foGa, 07 Сентября 2011

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