Яuбy / Говнокод #23398 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
def with_batched_ids(count, ids)
  if ids.is_a? Array
    if ids.length > 1
      ids.each_slice(count) do |ids|
        yield(ids)
      end
    else
      yield(ids)
    end
  else
    yield(ids)
  end
end

Заshitное программирование и просто красивая портянка из yield - end - else. Как на ровном месте придумать целый метод.

strax strax, (Updated )

Комментарии (1, +1)

Яuбy / Говнокод #23386 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
Руби говно на всей Земле
Руби говно другим во благо
Не за красивое "спасибо"
А за хорошее бабло

inho inho, (Updated )

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

Яuбy / Говнокод #23078 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
def self.allowed_symbols
  @allowed_symbols ||= (('A'..'Z').to_a + (0..9).to_a).shuffle
end

def self.forbidden_symbols_regexp
  @allowed_symbols_regexp ||= Regexp.new("[^#{allowed_symbols.join}]")
end

Проверка формата промокода

atipugin atipugin, (Updated )

Комментарии (1, +1)

Яuбy / Говнокод #22692 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
(params[:date_lte].present? && params[:date_gte].present?) ?
        @events = CalendarEvent.where(:publication_date.gte => DateTime.parse(params[:date_gte]),
                                      :publication_date.lte => DateTime.parse(params[:date_lte]) + 23.hours + 59.minutes) :
        @events = CalendarEvent.order(publication_date: :desc).limit(6)

Божественное использование тернарного оператора

maxk maxk, (Updated )

Комментарии (3, +3)

Яuбy / Говнокод #22524 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  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
def check_web_property(file_folder_id)
    folder_for_updated_files = FileFolder.find file_folder_id
    # min_to_be_active = folder_for_updated_files.min_properties_to_be_active
    process_uniq_id = SecureRandom.urlsafe_base64(30)
    min_web_property = folder_for_updated_files.min_web_property_check
    max_web_property = folder_for_updated_files.max_web_property_check
    #puts "update ad_groups with given inventory limit to Previus Inventory = nil "
    self.ad_groups.and( { "Inventory" => {'$gte' => folder_for_updated_files.min_web_property_check}}, {"Inventory" =>{'$lte' => folder_for_updated_files.max_web_property_check}}).update_all( "Previus Inventory" => nil, :update_complited => "no")
    #PpcBuild.last.ad_groups.and( { "Previus Inventory" =>{'$gte' => 1}}, {"Previus Inventory" =>{'$lte' => 8 } }).count

    puts "select ad_groups with given inventory limit"
    selrcted_ad_groups = self.ad_groups.and( { "Inventory" =>{'$gte' => folder_for_updated_files.min_web_property_check}}, {"Inventory" =>{'$lte' => folder_for_updated_files.max_web_property_check } })

    count_selected_ad_groups_for_processing = selrcted_ad_groups.count

    selrcted_ad_groups.no_timeout.each do |ad|
      if !self.uniq_urls.where("Landing Page"=> ad["Landing Page"], process_id: process_uniq_id).exists?
        new_url = UniqUrl.new("Landing Page"=> ad["Landing Page"], process_id: process_uniq_id, ppc_build_id: self.id)
        new_url.save
      end
    end
    all_uniq_url_selected = self.uniq_urls.where(process_id: process_uniq_id)
    elemetns_count = 0
    all_uniq_url_selected.no_timeout.each do |uniq_url|
      ad = AdGroup.find_by("Landing Page" => uniq_url["Landing Page"], ppc_build_id: self.id)
      ad_parameters = { "Landing Page" => uniq_url["Landing Page"], ppc_build_id: self.id.to_s }

      UpdateDataFromWebSite.perform_async(ad_parameters, process_uniq_id)

      min_to_be_active = ad.min_for_ad_group_to_be_active
      elemetns_count +=1

      ad.web_update_inventory(ad.id.to_s, process_uniq_id, min_to_be_active)
      if elemetns_count == 20
        sleep 0
        elemetns_count = 0
      end
      ad.update_attributes("Previus Inventory" => ad["Inventory"])
      ad.push(process_id: process_id)
      url = ad["Landing Page"]
      uri = URI(url)
      use_ssl = true
      http = Net::HTTP.new(uri.host, uri.port)
      http.use_ssl = use_ssl
      http.read_timeout = 20
      http.open_timeout = 20

      resp = http.start() { |http| http.get(uri.path) }

      body = resp.body
      page = Nokogiri::HTML(body)
      if !page.css('.results-count').empty?
      new_property = page.css('.results-count').first.text
      property_number = new_property[/(?<=of\s)?\d{1,}\D?\d?{1,}/]

      if property_number
      ad.update_attributes("Inventory" => new_property.gsub(/\s+/, ' ')[/(?<=of\s)?\d{1,}\D?\d?{1,}/].strip)

      else
      ad.update_attributes("Inventory" => "0")
      end
      else
      ad.update_attributes("Inventory" => "0")
      end
      ad.update_attributes("Status" => get_status(ad["Inventory"], min_to_be_active), update_complited: "yes")
    end

Пример метода из ruby класса содержащего 890 строк

gururuby gururuby, (Updated )

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