1. Ruby / Говнокод #6489

    −102

    1. 1
    2. 2
    3. 3
    def route_match? origin, destination
      origin.iata == origin and destination.iata == destination
    end

    В классе конечно определены методы origin и destination

    rakoth3d, 27 Апреля 2011

    Комментарии (15)
  2. Ruby / Говнокод #6419

    −100

    1. 1
    File.basename(File.basename(name, '.jpg'), '.png')

    Файл либо с расширением .png, либо .jpg

    e2718, 20 Апреля 2011

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

    −107

    1. 1
    require File.expand_path(File.dirname(__FILE__) + '/../../../../../../usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/connection_adapters/sqlite3_adapter.rb')

    e2718, 20 Апреля 2011

    Комментарии (13)
  4. Ruby / Говнокод #6357

    −97

    1. 1
    hash.to_a.select{|elem| elem[1].map{|st| st.from}.include? state}.map{|elem| elem[1].map{|inner| inner.to}.uniq}.flatten

    e2718, 14 Апреля 2011

    Комментарии (5)
  5. Ruby / Говнокод #6265

    −106

    1. 1
    Dir["#{Rails.root}/lib/**/*"].select { |f| File.directory? f }.join(' ')

    Рекурсивный список каталогов lib проекта Rails.

    e2718, 07 Апреля 2011

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

    −99

    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
    Было (плохо):
    
    <% @collection.each_with_index do |item, counter| -%>
      <%= "<div class='group'>" if ((counter)/items_in_block).to_i*items_in_block == (counter) %>
      <%= render :partial => 'item', :locals => { :item => item} %>
      <%= "</div>" if (counter > 0 and (((counter+1)/items_in_block).to_i*items_in_block == (counter+1)) or ((counter+1) == @collection.size)) %>
    <% end -%>
    
    Стало (чуть лучше ;):
    
    <% @collection.in_groups_of(items_in_block).each do |items| %>
      <div class="group">
        <% items.each do |item| %>
          <%= render :partial => 'item', :locals => { :item => item} %>
        <% end %>
      </div>
    <% end %>

    Группировка элементов в группы div'ов.

    e2718, 07 Апреля 2011

    Комментарии (3)
  7. Ruby / Говнокод #6086

    −106

    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
    # progress bar
    
    width = 60  # width of bar
    com   = 540 # input data
    
    pr = com * 0.01
    i = 0
    j = width
    
    v = 1
    puts
    while pr <= com
    
      print "\r#{v}% [#{"|"*i}#{" "*j}]"
    
      pr += com * 0.01  
    
      i += width * 0.01
      j -= width * 0.01
    
      v += 1  
      
      sleep(0.01)
      
    end
    puts

    Консольный прогресс-бар.

    delmind, 25 Марта 2011

    Комментарии (1)
  8. Ruby / Говнокод #5250

    −104

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    def query(sql)
    		begin
    			@mysql.query(sql)
    		rescue StandardError => err
    			@log.error("Mysql query: '#{sql}\n#{err}'") if @log.class == LoggerHandler
    		end
    	end

    Говнообертка. LoggerHandler - класс, наследующийся от Logger.
    Говнонюанс в том, что Logger.error возвращает true/false в зависимости от того была ли запись в лог успешной, что приводит потом к ошибкам вида NoMethodError: undefined method `each' for true:TrueClass

    govnozmey, 12 Января 2011

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

    −100

    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
    N = 5
    $mas = (1..N).to_a
    $c = 0
     
    def generate(l = 0)
        if l == N-1
            for i in 0..N-1 do
                print("#{$mas[i]} ")
            end
            $c += 1; print("\n")
        else
            for i in l..N-1 do
                t = $mas[l]; $mas[l] = $mas[i]; $mas[i] = t;
                generate(l+1)
                t = $mas[l]; $mas[l] = $mas[i]; $mas[i] = t;
            end
        end
        return $c
    end
     
    p generate(0);

    qbasic, 08 Января 2011

    Комментарии (7)
  10. Ruby / Говнокод #5119

    −110

    1. 001
    2. 002
    3. 003
    4. 004
    5. 005
    6. 006
    7. 007
    8. 008
    9. 009
    10. 010
    11. 011
    12. 012
    13. 013
    14. 014
    15. 015
    16. 016
    17. 017
    18. 018
    19. 019
    20. 020
    21. 021
    22. 022
    23. 023
    24. 024
    25. 025
    26. 026
    27. 027
    28. 028
    29. 029
    30. 030
    31. 031
    32. 032
    33. 033
    34. 034
    35. 035
    36. 036
    37. 037
    38. 038
    39. 039
    40. 040
    41. 041
    42. 042
    43. 043
    44. 044
    45. 045
    46. 046
    47. 047
    48. 048
    49. 049
    50. 050
    51. 051
    52. 052
    53. 053
    54. 054
    55. 055
    56. 056
    57. 057
    58. 058
    59. 059
    60. 060
    61. 061
    62. 062
    63. 063
    64. 064
    65. 065
    66. 066
    67. 067
    68. 068
    69. 069
    70. 070
    71. 071
    72. 072
    73. 073
    74. 074
    75. 075
    76. 076
    77. 077
    78. 078
    79. 079
    80. 080
    81. 081
    82. 082
    83. 083
    84. 084
    85. 085
    86. 086
    87. 087
    88. 088
    89. 089
    90. 090
    91. 091
    92. 092
    93. 093
    94. 094
    95. 095
    96. 096
    97. 097
    98. 098
    99. 099
    100. 100
    require "date"
    #Конвертируем массив цифр в двухмерный масив для отображения
    def get_numbers(numbers)
      output = []
      one = [["-","-","-","*","*"],["-","-","*","-","*"],["-","*","-","-","*"],["*","-","-","-","*"],["-","-","-","-","*"],["-","-","-","-","*"],["-","-","-","-","*"]]
      two = [["*","*","*","*","*"],["-","-","-","-","*"],["-","-","-","-","*"],["*","*","*","*","*"],["*","-","-","-","-"],["*","-","-","-","-"],["*","*","*","*","*"]]
      three = [["*","*","*","*","*"],["-","-","-","-","*"],["-","-","-","-","*"],["*","*","*","*","*"],["-","-","-","-","*"],["-","-","-","-","*"],["*","*","*","*","*"]]
      four = [["*","-","-","-","*"],["*","-","-","-","*"],["*","-","-","-","*"],["*","*","*","*","*"],["-","-","-","-","*"],["-","-","-","-","*"],["-","-","-","-","*"]]
      five = [["*","*","*","*","*"],["*","-","-","-","-"],["*","-","-","-","-"],["*","*","*","*","*"],["-","-","-","-","*"],["-","-","-","-","*"],["*","*","*","*","*"]]
      six = [["*","*","*","*","*"],["*","-","-","-","-"],["*","-","-","-","-"],["*","*","*","*","*"],["*","-","-","-","*"],["*","-","-","-","*"],["*","*","*","*","*"]]
      seven = [["*","*","*","*","*"],["-","-","-","-","*"],["-","-","-","*","-"],["-","-","*","-","-"],["-","*","-","-","-"],["*","-","-","-","-"],["*","-","-","-","-"]]
      eight = [["*","*","*","*","*"],["*","-","-","-","*"],["*","-","-","-","*"],["*","*","*","*","*"],["*","-","-","-","*"],["*","-","-","-","*"],["*","*","*","*","*"]]
      nine = [["*","*","*","*","*"],["*","-","-","-","*"],["*","-","-","-","*"],["*","*","*","*","*"],["-","-","-","-","*"],["-","-","-","-","*"],["*","*","*","*","*"]]
      zero = [["*","*","*","*","*"],["*","-","-","-","*"],["*","-","-","-","*"],["*","-","-","-","*"],["*","-","-","-","*"],["*","-","-","-","*"],["*","*","*","*","*"]]
      seperator = [["-","-","-","-","-"],["-","*","-","*","-"],["-","-","-","-","-"],["-","-","-","-","-"],["-","-","-","-","-"],["-","*","-","*","-"],["-","-","-","-","-"]]
      for i in numbers
        case i
          when "0"
            output += [zero]
          when "1"
            output += [one]
          when "2"
            output += [two]
          when "3"
            output += [three]
          when "4"
            output += [four]
          when "5"
            output += [five]
          when "6"
            output += [six]
          when "7"
            output += [seven]
          when "8"
            output += [eight]
          when "9"
            output += [nine]
          when ":"
            output += [seperator]
        end
      end  
      return output
    end
    #Получаем массив с текущим временем
    def get_time
      t = Time.new
      if t.hour.between?(0,9)
        hour = "0" + t.hour.to_s
      else
        hour = t.hour.to_s
      end
      if t.min.between?(0,9)
        min = "0" + t.min.to_s
      else
        min = t.min.to_s
      end
      if t.sec.between?(0,9)
        sec = "0" + t.sec.to_s
      else
        sec = t.sec.to_s
      end
      time = [hour[0],hour[1],":",min[0],min[1],":",sec[0],sec[1]]
    end
    
    #Рисуем с заменой символов на в
    def display_time(symbols = {:star => "0", :line => " "})
      color_taf = 0
      color_tab = 7
      loop do
    	#Для очитки экрана в UNIX
    	if RUBY_PLATFORM == "i386-mingw32" then
    	  system("cls")
    	else
    	  system("tput reset")
    	end
    	#Цвет и фон
        #system("tput setaf #{color_taf}")
        #system("tput setab #{color_tab}")
        m = get_numbers(get_time)
        #Посимвольная прорисовка
        for j in 0..6
          for i in 0..m.size-1
            for z in m[i][j]
              case z
                when "*"
                  print symbols[:star]
                when "-"
                  print symbols[:line]
                #sleep(0.01) Для просмотра прорисовки
              end
            end
            print " "
          end
          print "\n"
        end
        sleep(1)
      end
    end
    #Рисуем
    display_time :star => "0", :line => " "

    Фух... урезал до 100 строк :)

    naker, 30 Декабря 2010

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