A sorting algorithm for sorting by "hotness", roughly based on Reddit's algorithm with a few tweeks.
scope :order_by_hot, ->
{ order("round((votes_count - 1) / POW(DATE_PART('day', Now() - created_at) * 24 + DATE_PART('hour', Now() - created_at) + 2, 1.5)::numeric, 8) DESC, votes_count DESC") }