Thursday, December 27, 2007

If, Else, and Elsif Constructs

Too many if else statements can create confusion for ruby developers. If so better to refactor the code. Ruby is such an amazing object oriented language that this procedural garbage is the quickest way to ugly, unreadable code.

if you ever write something like this:
1
2
3
if my_object!= my_object_not
if my_object!= nil

If you wanna take the advantage of ruby use the following code for better readability

unless my_object== my_object_else
unless my_object.nil?

ActiveRecord partial updates

ActiveRecord updates all the columns when you save the object, without bothering to see if the column was changed or not.

Pratik Naik has given the solution for partial updates on changes.

http://m.onkey.org/2007/12/18/partial-updates

Make sure that you use optimistic locking.

Active Records support optimistic locking if the field lock_version is present. Each update to the record increments the lock_version column and the locking facilities ensure that records instantiated twice will let the last one saved raise a StaleObjectError if the first was also updated.

Thursday, December 20, 2007

Rails Plugins - Query Analyzer

The Query Analyzer plugin will expand the usability of your log files by providing query analysis using the MySQL query execution plan. Each SQL select query will be ‘EXPLAIN’ed and added to the log files right below the original query.

Installation

script/plugin install http://svn.nfectio.us/plugins/query_analyzer

Example Use

Refer to http://www.mysql.org/doc/refman/5.0/en/explain.html for more information on understanding the results.

http://www.rubyinside.com/columnized-text-datasets-in-rails-71.html http://habtm.com/articles/2006/06/10/pretty-tables-for-ruby-objects


Wednesday, December 19, 2007

Latest bug fixes for ruby pdf-writer 1.1.4

* Better memory footprint for PDF::SimpleTable
* Fixed an error with BMP images in ImageInfo#measure_BMP
* Temporary removal of encryption functionality, as it seems to have
numerous issues
* Resolved an issue with ordering of column names in PDF::SimpleTable
* Resolved an issue with shading in PDF::SimpleTable
* Applied a patch to allow toggling visible column separators in QuickRef
* Partially fixed issues with page numbering

rubyvmware-0.3-release

Rewrite all initialization codes. More OO and rubish.
Add VMware::VM class with poweron,poweroff,reset,suspend methods.
Try to move to VIX 1.2.

Track latest rubyvmware: http://rubyvmware.rubyforge.org

Ruby gem youtube-g version 0.4.0 has been released!

Aims to be in parity with Google's YouTube GData API

Basic queries:

@client = YouTubeG::Client.new
@client.videos_by(:query => "penguin")
@client.videos_by(:tags => ['tiger', 'leopard'])
@client.videos_by(:categories => [:news, :sports])
@client.videos_by(:categories => [:news, :sports], :tags => ['soccer', 'football'])
@client.videos_by(:user => 'liz')

Standard feeds:

@client.videos_by(:most_viewed)
@client.videos_by(:top_rated, :time => :today)

Advanced queries (with boolean operators OR (either), AND (include), NOT (exclude)):

@client.videos_by(:categories => { :either => [:news, :sports], :exclude => [:comedy] }, :tags => { :include => ['football'], :exclude => ['soccer'] })

## INSTALL

* sudo gem install youtube-g

Thursday, November 29, 2007

Calculating Time difference in Ruby

require 'date'
now = DateTime.new
date = Date.new
p now.strftime("%Y-%m-%d %I:%M:%S").to_s
p Time.now.strftime("%Y-%m-%d %I:%M:%S").to_s
dif = DateTime.parse(Time.now.strftime("%Y-%m-%d %I:%M:%S").to_s)-DateTime.parse("2007-9-12 14:07:00")
hours, mins, secs, ignore_fractions = Date::day_fraction_to_time(dif)
p hours * 60 * 60 + mins * 60 + secs

Tuesday, November 20, 2007

Pdf-writer -- Images in simple table

When using pdf-writer using ruby programming language, simple table always gives option of using text in the rows. I did not have an option to use images inside simple table as it uses data as

attr_accessor :data
# An array of Hash entries. Each row is a Hash where the keys are the
# names of the columns as specified in #column_order and the values are
# the values of the cell.

The following is the code change in simpletable.rb file is required to use images in respected cells.

line : 647
if(line.match("::Image"))
pic = line.gsub("::Image","")
line = pdf.add_image_from_file(pic,pos[name], pdf.y-5, @image_width)
line =""
else
line = pdf.add_text_wrap(pos[name], pdf.y,
max_width[name], line,
@font_size, just)
end


Note: Make sure that text should have "::Image" and remaing text is the path of the image .

like

data[i]["Q1Image"] ="::Image"+Dir.getwd+"/public/images/status_#{p.status_q1_image}.jpg"

For more information please post your comments.

Tuesday, May 01, 2007

Ruby and Related Links

http://www.oreillynet.com/ruby/blog/2006/05/post.html
(Zed on Ruby, Rails, Mongrel, and More)
Rails:
http://www-128.ibm.com/developerworks/java/library/j-cb08016/

Rails Deployment:
http://blog.duncandavidson.com/2005/12/deploying_rails.html
http://www.infoq.com/news/2006/12/deploy-rails-on-iis

Rails Migrations:
http://glu.ttono.us/articles/2005/10/27/the-joy-of-migrations
http://garrettsnider.backpackit.com/pub/367902

Scriptaculous Rails:
http://script.aculo.us/
http://www.juixe.com/techknow/index.php/2006/08/12/scriptaculous-rails/

Rest:
http://www.b-simple.de/documents

Second Life:
http://secondthoughts.typepad.com/second_thoughts/2006/06/getting_started.html
http://nwn.blogs.com/

Design Patterns:
http://www.dofactory.com/Patterns/Patterns.aspx

Agile SD:
http://www.adaptivesd.com/articles/cross_oct02.pdf

Sunday, January 14, 2007

Arjun Singh and the Love Goddess!

So what does the Love Goddess have to do with Arjun Singh and with reservations? As the Indian government, at the behest of Arjun Singh, rolled out yet another short sighted policy to deal with the horrible caste system, we found out about some other activities of Arjun Singh.