Archive

Posts Tagged ‘linkedin’

Installing Node.js on Mac OsX

Node.js intrigued me and I wanted to hack with Node.js & CouchDB. I read about Node.js and wanted to install it on my Mac. Here is the guide to install Node.js quickly on Os X.

1. If you are running Snow Leopard then the process is simple. Download the latest package from http://sites.google.com/site/nodejsmacosx/ and install it. Done!!

2.If you haven’t upgraded to Snow Leopard and still running on Leopard (like me) then you have made your life miserable. I encountered with a problem in OpenSSL. Apple pushes a very old version of OpenSSL with Leopard. I spent an entire day looking at ways to compile the code to work for Leopard. The errors encountered were as follows:

1. Link error

collect2: ld returned 1 exit status
Waf: Leaving directory `/Users/harsharv/Downloads/nodejs
/node-v0.4.8/build'
Build failed:  -> task failed (err #1): 
	{task: cxx_link node_main_4.o,node_4.o,node_buffer_4.o,
node_javascript_4.o,node_extensions_4.o,node_http_parser_4.o,
node_net_4.o,node_io_watcher_4.o,node_constants_4.o,node_cares_4.o,
node_events_4.o,node_file_4.o,node_signal_watcher_4.o,
node_stat_watcher_4.o,node_timer_4.o,node_script_4.o,
node_os_4.o,node_dtrace_4.o,node_string_4.o,node_stdio_4.o,
node_child_process_4.o,platform_darwin_4.o,node_crypto_4.o,
eio_1.o,http_parser_2.o,ev_1.o,ares_strcasecmp_1.o,ares_free_string_1.o,
ares_options_1.o,ares_send_1.o,ares_parse_txt_reply_1.o,
ares_parse_ptr_reply_1.o,ares_nowarn_1.o,ares_search_1.o,
ares_gethostbyname_1.o,ares_getsock_1.o,ares__timeval_1.o,
inet_ntop_1.o,ares_parse_a_reply_1.o,ares_getopt_1.o,
ares__close_sockets_1.o,ares_expand_string_1.o,
ares_destroy_1.o,ares_cancel_1.o,
ares_parse_aaaa_reply_1.o,ares_parse_ns_reply_1.o,
ares_version_1.o,ares__get_hostent_1.o,ares_writev_1.o,
ares_expand_name_1.o,ares_free_hostent_1.o,
ares_parse_mx_reply_1.o,ares_gethostbyaddr_1.o,
ares_query_1.o,ares_data_1.o,ares_init_1.o,
ares_fds_1.o,inet_net_pton_1.o,ares_strerror_1.o,bitncmp_1.o,
ares_getnameinfo_1.o,ares_library_init_1.o,ares_mkquery_1.o,
ares_process_1.o,windows_port_1.o,ares_parse_srv_reply_1.o,
ares_llist_1.o,ares_timeout_1.o,ares__read_line_1.o,
ares_strdup_1.o -> node}
make: *** [program] Error 1

This problem is solved by upgrading OpenSSL.

2. You have managed to upgrade OpenSSL from 0.97 to 1.* and when you enter the command “node” you get the error

dyld: unknown required load command 0x80000022
Trace/BPT trap

The solution for this was very simple. Compile with out Open SSL 😀
Let me aggregate them. The steps are as follows:

  1. Download the latest source code from http://nodejs.org/#download. Example:http://nodejs.org/dist/node-v0.4.4.tar.gz
  2. tar -xzf node-v0.4.4.tar.gz
  3. cd node-v0.4.4
  4. ./configure –without-ssl
  5. make
  6. make install
  7. cd build/default/node
  8. node
Done

		
Advertisements

Exceptions – Kick start guide to designing exceptions for your system

February 13, 2010 Leave a comment

The main problem with exception handling is knowing when and how to use it. Exception designing requires discretion, experience in OO programing and knowledge of the users of your system.

What is an Exception?
An exception is an event, which occurs during the execution of a program, that disrupts the normal flow of the program’s instructions. When an error occurs within a method, the method creates an object and hands it off to the run time system. The object, called an exception object, contains information about the error, including its type and the state of the program when the error occurred. Creating an exception object and handing it to the run time system is called throwing an exception.

Types of Exceptions:
There are two types of exceptions:

  1. Checked Exceptions
  2. Unchecked Exceptions

Checked exceptions represent invalid conditions in areas outside the immediate control of the program (invalid user input, database problems, network outages, absent files) Checked exceptions forces the user to use a try-catch block to catch the exception.

To quote from The Java Programming Language, by Gosling, Arnold, and Holmes : “Unchecked run time exceptions represent conditions that, generally speaking, reflect errors in your program’s logic and cannot be reasonably recovered from at run time.” . Unchecked exception doesn’t impose the use of try-catch block and this is caught at the highest level. They are subclasses of RuntimeException, and some examples are IllegalArgumentException, NullPointerException and IllegalStateException.

Checked or Unchecked Exceptions?
There are many arguments for and against both checked and unchecked, and whether to use checked exceptions at all. What I am going to say below is what sounds best to me (and a couple of people around me at Yahoo!).

Why custom defined exceptions?

In the above diagram the user of the system should be aware of exceptions A,B,C which are some custom exceptions of internal components. So, the user has to import A,B,C. It is highly impractical and illogical for the user of the system to be aware of the internal exceptions. So it makes sense to wrap all the internal exceptions in a custom exception Z. The user of the system will have to know about and import only z.

Let us consider that we are building a Banking software. The component built by us will be used by another team. The diagram below adds more clarity to our understanding.

When to use custom unchecked Exception?

Use unchecked exceptions when the user of system can’t recover from the error.

When to use custom checked Exception?

Use checked exceptions when the user of system can recover from the error.

What should be avoided?

One should avoid creating an Exception explosion. Try to limit the number of custom defined exceptions as it would become inconvenient for user of the system.

What can be my next steps?

Look at Decorator pattern to improvise the design.

Talk in MSRIT

September 5, 2009 Leave a comment

(The blog is on YDN also. http://developer.yahoo.net/blog/archives/2009/03/pipes_yql_talk.html)

On a bright Monday morning, I was giving a talk on Pipes, YQL and web development to a bunch of students in MSRIT. After meeting the HOD of the Computer Science Department and other senior professors, I was taken to the seminar hall. There were at least 100 people in the room. They were all students – under grads, who were in third and fourth year of their Engineering. I was a bit skeptical of they being able to digest what I was going to feed them. But in the end I was pretty happy with the outcome.

First, I spoke to them about web development and how it was discouraged in the present day Universities in India.

Then we spoke about Pipes for half hour. Most of them appreciated the beauty of Pipes. Some of them had already started thinking of using Pipes in their projects. We did a quick demo; where in the news about “Lok Sabha Elections 2009″ was aggregated from various sources (news sites and search) and the data was consumed /displayed else where.

Then we had a look at YQL and that is when I realized the beauty of the YQL console. It is not only easy to write SQL style queries, YQL scores in being easy to demo, evangelize and play around with.
We also touched upon writing open tables with simple examples(Twitter).

In the end we also looked at the other useful services of Yahoo! like BOSS, YUI and what has been built using it.

The Q&A section was Pipes centric. Some questions about licensing and other operators in Pipes.
A couple of them who were building websites for their department and batch were interested in YUI. I wanted to show them YUI Grid Builder but the internet failed on us. So they had to settle for pointers on YUI.

There were two people who came up later and asked if there was any location based services of Yahoo! They were building a low cost GPS system and they were happy to find out Fire Eagle and Geo helped their cause.

I really wish the PR could have arranged for some goodies. The event was overall successful, served its cause.

The feedback that I got was more than satisfactory.

YQL – makes you want to hack more

September 5, 2009 Leave a comment

Yahoo! Query Language (YQL)

YQL is a SQL like Query Language developed by Yahoo! to provide a single interface for all the properties of Yahoo! which have exposed their APIs. The best part of YQL (unlike most of the other (*)QLs) is the concept of open tables, in addition to the 50+ Yahoo tables. You can as well fetch a RSS feed, select what is required, massage them and display it.

What makes YQL even more attractive then other (*)QLs is the Console. Developers can type their queries in the console, test them and get the REST URL for the query.

For quick understanding, let us say that a developer has to:
1. Search for photos from Flickr Search the web for data, photos
2. Search for local business
3. Fetch weather info
4. Fetch(add) events from(to) Upcoming
5. Fetch contacts, updates, profiles from profiles (social)
6. Fetch RSS and render it

The developer can use YQl for the above operations. Sample YQL queries are as below:
1. Flickr photo search
select * from flickr.photos.search where text=’Angelina’
2. Search the web
select title, abstract from search.web where query=’Taj mahal’
3. Read RSS
select title from rss where url=’http://twitter.com/statuses/user_timeline/15722583.rss’
4. Read from a HTML page
select * from html where url=’www.harsharv.com’ and xpath=’//body/div[@id=”doc2″]/div[1]/h1′
5. Social: Fetch contacts for a user
select fields.value from social.contacts where guid=[the guid]
6. Social: Updates for a user
select * from social.updates where guid=[the guid]

Other SQL commands like limit, in, joins, sub-queries, unique hold good too.

Overall, YQL is one of the big hit promises that Yahoo! has shown recently. I personally appreciate and love it. It makes me want to hack more. I will use YQL in situations where I would use pipes.

More examples can be found and tried at http://developer.yahoo.com/yql/console

The documentation can be found at http://developer.yahoo.com/yql/guide