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

    −110

    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
    columns.each do |c|
            case c
            when 'Device'
              h << c
            when 'Usage'
              h << c
            when 'Status'
              h << c
            when 'Battery'
              h << c
            when 'GPS status'
              h << c
            when 'Wi-Fi status'
              h << c
            when 'Temperature'
              h << c
            when 'Alerts'
              h << c
            end
          end

    случайно вот родил )

    Dreamfall, 23 Декабря 2010

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

    −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
    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
    #!/usr/bin/ruby1.8
    
    require 'mysql'
    $KCODE = 'UTF8'
    
    class Country
      @@country = Array.new
      @@insert_query = String.new
      @@db = Mysql
    
      def initialize(filename)
        file = File.open(filename)
        while !file.eof?
          value, index = file.readline.split(/\s+/u)
          @@country[index.to_i] = value.to_s
        end
        file.close
      end
    
      def database_connect
        @@db = Mysql.new('localhost','username','userpass','userdatabase')
        begin
          @@db.query("SET NAMES utf8")
        rescue
          puts @@db.error
        end
      end
    
      def create_query
        begin
          result = @@db.query("SELECT * FROM table")
        rescue
          puts @@db.error
        end
        result.each_hash do |field|
          @@country.each_index do |index|
          @@insert_query += "UPDATE table SET position = #{index} WHERE caption = '#{field['caption']}';" if @@country[index] == field['caption']
          end
        end
      end
    
      def execute_query
        begin
          @@insert_query.split(/;/u).each { |query| @@db.query(query) }
          puts "result: #{@@db.errno}" if @@db.errno
        rescue
          puts @@db.error
        end
      end
    
      def database_disconnect
        @@db.close
      end
    end
    
    cnt = Country.new('country.txt')
    # connect to DB
    cnt.database_connect
    # construct query
    cnt.create_query
    # execute constructed query
    cnt.execute_query
    # close connect
    cnt.database_disconnect

    Ну можно же как-то сделать лучше?

    avastor, 19 Декабря 2010

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

    −98

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    def non_blank_attrs_amount
        return_value = 4
        return_value = return_value + 1 if (!country.blank?)
        return_value = return_value + 1 if (!address.blank?)
        return_value = return_value + 1 if (!phone.blank?)
        return_value = return_value + 1 if (!email.blank?)
        return_value = return_value + 1 if (!skype.blank?)
        return_value = return_value + 1 if (!site.blank?)
        return_value = return_value + 1 if (!comment.blank?)
        return_value.to_s
      end

    Dreamfall, 13 Декабря 2010

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

    −111

    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
    def get_line_from_file(path, line)
      result = nil
    
      File.open(path, "r") do |f|
        while line > 0
          line -= 1
          result = f.gets
        end
      end
    
      return result
    end
    
    get_line_from_file("/tmp/foo.txt", 20)

    (с) stackoverflow.com

    Nakilon, 25 Октября 2010

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

    −155

    1. 1
    2. 2
    3. 3
    4. 4
    @image = (image unless image.nil?) or 
             (Rubygame::Surface.autoload(image_file) unless image_file.nil?) or 
             (Rubygame::Surface.autoload("#{@name}.png") unless @name.nil?) or 
             Rubygame::Surface.new([16, 16])

    (c) http://stackoverflow.com/questions/3690508

    Nakilon, 11 Сентября 2010

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

    −108

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    self.values.each do |v|
          if v.is_a? Hash
            v.recursively_symbolize_keys!
          elsif v.is_a? Array
            v.recursively_symbolize_keys!
          end
    end

    Замечательная логика из одного сниппета :)

    smileart, 10 Сентября 2010

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

    −96

    1. 1
    2. 2
    3. 3
    4. 4
    accounts=[]
    clients_accounts.each_key do |key|
       accounts.push key
    end

    vlad-druzh, 12 Августа 2010

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

    −104

    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
    i = -1
    ans = threes.map do |s|
      i+= 1
      n = s.to_i
      next if n == 0
      if i == 0
        nums[n]
      elsif i == 1
        # тысячи
        e = n % 10
        d = n % 100
        suff = ok_z[e]
        suff = ok_z[0] if d > 10 and d < 20
        t = nums[n]
        if e == 1 or e == 2 and not (d > 10 and d < 20)
          # один и два перед тысячами меняются.
          # не регексп, чтобы работал и юникод и однобайтные кодировки
          t = " " + t + " "
          t = t.sub(" один "," одна ").sub(" два "," две ")
          t = t[1..99].chop
        end
        t + (n!=0 ? " " : "") + threes_names[i-1] + suff
      else
        e = n % 10
        d = n % 100
        suff = ok_m[e]
        suff = ok_m[0] if d > 10 and d < 20
        nums[n] + (n!=0 ? " " : "") + threes_names[i-1] + suff
      end
    end.reverse.compact.join(" ")
     
    puts ans

    evrial, 08 Августа 2010

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

    −105

    1. 1
    rhour=hour[0].to_s+hour[1].to_s+':'+hour[2].to_s+hour[3].to_s;

    нужна была сортировка по времени, я сначала поубивал : потом надо отобразить в норм виде.. получилось это

    homakov, 01 Августа 2010

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