Monday, 19 March 2012

How to Install Google Chrome in Ubuntu 11.10(64 bit)

https://www.google.com/chrome?platform=linux

1) Download Chrome fromhttps://www.google.com/chrome?platform=linux  the folder you saved in 

2) Open Terminal by pressing ctrl+alt+t... 

3) Run this 
sudo apt-get install libnspr4-0d libnss3-1d libxss1 libcurl3 

4) Run this mandatory command 
sudo dpkg -i './Downloads/google-chrome-stable_current_amd64.deb' 

Now Google Chrome is successfully installed and you can search it in the search box..... 

Wednesday, 7 March 2012

Controlling your Browser with your Phone and Grails


’ve called this blog post ‘Controlling your Browser with your Phone and Grails’ but I perfectly could have named it ‘Building Publish / Subscribe Apps with Tropo and Redis Revisited’ as what I’m going to show you here is basically a remake of Mark Headd’s super-awesome blog post from April 4th that showed how you could create voice-powered publish-subscribe applications using Redis and Tropo.
In Mark’s example you learnt how to create an application that was able to react to your orders from your telephone switching the color of your browser. I thought it was super-cool, and I also thought that it would be very cool to recreate the same example but using WebApi and Grailsinstead of Tropo Scripting.
The architecture of this project is very similar to Mark’s architecture. You can check it out here. The main differences are basically that my application is based in the WebApi model and that it uses Cometd to communicate from the server to the browser. I’ve uploaded a screencast to YouTube that explains the source code and that shows the application in action:
The source code for this sample project is available at Github. I hope you like it!

To pass current_user object to named_scope in model

named_scope is a way to search records from table repeatedly. Its written in model and one of the easiest way to fetch records.
For example to fetch records from projects table with status finish true, we can proceed as follows: 
class Project < ActiveRecord::Base
  named_scope :completed,:conditions=>"finish = true" 
end
And to use it we can call model name dot named_scope method :
Project.completed
Its very simple, but to pass current_user object to this named_scope is a bit tricky. Suppose we have to find all the projects with status finish, of the current user then it can be done by taking user as an object in it passing user.id as displayed in the below code:

class Project < ActiveRecord::Base 
  named_scope :completed,lambda { |user| where("finish=? and user_id = ?", true, user.id)} 
end

And to use we have to pass the current_user object as:
Project.completed(current_user)
Simple, isn't it !

What is the difference between ImageMagick and RMagick

ImageMagick is a software suite to create, edit, compose, or convert bitmap images, resize, flip, mirror, rotate, distort, shear and transform images, adjust image colors, apply various special effects, or draw text, lines, polygons, ellipses and Bézier curves. It can read and write images in different types of formats including GIF, JPEG,PDF, PNG, TIFF and many more. 

Its functionality can be utilized from the command line or you can use the features from programs like: G2F (Ada), MagickCore (C), MagickWand (C), ChMagick (Ch), ImageMagickObject (COM+), Magick++ (C++), JMagick (Java), L-Magick (Lisp), NMagick (Neko/haXe), MagickNet (.NET), PascalMagick (Pascal), PerlMagick (Perl), MagickWand for PHP (PHP), IMagick (PHP), PythonMagick (Python), RMagick (Ruby), or TclMagick (Tcl/TK).



RMagick is a binding from Ruby to the ImageMagick image manipulation library. RMagick is a complete interface to ImageMagick. RMagick 1 and RMagick 2 are the two RMagick versions. RMagick 2 is the future of RMagick which works with the latest Ruby version

Difference between Validations, Callbacks and Observers

Validations allow you to ensure that only valid data is stored in your database.
Example: validates_presence_of :user_name, :password
                 validates_numericality_of :value

We can write custom validation also as

def validate
  errors.add(:price, “should be a positive value”) if price.nil?|| price < 0.01
end

Callbacks and observers allow you to trigger logic before or after an alteration of an object’s state.

Callbacks are methods that get called at certain moments of an object’s life cycle. With callbacks it’s possible to write code that will run whenever an Active Record object is created, saved, updated, deleted, validated, or loaded from the database.

Callbacks are hooks into the life cycle of an Active Record object that allow you to trigger logic before or after an alteration of the object state. This can be used to make sure that associated and dependent objects are deleted when destroy is called (by overwriting before_destroy) or to massage attributes before they’re validated (by overwriting before_validation)

Observers are similar to callbacks, but with important differences. Whereas callbacks can pollute a model with code that isn’t directly related to its purpose, observers allow you to add the same functionality outside of a model. For example, it could be argued that a User model should not include code to send registration confirmation emails. Whenever you use callbacks with code that isn’t directly related to your model, you may want to consider creating an observer instead.

Difference between Application server and Web Server

apache, nginx, IIS are web servers
mongrel, webrick, phusion passenger are app servers

App server is something which works with particular programming language and parses and executes the code
since mongrel and webrick can only work with rails, so they are app servers

Web servers are servers which can take the request from the browser.
Web servers normally works on port 80 though we can change the port in configuration 
since mongrel and webrick can take that request directly, so they can be thought of as web servers but web servers do have a lot of other functionality like request pipeline, load balancing etc.
App servers lack these functionalities.

About Mongrel server:
mongrel work as web as well as app server if you are talking about dev environment
but in production, mongrel alone can not work it will be too slow
so we need a web server in front of mongrel

Thanks to Mr. Sumit  Garg & Mr. Sidhant for clarifying these points in details.
I would love to have others view also on this.

Update Rails 3.1 to Rails 3.2


In Gemfile, change following versions of assets and rails

gem 'rails', '3.2.0'

group :assets do
  gem 'sass-rails', "  ~> 3.2.3"
  gem 'coffee-rails', "~> 3.2.1"
  gem 'uglifier', '>= 1.0.3'
end

Run 'bundle update'