1. Список говнокодов пользователя sumskyi

    Всего: 6

  2. Ruby / Говнокод #13440

    −165

    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
    def check_dates
        if !start_on.nil? && !end_on.nil? && start_on > end_on
          errors.add(:base, 'The first month cannot be after the last month.')
          return false
        end
        is_admin_user = User.has_level?('admin')
        if confirmed_at.nil? && !start_on.nil? && !is_admin_edit? && !is_admin_edit_revision?
          d = Date.current_date
          if is_newsletter?
            if !is_admin_user && (d.year > start_on.year || (d.year == start_on.year && d.month > start_on.month))
              errors.add(:base, 'The first month has already passed.')
              return false
            end
            if !office_id.nil?
              office = Office.find_by_id(office_id)
              deadline = office.deadline(start_on.year, start_on.month)
              if !is_admin_user && d > (deadline + Order::PastDeadlineLimit)
                errors.add(:base, "The #{office.name} office deadline for this month has already passed.")
                return false
              end
              if is_design_only?
                original = get_original_order
                if start_on < original.start_on
                  errors.add(:base, 'The first month cannot be before the first month of the original order.')
                  return false
                end
                if start_on > original.end_on
                  errors.add(:base, 'The first month cannot be after the last month of the original order.')
                  return false
                end
              end
    
              validate_adjusted_order
            end
          else
            if new_record? && !is_admin_user
              if d.year > start_on.year
                errors.add(:base, 'The year has already passed.')
                return false
              end
            end
            if !is_admin_user && !ads.empty? && 1 == ads.map(&:neighborhood_id).uniq.size
              if directory && directory.finalized? && d > (directory.finalized_on + Order::PastDeadlineLimit)
                errors.add(:base, 'The directory has already been finalized.')
                return false
              end
            end
          end
        end
        if is_admin_edit?
          original = get_original_order
          if months < original.publication_month_with_receipt_span
            errors.add(:base, 'The order already has more paid months than the new contract length.')
          end
        end
      end

    sumskyi, 17 Июля 2013

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

    −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
    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
    module ModelHelper
      extend ActiveSupport::Concern
    
      module InstanceMethods
    
        def prepare_url
          "http://#{Banjo::Application.config.short_url_host}"
        end
    
        def adjust_comment(text, url, max_len)
          maximum_text_length = max_len - url.length - 1
          if text.length > maximum_text_length
            text = text[0, maximum_text_length - 3] + "..."
          end
          if url.present?
            message = [text, url].join(' ')
          else
            message = text
          end
          message
        end
    
        def fullname_to_first_last_initial(fullname)
          name_token = fullname.split(/ /)
          last_initial = (name_token.length > 1) ? name_token.pop.first : nil
          first = name_token.join(' ')
          return (last_initial.nil?) ? first : "#{first} #{last_initial}"
        end
    
      end
    
      module ClassMethods
    
        def adjust_comment(text, url, max_len)
          maximum_text_length = max_len - url.length - 1
          if text.length > maximum_text_length
            text = text[0, maximum_text_length - 3] + "..."
          end
          if url.present?
            message = [text, url].join(' ')
          else
            message = text
          end
          message
        end
    
        def fullname_to_first_last_initial(fullname)
          name_token = fullname.split(/ /)
          last_initial = (name_token.length > 1) ? name_token.pop.first : nil
          first = name_token.join(' ')
          return (last_initial.nil?) ? first : "#{first} #{last_initial}"
        end
    
      end
    
    end

    DRY principle in action

    sumskyi, 09 Декабря 2011

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

    −99

    1. 1
    2. 2
    3. 3
    4. 4
    respond_with_error("Lat can't be blank.", :unprocessable_entity) and return if params[:lat].blank?
        respond_with_error("Lon can't be blank.", :unprocessable_entity) and return if params[:lon].blank?
        respond_with_error("Lat is not a number.", :unprocessable_entity) and return if !is_float?(params[:lat])
        respond_with_error("Lon is not a number.", :unprocessable_entity) and return if !is_float?(params[:lon])

    индусский кот от Фет Фрумоса

    sumskyi, 25 Мая 2011

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

    −106

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    def parse_response(object)
        return Hashie::Mash.new(JSON.parse(object))
      rescue => e
        #should handle here different error types/levels or else throw the exceptions to the upper layer (client)
        if e.is_a?(JSON::ParserError) && e.message =~ /<html>/
          raise "Invalid response from Platform server - #{self.class.parse_json_error(response.body)}"
        else
          raise e
        end
      end

    sumskyi, 10 Мая 2011

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