Thursday, November 19, 2009

metric_fu installation

Installing metric_fu

metric_fu is a Ruby gem, which means you can download and install it with:

sudo gem install metric_fu

The metric_fu gem specification automatically requires a number of other gems that it uses, including rcov and Flog. So installing the metric_fu gem should mean your system is ready, without the need for additional downloads and installations.

Assuming you are using metric_fu with Rails, you probably will want to tell Rails that it should look for and include the metric_fu gem. You can do this in modern versions of Rails by adding the following line to config/environment.rb:

config.gem 'jscruggs-metric_fu', :version => '0.9.0',
:lib => 'metric_fu', :source => 'http://gems.github.com'

In other words, you want Rails to load the gem known as metric_fu, which can be downloaded from Github as jscruggs-metric_fu, version 0.9.0. If this gem does not exist, Rails will exit with an error.

Finally, you must add a line to your Rails application's Rakefile, telling it you want to load the Rake tasks associated with metric_fu:

require 'metric_fu'

Once this is complete, you should find a number of new tasks, all of whose names start with metric, available in Rake. You can list them with:

rake -T | grep metrics

I typically run all the tests, which you can invoke with:

rake metrics:all

This runs all of the software metric_fu works with, a list that has grown somewhat in the last year. At the time of this writing, running metrics:all includes:

  • churn: which files change the most?

  • coverage: which parts of your code are tested?

  • flay: which parts of your code are duplicated?

  • flog: is your code unnecessarily complex?

  • reek: does your code suffer from well-known bad practices?

  • saikuro: how complex is your code?

I cover a number of these tests in greater detail below. But, before continuing, it's important to note that metrics:all will fail to run all the tests if the rcov coverage tool encounters one or more errors. This isn't a problem if you test frequently, but it can bite you if you break a test and then run metrics:all.

When you run the full report with rake metrics:all, metric_fu puts all the output files under your application's tmp/metric_fu directory. Each test has its own separate subdirectory and produces output in HTML for easy reading with a Web browser. The fact that the files are put in tmp/metric_fu makes them easy to find and view on a local system, but it requires that you move them into a Web-accessible directory (for example, public/tmp/metric_fu) if you want to view them from a remote machine. It should go without saying that you don't want this information to appear on a Web site that is publicly viewable, so be sure to password-protect or delete these reports to avoid unpleasantness.

Although metric_fu's defaults work for most initial cases, you may find yourself wanting to customize one or more of its tests. You can do this within your Rakefile by adding a MetricFu::Configuration block and invoking config.*, where * is one of the tests that metric_fu brings in. For example, you can customize which tests run for :all with:

MetricFu::Configuration.run do |config|
config.metrics = [:coverage, :flog]
end

Wednesday, November 18, 2009

Difference between gem and plugin

Now a days many developers are developing web application using ruby on rails. But a few of them know what actually the difference between “Gem” and “Plugin”.

Here are some of them
GEM
1. Gem is a packaged ruby application using the packaging system defined by RubyGems.
2. Rails itself is a Gem
3. We can install,upgrade and query the gem version.
4. Gem installed for Ruby interpreter can be used system-wide by that interpreter.

Plugin

1. Plugin is an extension of Rails Framework.
2. Can not be upgraded by using a command. To upgrade one have to uninstall and then install upgraded version.
3. Has to be hooked into rails application. (has to have init.rb)
4. Have an install.rb file.
5. Can only be used application wide.

Tuesday, November 17, 2009

Populating database with test data

Steps for populating database by test data
--------------------------------------------
1) gem install populator
2) gem install faker

3)
# lib/tasks/populate.rake
namespace :db do
desc "Erase and fill database"
task :populate => :environment do
require 'populator'
require 'faker'

[Category, Product, Person].each(&:delete_all)

