Fixing corrupt position in acts_as_list

When there is no uniqueness in mysql, things can go wrong….so we fix em…

module ActsAsList
  # positions can get mixed up when users click like crazy -> reorder them if necessary
  # ActsAsList.reorder_positions!(current_user.categories)
  def self.reorder_positions!(objects)
    objects.each_with_index do |object, index|
      new_position = index + 1
      next if object.position == new_position
      object.update_attributes(:position => new_position)
    end
  end
end

sh without rake

Just built this little sh script, that can be used when rake is not installed (we use it to setup a new/clean system)

def sh(cmd)
  puts cmd
  IO.popen(cmd) do |pipe|
    while str = pipe.gets
      puts str
    end
  end
  $?.success?
end