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

    Всего: 3

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

    −55

    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
    module CoreExt; module Array
    
      # Check if all array members are instances of given class(es).
      #
      # @return [Boolean]
      # @param [Array, Class] klasses_allowed Array of classes, or a single class
      # @note Returns <tt>true</tt> if the array is empty.
      def is_array_of?(klasses_allowed)
        if klasses_allowed.kind_of? Array
          fail ArgumentError, "Array of Classes expected. Some members are not instances of Class." \
            unless klasses_allowed.is_array_of?(Class)
        elsif klasses_allowed.kind_of? Class
          klasses_allowed = [klasses_allowed]
        else
          fail ArgumentError, "Class or array of classes expected, #{klasses_allowed.class.name} given"
        end
        return true if self.empty?
        self.map(&:class).uniq.reject{ |klass| klasses_allowed.include?(klass) }.empty?
      end
    
    
      # @note Sums array members.
      #
      # @return [nil] If source array contains non-numeric values.
      # @return [Fixnum, Integer, Float]
      def sum
        return nil unless self.is_array_of? [Integer, Float, Fixnum]
        self.inject(0) { |sum, value| sum + value }
      end
    
    
      # Boil down values proportionally, to make their sum equal to <tt>target_sum</tt>.
      #
      # @param [Fixnum] target_sum
      # @return [Array] Array of pairs [old value, new_value].
      def reduce_to_sum(target_sum)
        current_sum = self.sum
        gap = current_sum - target_sum
        if gap < 0
          return nil
        elsif gap == 0
          return self.collect { |value| [value, value] }
        else
          reduced = 0
          result = self.collect do |value|
            x = (gap * value) / current_sum # Floats round here
            reduced += x
            [value, value - x]
          end
          # Second pass, as target sum is not reached yet due to rounding of floats
          (gap - reduced).times { |i| result[i][1] -= 1 }
          result
        end
      end
    
    end; end
    
    
    if defined? Array
      Array.class_eval do
        include CoreExt::Array
      end
    end

    https://github.com/gorodulin/assemblr/blob/master/lib/core_ext/array.rb

    cancerogen, 27 Мая 2016

    Комментарии (48)
  3. JavaScript / Говнокод #9769

    +155

    1. 1
    2. 2
    var len = final_amount.length;
    var final_amount_formatted = (final_amount == "" ? "0" : final_amount.substring(0,len-2) + '.' + final_amount.substring(len-2, len));

    cancerogen, 26 Марта 2012

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

    −102

    1. 1
    Money.new(v[:amount].gsub('.','').to_i)

    а вы умеете так переводить баксы в центы?

    cancerogen, 26 Марта 2012

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