Thursday, May 24, 2012

Ruby 1.9.3 - defined?

It's a ruby method for checking passed expression defined or not

Some examples

1.9.3p0 :025 > message = "hello" => "hello" 1.9.3p0 :031 > defined? message => "local-variable" 1.9.3p0 :032 > if defined? message 1.9.3p0 :033?> puts "message defined" 1.9.3p0 :034?> end message defined
1.9.3p0 :050 > defined? $_ => "global-variable"

1.9.3p0 :052 > defined? lastname => nil

1.9.3p0 :053 > books = [] => [] 1.9.3p0 :054 > defined? books => "local-variable"

1.9.3p0 :055 > name = "" => "" 1.9.3p0 :056 > defined? name => "local-variable" 1.9.3p0 :057 > author = "Steve" => "Steve" 1.9.3p0 :058 > defined? author => "local-variable" 1.9.3p0 :059 > object = => "" 1.9.3p0 :060 > defined? object => "local-variable"

I hope you understand defined? method from these examples.

Tuesday, May 22, 2012

Procs in rails 3

Proc is an object of code blocks that are assigned into variable.Proc and Blocks are same, but the primary difference is performance.

def say_message_with_name(message) do |name| message + " " +name end end
message1 = say_message_with_name("Good morning")"Tom")
In this example, simply show message with name. Proc is created when constructor is called and given a block as a parameter

The code in the block is treated as Proc instance and can be called any time.You can call Proc code block anytime using "call" method

Output of above example

1.9.3p0 :011 > def say_message_with_name(message) 1.9.3p0 :012?> do 1.9.3p0 :013 > |name| message + " " +name 1.9.3p0 :014?> end 1.9.3p0 :015?> end => nil
1.9.3p0 :016 > message1 = say_message_with_name("Good morning") => #<Proc:0x8e8382c@(irb):12> 1.9.3p0 :017 >"Tom") => "Good morning Tom"

Purpose of Proc

If you want to create a block of code and pass it around on you're application or generate new blocks from existing block.

Blocks in rails 3

Blocks are generally simple code wrapped in a do/end construct.


books = %w{book1 book2 book3 book4}
books.each do |name| print "Book name :: #{name}\n" end

In this example code between do and end is Blocks. what it does is that iterates an array using the each method and passes in each element(i.e name) to the code block

GitHub for Windows

GitHub announced GitHub for Windows

Read this article for more information

Monday, May 21, 2012

Ruby method calling

Different way of Ruby method calling

puts "Hello world"
puts ("Hello world")

Above type applies only ruby puts method. it may vary for other methods based on definition

Ruby method - 1.9.3

Simple ruby method definition

1.9.3p0 :016 > def my_method(message)
puts "Hello," + message

Method call

1.9.3p0 :016 > my_method("World")
=> Hello, World

Ruby method with variable length parameters

1.9.3p0 :016 > def author_books(author, *books)
puts "Author #{author} is written books - #{books.join(', ')}"

Method call

1.9.3p0 :016 >author_books("x-author","book1","book2","book3")
=> Author x-author is written books - book1,book2,book3

Saturday, May 19, 2012

Rails 3 - Routing

Purpose of rails router is that understanding requesting URLs and dispatches them to a controller's action.

Rails 3 introduced new routing DSL which is slight different than rails 2


1. Simple route to welcome page which is handled by index action in shops controller

# Rails 2
map.connect 'welcome', :controller => 'shops', :action => 'index'

# Rails 3
match 'welcome' => 'shops#index'

2. Resources - which allows us to quickly declare all of the common routes for a given resourceful controller

# Rails 2

map.resources :products

# Rails 3

resources :products
It creates different routes in your application for Products controller. The routes are /products,/products/new,/products/:id,/products/:id/edit,etc.

3. Namespaces and Routing

Suppose if you want to organize group of controller under a namespace, Example scenario would be mapping admin specific controllers under admin namespace.

# Rails 2

map.namespace :admin do |admin|
  admin.resources :controller => 'orders'

# Rails 3
namespace :admin do
  resources :orders

In this case you can access admin specific controllers by /admin/orders, etc

4. Simple ROOT mapping on rails 2 and rails 3

# Rails 2

map.root :controller => 'stores', :action => 'index'

# Rails 3

root :to => 'stores#index'

Stores's index action will be called if you access web application directly -

Friday, May 18, 2012

Ambrose - Monitoring of MapReduce data

Twitter announced it's project "Ambrose" is available as open source.

It's a platform for visualization and real-time monitoring of MapReduce data workflows. It presents a global view of all the map-reduce jobs derived from your workflow after planning and optimization. As jobs are submitted for execution on your Hadoop cluster, Ambrose updates its visualization to reflect the latest job status, polled from your process.

Repository for source code/contribute.

Friday, May 11, 2012

An error occured while installing rmagick - Rails 3 Gem(Ubuntu 11.10)

Issue while installing rmagick gem:

