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

    −105

    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
    def show
        @updates = UpdateList.new
        update_id = params[:update_id]
    
        if 'twitter' == @provider_key
          provider_api = ProviderApi::Twitter.new(current_user)
    
          if update_id.present?
            begin
              benchmark(" Twitter API: status") do
                @api_response = provider_api.status(update_id)
              end
              @update = update = SocialUpdate.from_twitter_response(@api_response, true)
              while update && (in_reply_to = update.in_reply_to_update_id)
                benchmark(" Twitter API: status") do
                  @previous_status = provider_api.status(in_reply_to)
                end
    
                if error = @previous_status['error']
                  @updates << SocialUpdate.from_twitter_error(error)
                  break
                else
                  update = SocialUpdate.from_twitter_response(@previous_status, true)
                  @updates << update
                end
              end
            rescue => e
              logger.info("Error in fetching status #{in_reply_to || update_id}: #{e}")
            end
          end
        end
    
        @update.flag_for_user(current_user) if @update
        @updates.flag_for_user(current_user)
      end

    sumskyi, 19 Сентября 2011

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

    −96

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    <%products = Array.new
      count = Product.count(:conditions => "novelty = 'true'")
      while products.size < 10 do
        products << Product.find(:first, :conditions => "novelty = 'true'",:offset => rand(count))
        products.uniq!
      end-%>

    при количестве новинок меньше 10 получаем бесконечный цикл. счастье в продакшене, там sql запросы не пишутся в лог)

    malleus, 13 Сентября 2011

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

    −113

    1. 1
    2. 2
    3. 3
    4. 4
    def a
    print rand(1)
    end
    puts a

    Попытался нагадить… короче, puts puts 0

    nbvec222, 10 Сентября 2011

    Комментарии (8)
  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. Ruby / Говнокод #7784

    −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
    begin
        # etc
      rescue Exception => e
        case e
          when LinkedIn::Unauthorized
            account.invalidate_token if !account.invalid_token?
            raise InvalidTokenException.new(account.primary, provider_name)
          when LinkedIn::InformLinkedIn, LinkedIn::Unavailable  #LinkedIn::Unavailable represents 502..503 error codes & LinkedIn::InformLinkedIn represent 500
            raise UnexpectedApiException.new(provider_name)
          else
            handle_api_exception(e, e.message)
        end
      end

    элегантный отлов ексепшнов

    sumskyi, 06 Сентября 2011

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

    −95

    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
    loop do
      client = server.accept
      otvet = []
    
      while line = client.gets
        otvet << line
         break if line == "\r\n"
      end
    
      client.print "HTTP/1.1 200/OK\n"
      client.print "Content-type: text/html\n\n"
      client.print '"<meta http-equiv="refresh" content="0; url=http://www.google.ru">"' # переадресация
      client.close
      puts otvet
      File.open('log.txt', 'a'){ |f| f.puts("#{otvet}")} # запись лога
    end

    творние юного кулхацкера

    wapoo!11, 26 Августа 2011

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

    −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
    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
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    def entities(model, params = {})
            @entities                 ||= {}
            @entities[model]    ||= []
    
            if @entities[model].blank? or parameters_changed?(model, params)
              @entities[model]  = []
              include           = params[:include]  || nil
              group             = params[:group]    || nil
              order             = params[:order]    || nil
              page              = params[:page]     || nil
              entity_ids        = []
              model_role        = nil
              model_class       = model.to_s.classify.constantize
    
              if self.has_role_for?(model_class)
                self.roles_for(model_class).uniq.each do |role|
                  if role.authorizable_id.blank?
                    raise "Authorization problem! Found more than one #{model_class} model permission!" unless model_role.blank?
                    model_role = role.name
                    next
                  end
    
                  if !role.authorizable_id.blank? && MerchantRole::MERCHANT_ROLES.include?(role.name)
                    entity_ids << role.authorizable.id
                  end
                end
    
                if entity_ids.blank? and MerchantRole::MERCHANT_ROLES.include?(model_role)
                  #WARNING! RECURSION! EVIL!
                  if MerchantRole.has_entity_parent?(model)
                    parent_model    = MerchantRole.entity_parent(model)
                    parent_entities = self.entities(parent_model)
                    unless parent_entities.blank?
                      _params = {
                        :conditions => conditions_and_parameters(params, nil, ["`#{model.to_s}`.`#{parent_model.to_s.singularize}_id` IN (?)", parent_entities.map(&:id)]),
                        :include => include,
                        :order => order,
                        :group => group
                      }
                      _params.merge!(:page => page) if params.keys.include?(:page)
                      if block_given?
                        (self.is_reseller? ? self.reseller.send(model) : model_class).each(_params) do |o|
                          yield o
                        end
                      else
                        @entities[model] = (self.is_reseller? ? self.reseller.send(model) : model_class).send(params.keys.include?(:page) ? :paginate : :find, :all, _params)
                      end
                    end
                  else
                    _params = {
                      :conditions => conditions_and_parameters(params, nil),
                      :include => include,
                      :order => order,
                      :group => group
                    }
                    _params.merge!(:page => page) if params.keys.include?(:page)
       
                    if block_given?    #Find only merchants associated with the reseller or all merchants if we are no reseller.
                      (self.is_reseller? ? self.reseller.send(model) : model_class).each(_params) do |o|
                        yield o
                      end
                    else
                      @entities[model] = (self.is_reseller? ? self.reseller.send(model) : model_class).send(params.keys.include?(:page) ? :paginate : :find, :all, _params)
                    end
                  end
                else
                  _params = { :conditions => conditions_and_parameters(params, nil, ["`#{model.to_s}`.`id` IN (?)", entity_ids]),
                                       :include => include,
                                       :order => order,
                                       :group => group }
                   _params.merge!(:page => page) if params.keys.include?(:page)
                   if block_given?
                     model_class.each(_params) do |o|
                       yield o
                     end
                   else
                     @entities[model] = model_class.send(params.keys.include?(:page) ? :paginate : :find, :all, _params)
                   end
                 end
               end
            end
         entities[@model]
       end

    This method does the following (you guessed it, right?):

    #Fetch entities for which we have a read permission.
    #This is now it should work:
    #1. : If we don't have any role on the model, we won't get anything.
    #2a.: Check roles we have for whole model. If no role for whole model we can only fetch instances we have assigned.
    #2b.: Check all instances we have a role for and store them.
    #3a.: We have roles for instances -> Goto(#7)
    #3b.: We have no instance roles but have a role for the whole model.
    #4. : Check recusively if we have roles fro a parent model (channels -> merchants).
    #5a.: If we have a parent role and got parent entities returned we only fetch instances belonging to the parent entities.
    #6a.: If we have a parent role and got no entities back, then we won't get anything since we are not supposed to.
    #7. : Get all instances based on our reseller or globally for the system.

    emilpetkov, 25 Августа 2011

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

    −95

    1. 1
    session[:mark == md5(Time.now)]

    это печально

    MaxD, 18 Августа 2011

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

    −96

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    module AuthenticatedSystem
    protected
    
    def logged_in?
      !!current_user
    end
    
    def current_user
      @current_user ||= login_from_session unless @current_user == false
      @current_user
    end

    bebesuk, 12 Августа 2011

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

    −98

    1. 1
    amount = ('-' + batch['settleAmount'].to_s).to_i

    работа с платежными системами требует вдумчивости и оригинальности.

    malleus, 07 Июля 2011

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