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

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 append_card(cards, new_card)
      if cards.nil?
        new_card == GameEvent::YELLOW_CARD ? 'yellow' : 'red'
      elsif cards == 'yellow'
        new_card == GameEvent::YELLOW_CARD ? 'two_yellow' : 'yellow_red'
      elsif cards == 'red'
        new_card == GameEvent::YELLOW_CARD ? 'yellow_red' : 'red'
      elsif cards == 'two_yellow'
        'two_yellow'
      elsif cards == 'yellow_red'
        new_card == GameEvent::YELLOW_CARD ? 'two_yellow' : 'yellow_red'
      end 
    end

ничего особенного, просто подсчитываем, какую карточку получил игрок футбольной команды.
а я думал, что что-то понимаю в футболе... я никогда в жизни так не ошибался

iHateBidlocod iHateBidlocod, (Updated )

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

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

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
  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
  84. 84
  85. 85
  86. 86
  87. 87
  88. 88
  89. 89
  90. 90
  91. 91
  92. 92
  93. 93
  94. 94
  95. 95
  96. 96
  97. 97
  98. 98
  99. 99
  100. 100
# Да, да, захардкоженные id! 
# .where(id: [id_arrays]) ? Не, не слышал
@cities = [52, 21, 9, 18, 196, 27, 106, 4, 40, 71].collect { |c| City.find(c) }

# Это все в одном экшене, ага.
    session[:latitude] = params[:my_latitude]
    session[:longitude] = params[:my_longitude]
    session[:my_address] = params[:my_address]
    session[:fuel] = params[:fuel][:fuel_id]
    session[:range] = params[:station][:range]

# А потом кто-нибудь развернет базу из бэкапа без сохранения первичных ключей и все перестанет работать.
@fuels = Fuel.where(:id=>[1, 2, 3, 5])

# Типичный экшен
    session[:view_sub_page] = action_name
    id = params[:station_chain].split("-")
    s_id = id[id.size - 2]
    station = Station.where(:id=>s_id)
    @fuels_level = AppUtils.calculate_price(station)
    @prices = station.last.prices.order("created_at").group_by { |item| item.fuel_id }
    @fuel_id = id[id.size - 1].to_i
    @station_lists = Station.get_station_detail_map(station, @fuels_level, @fuel_id, @prices)
    @station = station.last
    @station_logo = ''
    @station_logo_chain = ManageStationChain.where(:brand_id=>@station.brand_id).last
    @station_logo = PromoLogo.find_by_station_id(@station.id)
    @end = @station.address
    @fuels = Fuel.where(:id=>[1, 2, 3, 5])
    @sub_station = ""
    @cities = Station.get_static_cities()

# Какие еще Rails, у меня свой лисопед
  def City.find_by_name(name)
    city = City.where("name = ?", name).first

    if city.nil?
      city = City.new
      city.name = name
      city.save
    end
    return city
  end

# Именно так, в одну строчку. station.open_time и close_time - типа :time в базе
if !station.open_time.nil? and !station.close_time.nil? and (Time.parse(station.open_time.to_s)...Time.parse(station.close_time.to_s)).cover?(Time.now.utc.change(year: 2000, month: 1, day: 1, hour: Time.now.hour, min: Time.now.min, second: 0)) == false
        return "PRICE_LEVEL_CLOSE"
  end

# Компьютер купил, программировать не купил
# В таблице Points - тысячи записей
def get_points
    points = Points.all
    render json: {:success => true, :data => {:points => points.as_json(:only => [:action, :points, :points_new])}} and return
  end

# И под занавес - код логина
# Гемы? Devise? OAuth? А чой энта?
def login
    register = false
    url = "https://graph.facebook.com/me/?access_token="+params[:facebook_token]
    uri = URI.parse(url)
    http = Net::HTTP.new(uri.host, uri.port)
    http.use_ssl = true
    request = Net::HTTP::Get.new(uri.path + "?" + uri.query)
    response = http.request(request)
    if response.code == "200"
      facebook_response = JSON.parse(response.body)
      user = User.where("facebook_id = ?", facebook_response["id"]).first
      if !user
        user = User.new
        user.facebook_id = facebook_response["id"]
        user.nick = facebook_response["username"]
        user.email = facebook_response["email"]
        register = true
      end
      user.email = facebook_response["email"]
      user.generate_token
      user.save
      if register == true
        history = History.new
        history.user = user
        points = Points.where(:action => "REGISTER").first
        history.points_action = points
        history.points = points.points
        user.points+=points.points
        user.save
        history.save
      end
      logger.debug("Calculating point");
      points = Points.where('action != ?', 'FACEBOOK_INVITES')
      logger.debug(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
      logger.debug("Testing for points");
      logger.debug(points.as_json(:only => [:action, :points]))
      logger.debug(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
      if user.disabled == true
        render json: {:success => false, :error => {:message => "Invalid facebook token", :error_code => "INVALID_TOKEN"}}, status: :unauthorized and return
      else
        render json: {:success => true, :data => {:auth_token => user.auth_token, :points => points.as_json(:only => [:action, :points])}} and return# 
...

Почему никогда нельзя нанимать индусских программистов. Выдержки из избранного.

deadleaves1985 deadleaves1985, (Updated )

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

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

0

  1. 1
deals = Deal.joins(:deal_locations).select("deals.id, (SELECT array(SELECT category_id FROM deal_categories WHERE deal_id = deals.id ORDER BY category_id ASC)) AS category, deals.start_date, deals.end_date, deals.address, deals.theme, deals.alias, deals.metro, deals.district, deals.discount, deals.coupon_count, deals.issued_coupons, deals.main_image, count(*) OVER() AS total_count, trunc(abs(extract(epoch FROM age(deals.end_date, clock_timestamp()))/86400)) AS days_left").where("deal_locations.deal_id = deals.id AND deal_locations.location_id = ? AND deals.category_id IN (#{categories[0...-2]}) AND deals.id NOT IN (#{ex_deals.map{|e| e}.join(", ")})", params[:location].to_i).active.in_stock.limit(limit).offset(offset).order("deals.start_date desc")

Rails. Да, да, активрекорд, я помню о тебе.

adastreamer adastreamer, (Updated )

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

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

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
class Category < ActiveRecord::Base
  acts_as_nested_set
  ...
  def self.only_roots
    self.all.select { |c| c == c.root }
  end
end

https://github.com/collectiveidea/awesome_nested_set/wiki/Awesome-nested-set-cheat-sheet#advanced-usage
#root осилил..

.roots напрашивается и без доки, хз что в голове творится у таких писателей

podsel_na_legacy podsel_na_legacy, (Updated )

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

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

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
def get_team_choices_with_index
    school_ids = params[:school_id].split(",")
    @index = params[:index]

    @teams_array = Array.new
    school_ids.each do |s|
      next if s.eql? "0"
      School.find(s).teams.each do |t|
        @teams_array << t
      end
    end

    @teams_array.flatten!
    @teams_array
  end

А должно быть что-то вроде
@teams_array = Team.where(school_id: school_ids)

dj_Andreus dj_Andreus, (Updated )

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