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

    −101

    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
    class CheckDatabaseYmlEncoding < ActiveRecord::Migration
      def self.up
        config   = Rails::Configuration.new
        ['development', 'production' ].each { |env|
          db_config = config.database_configuration[env];
          if db_config
            if db_config['encoding'] != 'utf8'
              msg = "please use encoding: utf8 in database.yml's #{env} configuration"
              Rails.logger.error(msg)
              raise msg 
            else
              Rails.logger.info("database.yml's #{env} configuration is using encoding: utf8. Good !" )
            end
          else
            Rails.logger.error("#{env} is missing in database.yml" )
          end
        }
    
      end
    
      def self.down
      end
    end

    Задорная миграция

    Fester, 27 Октября 2011

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

    −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
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    # Work fine only on call with has_many association
    def self.new_from_params options
      new_rule = Rule.new
      return nil if new_rule.project_id.nil?
    
      rule = Rule.find_by_id options[:rule_id]
      if rule.nil? or (new_rule.project.id != rule.project.id)
        rule = Rule.new
      end
    
      new_rule.rule_id = options[:rule_id]
      new_rule.users = (rule.users.to_a + options[:users].to_a).uniq
      new_rule.statuses = (rule.statuses.to_a + options[:statuses].to_a).uniq
      new_rule.tags = (rule.tags.to_a + options[:tags].to_a).uniq
      new_rule.grouped_by = options[:grouped_by].presence || rule.grouped_by.presence
      new_rule.sorted_by = options[:sorted_by].presence || rule.sorted_by.presence
      new_rule.search = options[:search].presence || rule.search.presence
      new_rule.period_start = options[:period_start].presence || rule.period_start.presence
      new_rule.period_end = options[:period_end].presence || rule.period_end.presence
    
      new_rule
     end

    emerald, 21 Октября 2011

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

    −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
    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
    def self.find_or_create params
      if params[:rule_id].present?
        rule = new_from_params params
        return nil if rule.nil?
        parent_rule = Rule.find_by_id params[:rule_id]
    
        if parent_rule and Rule.calc_md5(rule.to_hash) == parent_rule.crc
          parent_rule.rule_id = parent_rule.id
          parent_rule.grouped_by = rule.grouped_by
          parent_rule.sorted_by = rule.sorted_by
          parent_rule.save
          return parent_rule
        end
        rule_id = params.delete :rule_id
      end
    
      params = clear_and_sort params
      if (rule = Rule.find_by_crc(Rule.calc_md5(params))).present?
        rule.rule_id = rule_id
        rule.grouped_by = params[:grouped_by]
        rule.sorted_by = params[:sorted_by]
        rule.save
      else
        rule = new_from_params params.merge(:rule_id => rule_id)
        rule.save
      end
      rule
    end

    Метод модели, используется для поиска, создания и чего-то еще...

    emerald, 19 Октября 2011

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

    −147

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    {if $oUserProfile->getProfileIcq()}
    	<strong>{$aLang.profile_social_contacts}</strong>
    	<ul>
    	{if $oUserProfile->getProfileIcq()}
    		<li class="icq"><a href="http://www.icq.com/people/about_me.php?uin={$oUserProfile->getProfileIcq()|escape:'html'}" target="_blank">{$oUserProfile->getProfileIcq()}</a></li>
    	{/if}					
    	</ul>
    {/if}

    Smarty-шаблон. ActionProfile/sidebar.tpl (17-я строчка в скине "new") из LiveStreet.
    Озадачивают 1-я и 4-я строки. Типа: "А вдруг?!"

    alexoy, 17 Октября 2011

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

    −94

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    def format_price price, delimeter = ' '
      s, i = price.to_s.reverse, 0
      Array.new(s.size) do |n|
        c = n.zero? ? '' : ((i += 1) % 3).zero? ? delimeter.to_s : ''
        c + s[n, 1]
      end.join.reverse
    end

    10000 -> "10 000"
    Как такое вообще принято делать между ровными пацанами?

    LeshaXakir, 14 Октября 2011

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

    −93

    1. 1
    2. 2
    3. 3
    4. 4
    def properties
      Hash.send :[], *(self.class.column_names & self.class::PROPERTIES).
        inject([]) { |a, p| a << p.to_sym << send(p) }
    end

    это же очевидно

    LeshaXakir, 29 Сентября 2011

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

    −107

    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
    while 2 > 1 do
    			@command = io.gets();
    			case @command 
    				when 'version' 
    					puts('0.01 Alpha for developers SUPIRPUPIRSIKRIT');
    				when 'register, #{@arg}'
    					@name = @arg;
    					@name = User.new;
    					@name.register;
    					@name = '';
    					@arg ='';
    				when 'login, arg '
    					@user = @arg;
    					@user.login;
    					@user = '';
    				when 'quit'
    					server.shutdown;
    				else
    					puts(@command);
    			end 
    		end

    Извиняюсь за мультипост.
    P.S.: как здесь удалять посты?

    urm, 26 Сентября 2011

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

    −103

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    @name = @arg;
    @name = User.new;
    @name.register;
    @name = '';
    @arg ='';
    @user = @arg;
    @user.login;
    @user = '';

    Вырезан наиболее эпичный фрагмент кода

    urm, 26 Сентября 2011

    Комментарии (6)
  9. 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)
  10. 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)