Category.populate 20 do |category|
category.name = Populator.words(1..3).titleize
Product.populate 10..100 do |product|
product.category_id = category.id
product.name = Populator.words(1..5).titleize
product.description = Populator.sentences(2..10)
product.price = [4.99, 19.95, 100]
product.created_at = 2.years.ago..Time.now
end
end

Person.populate 100 do |person|
person.name = Faker::Name.name
person.company = Faker::Company.name
person.email = Faker::Internet.email
person.phone = Faker::PhoneNumber.phone_number
person.street = Faker::Address.street_address
person.city = Faker::Address.city
person.state = Faker::Address.us_state_abbr
person.zip = Faker::Address.zip_code
end
end
end

4) rake db:populate

Thursday, November 5, 2009

Difference Between Windows and Linux

Difference Between Windows and Linux
-----------------------------------------------------------------

Linux and Windows are completely different operating systems. There r no similarities at all.

Linux is a kernel that is a descendant of the original Unix. Windows currently uses the NT kernel made by Microsoft. All Linux operating systems such as Ubuntu, OpenSUSE, Mint all use the same Linux kernel.

Since Linux is a Unix operating system that it makes it most stable OS around. You could leave a Linux desktop on for a month and still u won't notice a performance difference whereas Windows if left on for 2 days would start crashing.

Linux organizes files in a completely different way from windows, almost everything Linux does is different from Windows and that is what makes it better. Linux behaves in the exact same way as the original Unix.

Linux uses different and better file systems than Windows such as Windows uses NTFS whereas Linux uses ext3 and many others. In Linux the GUI is not part of Linux itself so even if the graphical user interface crashes the Linux kernel will keep working without a problem.

In Windows the NT kernel and the GUI is combined so if anything misbehaves the whole system crashes. Linux better manages your resources meaning it knows how to allocate memory and utilize the processor more efficiently than Windows.

Linux uses user account control that means ordinary users cannot modify or do not have permission to modify whatever they like. This is an advantage so if a virus ever does try an attack linux or if a hacker attacks linux then he can not do any damages to your system since he won't be able to get permission to. In Windows everyone has full control of the system so viruses can install and change files with ease, any attacker will immediately have full control of ur system in Windows.

In Linux the GUI interface is controlled by the xserver and is separate from the kernel so problems of the interface won't affect the kernel unlike windows in which the nt kernel and interface is combined.

Linux is a true multi tasking operating system, meaning all programs being used will get a certain time of the processor so even if a program hangs the OS won't freeze and the system doesn't crash. Windows multi tasking is useless cause if an application freezes then it continues using the processor time and the nt kernel is unable to switch resources to other programs so the entire system including the nt kernel hangs and that means u have to reboot ur Windows system.

Linux uses run levels for working, u may know of them if u used Unix, Linux is Unix though. In run levels different levels of ur system do different jobs such as run level 0 starts when booting the system, run level 7 starts your GUI, etc.

You can find out more by visiting wikipedia if u want.

Linux or Unix itself is much more advanced than Windows or any other OS created till now.

I hope I helped.

Good Luck and take care!
ROR Setup on Ubunto
------------------------------------

If you are on Ubuntu then installation of Ruby is Very easy.

1. Open terminal and enter command.

sudo apt-get install ruby-full build-essential

2. You can use WEBrick which is inbuilr server. But to configure with Apache.

sudo apt-get install apache2 apache2-mpm-prefork apache2-prefork-dev

3. Installing RubyGems.

wget http://rubyforge.org/frs/download.php/60718/rubygems-1.3.5.tgz
tar xzvf rubygems-1.3.4.tgz
cd rubygems-1.3.4
sudo ruby setup.rb
sudo ln -s /usr/bin/gem1.8 /usr/bin/gem
sudo gem update --system

4. Installing Rails

sudo gem install rails

5. Installing MySql database

sudo apt-get install mysql-server mysql-client

sudo apt-get install libmysql-ruby libmysqlclient15-dev

sudo gem install mysql

6. Installing Mongrel server

sudo gem install mongrel