An error occured while installing rmagick (2.13.1), and Bundler cannot continue.
Make sure that `gem install rmagick -v '2.13.1'` succeeds before bundling.

Solution would be installing rmagick code library.

$ sudo apt-get install libmagickcore-dev libmagickwand-dev

Thursday, May 10, 2012

Vaadin 7 Alpha 2 Released!

After Vaadin 7 Alpha 1, Vaadin announced it's second development(alpha) release of vaadin 7. Just tried, seems some interesting updates on this alpha release.


Release Notes:


Migration Guide:

API documentation:



JRuby Released!

The JRuby community announced the release of JRuby
It's shipped copy of RubyGems to version 1.8.24.This version of RubyGems is the first version to verify that a RubyGems server certficate is valid. This helps to prevent a “man in the middle” style of attack when someone controls a portion of the network between you and the RubyGems server


Wednesday, May 9, 2012

Ruby/Rails 3 with NetBeans IDE 7.1.2

This post help you to install Rails 3/Ruby Plugin for NetBean IDE 7.1.2.
Nice Stuff i noticed after install this plugin
1. Open you're existing rails 3 project
2. Open new rails 3 project
3. Run/Debug Rake Task
4. Ruby Shell
5. Rails Console
6. Migrate database
7. Run
8. Debug,etc

I hope it makes rails development faster.

Tuesday, May 8, 2012

Google Open Source Blog: Introducing Ceres Solver - A Nonlinear Least Squar...

 Ceres Solver(C++ library) - Solving large complex nonlinear least squares problems

Google Open Source Blog: Introducing Ceres Solver - A Nonlinear Least Squar...: Solving non-linear least squares problems comes up in a broad range of areas across science and engineering - from fitting complicated curv...

Monday, May 7, 2012

Git available!

Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.

It released latest stable version

Download for Linux:

Release Notes:


CakePHP 2.1.2 & 2.2.0-beta released

CakePHP stable release 2.1.2 available.


Release notes:


Yii Framework 1.1.10!

Yii is a high-performance PHP framework best for developing Web 2.0 applications

It's available here for download


MongoDB 2.0.4 available!

MongoDB 2.0.4 distributions available for download, It's available as binary/package for different operating system.


Wicket 1.5.6 - Java web development frameworks

Apache Wicket is a component-based framework, which puts it in stark contrast to some of the earlier solutions to the sometimes monotonous task of web programming.

Like other frameworks, Wicket builds on top of Sun's servlet API; however, unlike frameworks like Struts or Spring MVC, the developer using Wicket is mostly removed from the request/response nature that is inherent with the web and Servlets. Instead of building controllers that must service many users and threads simultaneously, taking in requests, returning responses, and never storing any state, the Wicket developer thinks in terms of stateful components. Instead of creating a controller or action class, he or she creates a page, places components on it, and defines how each component reacts to user input.

Latest stable release available here

Here is simple guide line to include Wicket 1.5.6 on you're MAVEN 2 Project. Add following lines on your pom.xml



Cassandra 1.1.0!

Apache Cassandra announced it's latest release 1.1.0. it's available for download.
For more information about download, release notes and install instructions.

Sunday, May 6, 2012

Install & setup Passenger module on Apache2 - Ubuntu 11.10

This guide help you to deploy Rails 3 application on apache2.

1. Install passenger gem on you're machine
$ sudo gem install passenger

2. Install apache2 module for passenger
$ sudo passenger-install-apache2-module

It does following three steps

a. The Apache 2 module will be installed for you.

If any software not available on you're server to install apache 2 module. It will guide you about missing software and some suggestion how to install those missed software

Once all support software available, then it compile & install apache 2 module.

b. Guide you how to configure apache

Once apache2 module installed, it guide you to configure apache - display LoadModule, RailsSpawnServer and RailsRuby location which will be required to configure passenger module on apache(httpd.conf).Just copy and paste those lines to httpd.conf

c. Guide you how to deploy a Ruby on Rails application
<VirtualHost *:80>


DocumentRoot /somewhere/public


add this virtualhost configuration on httpd.conf file

Now i hope you're apache2 server ready to deploy rails 3 application. it use passenger module for apache2.

Java code snap - Create a File

package com.example.javaIO


public class CreateFile
public static void main( String args[] )
try {

File file = new File("/home/user/readme_IO.txt");

if (file.createNewFile()){
    System.out.println("JAVA IO - Created a File - /home/user/readme_IO.txt");
    System.out.println("JAVA IO - Created a File faild - /home/user/readme_IO.txt");

} catch (IOException e) {
System.out.println("JAVA IO - Catch Exception");

Simple program java program to create a file on server.

This example creates a file which is called readme_IO.txt file on server location("/home/user/readme_IO.txt"). It use createNewFile method to create a file, it return true if the file is created otherwise returns false.


Friday, May 4, 2012

Tuesday, May 1, 2012

NetBeans IDE 7.1.2!

NetBeans IDE 7.1.2 is available now, you can download it from here.

For more information, see Release notes.