record_activities Rails Plugin for Activity Logging in 16LOC

Since most activity logging solutions out there are either complex or require controller hacking i based this new dead-simple activity logging plugin on userstamps.

Thats 16LOC for complete activity logging

Record Activities Rails plugin


class Comment < ActiveRecord::Base
  stampable
  record_activities #same as record_activities  :create, :update
end
Comment.create! -> Activity(:subject=>comment,:actor=>current_user,:action=>'create')


Grabbing Zen and the Art of Motorcycle Maintenance

I just found “Zen and the Art of Motorcycle Maintenance” for free online, a book that was on my wish list for quiet some time (recommended by a good number of programmers…).

And since i like a printed version here is a small script to get it in a printable format.
(which i post here for educational purpose only)

require 'rubygems'
require 'open-uri'
require 'hpricot'

book = 'zen_and_the_art/zen_and_the_art'
pages = 32
text = ''
1.upto(pages) { |i|
  doc = Hpricot(open("http://www.esolibris.com/ebooks/#{book}_#{i.to_s.rjust(2,'0')}.php").read)
  doc.search('table.body tr td[@height=40] div').remove
  doc.search('table.body tr td[@height=40] img').remove
  doc.search('table.body tr td[@height=40] p.body').remove
  doc.search('table.body tr td[@height=40] p a').remove
  part = doc.search('table.body tr td[@height=40]')
  text += part.inner_html
}

File.open('out.html','w') {|f|f.puts text}

Alter Column the Missing Migration Method for ActiveRecord

Changing many columns is not so easy, because change_column forces you to enter all attributes you want (default,limit,null…) again.
So to make less errors we just alter the attributes we want to change and leave the rest alone.

Install

#Inside your migration
def self.alter_column(table,column,text)
  execute("ALTER TABLE #{quote_table_name(table)} ALTER #{quote_column_name(column)} #{text}")
end

Usage

# to set the default to nil, without remembering all the other 
# stuff change_column needs
alter_column(:users,:name,"DROP DEFAULT")

So thats very basic, but i hope it helps anyway 🙂