Archive for August, 2010

27th August
2010
written by simplelight

I was reading an interesting article on the possibility of hyperinflation in the US. It had an interesting take on the discontinuity between inflation and hyperinflation:

Inflation is when the economy overheats: It’s when an economy’s consumables (labor and commodities) are so in-demand because of economic growth, coupled with an expansionist credit environment, that the consumables rise in price. This forces all goods and services to rise in price as well, so that producers can keep up with costs. It is essentially a demand-driven phenomena.

Hyperinflation is the loss of faith in the currency. Prices rise in a hyperinflationary environment just like in an inflationary environment, but they rise not because people want more money for their labor or for commodities, but because people are trying to get out of the currency. It’s not that they want more money—they want less of the currency: So they will pay anything for a good which is not the currency.

25th August
2010
written by simplelight

When you’re debugging/analyzing MySQL queries in the Rails console, it helps to turn on ActiveRecord logging:

#Enable ActiveRecord logging
def loud_logger(enable = true)
  logger = (enable == true ? Logger.new(STDOUT) : nil)
  ActiveRecord::Base.logger = logger
  ActiveRecord::Base.clear_active_connections!
end
11th August
2010
written by simplelight

collect {|item|block} and map{|item|block} do the same thing – return an array of things returned by the block.  This is different from returning specific items in the collection being iterated over.

Which leads to select.

select{|item|block} will return actual collection items being iterated over if, for each item, the block condition evaluates to true. Not the same as returning what the block, itself, may return.  In the case of select, the block would always return an instance of class TrueClass or FalseClass.  Typically, [true, false, ..., true] is not what you’re looking for in your resulting array.

Slightly modifying the core RDoc example:

a = ["a", "b", "c", "d"]      #=> ["a", "b", "c", "d"]
a.map {|item|"a" == item}     #=> [true, false, false, false]
a.select {|item|"a" == item}  #=> ["a"]