Sunday, April 30, 2006

Pick Up Javascript code for bookmark

Bookmark this site here
Tested on Firefox and IE. Please comment if you face any run-time or javascript errors with your favourite browser.

Friday, April 14, 2006

Online tutorial to learn Web Services in Java

http://java.sun.com/webservices/docs/1.5/tutorial/doc/index.html

The above is a guide to developing Web applications with the Java Web Services Developer Pack (Java WSDP).

Sun's Application Server needs to be used in here to implement the examples.

The tutorials covers various things like
-The Java API for XML Processing (JAXP)
-The Java API for XML-based RPC (JAX-RPC)
-SOAP with Attachments API for Java (SAAJ)
-The Java API for XML Registries (JAXR)

Best part of this is -- all examples are available for download . Hardly any work is needed to get the simple examples working.

Worst part is --various jargons are in place like SAX(Simple API for XML), DCOM(Document Object Model) . These are XML processing models.

This link is a good starting point to parse XML documents using a SAX parser in Java.

Friday, April 07, 2006

Pick up code for sending mail in Java

////Use Java 1.3 and above

import javax.mail.*;
import javax.mail.internet.*;

import java.util.*;

/**
* A simple email sender class.
*/
public class SimpleSender
{

public static void main(String args[])
{
try
{
*************Change the smtpServer name ***************************
String smtpServer="mySMTP";//Use the respective smtpServer name
String to="shantanu.gg@gmail.com";
String from="shantanu.gg@gmail.com";
String subject="Please work";
String body="Consider urself lucky";

send(smtpServer, to, from, subject, body);
}
catch (Exception ex)
{
System.out.println("Usage:"
+" smtpServer toAddress fromAddress subjectText bodyText");
}

System.exit(0);
}
public static void send(String smtpServer, String to, String from
, String subject, String body)
{
try
{
Properties props = System.getProperties();

// -- Attaching to default Session, or we could start a new one --

props.put("mail.smtp.host", smtpServer);
Session session = Session.getDefaultInstance(props, null);

// -- Create a new message --
Message msg = new MimeMessage(session);

// -- Set the FROM and TO fields --
msg.setFrom(new InternetAddress(from));
msg.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(to, false));

// -- We could include CC recipients too --
// if (cc != null)
// msg.setRecipients(Message.RecipientType.CC
// ,InternetAddress.parse(cc, false));

// -- Set the subject and body text --
msg.setSubject(subject);
msg.setText(body);

// -- Set some other header information --
msg.setHeader("X-Mailer", "MyMail");
msg.setSentDate(new Date());

// -- Send the message --
Transport.send(msg);

System.out.println("Message sent OK.");
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
}

Thursday, March 16, 2006

Just got Geekie

There is a hairline difference between techie/geekie and posts like this will transcend into the geeky category.
Here is a small,lazy-- time saving tip for the readers who just can get the article on their systems as and when they are created.

Here is the RSS feed link for this blog

http://puretechie.blogspot.com/atom.xml

Use this feed with your favourite RSS reader and be the first to view the articles....(Now u know what geeky really means ). I use Mozilla thunderbird --real good for such geeky things.

Stay Updated................

Monday, February 27, 2006

New features in Java 1.5

The For-Each loop
A task that is done often is to iterate through a collection, and do something with each element. For example, this shows all the elements in a list :

public void Show(List l) {
for (int i = 0; i < l.size(); i++) {
System.out.println (l.get(i));
}
}

This code seems right; however it could be very inefficient.
The in-efficiency can be attributed to the sequential manner - the
above progresses,resulting in an algorithm of order O(n^2)
whereas an algorithm O(n) is easily obtained.

O(n) can be got with the use of iterators (similar to c++)

public static void ShowFast(List l) {
for (Iterator it = l.iterator(); it.hasNext();) {
System.out.println (it.next());
}
}

When you ask for an iterator of the collection using the method
iterator(), a reference to the beginning of the list is retrieved.
Then, the hasNext() method returns whether there are still more
elements to come, and it.next() does two things: it advances the
reference to the next element in the collection and retrieves the
current element. This gives the LinkedList the opportunity to iterate
through the list in O(n). For the moment, all that can be done in
earlier versions of Java. Even if the above code works, it's not nice
and quite error prone. For example, if in the hurry you call again to
it.next() in the for block in order to retrieve again the element,
you'll get half the list in one place and half in another. Of course
that this can be solved storing the value of it.next() in a local
variable, but Java 1.5 brings a nicer and safer way to do the same: the
for-each loop.


public static void ShowFastAndNice(List l) {
for (Object o : l) {
System.out.println (o);
}

}


You can read the for sentence as "for each Object o in l"

With New features--- have to come their share of new problems.
Not everything is rosy here .....

The following bombs
Object o;
for (o : l) {
System.out.println (o);
}

Sun documents this as "these kinds of practices are not very clear and robust,
so the compiler is making you to write better code, even if it might require
an additional flag."(not verbatim but on similar lines).



Friday, February 24, 2006

A bit off track , nevertheless useful

Spent a hell lot of time getting this

How do you find the OS your DB is running on ???????

As Simple as

select dbms_utility.port_string from dual;

Now I am posting it so that I myself dont forget it .....

Tuesday, February 14, 2006

How does it work

int main()
{
return(mycmp("a"));
}
int mycmp(char * a1,char *a2)
{
printf("mycmp called");
return(1);
}


$>cc mystring.c
$>./a.out
mycmp called
$>

How is mycmp called when the parameters are different.

Saturday, January 21, 2006

Floating Point Anamoly

Source:YPK "Test Your C Skills" Ch-4 "Floating Point Issues" 1st question

main()
{
float a=0.7;
if(a <0.7) a="="b" href="http://docs.sun.com/source/806-3568/ncg_goldberg.html">IEEE
and
Why this anamoly

One good practice is

use something like
#include <math.h>

if(fabs(a - b) <= epsilon * fabs(a))

for some suitably-chosen degree of closeness epsilon (as long as a is nonzero!).


Is a[i] = i++; valid?

This is a very basic question, but many intersting concepts emerge out of it.

Answer is "Behaviour is Undefined".A compiler may do anything it likes when faced with undefined behavior (and, within limits, with implementation-defined and unspecified behavior), including doing what you expect.

Briefly: implementation-defined means that an implementation must choose some behavior and document it. Unspecified means that an implementation should choose some behavior, but need not document it. Undefined means that absolutely anything might happen. In no case does the Standard impose requirements; in the first two cases it occasionally suggests (and may require a choice from among) a small set of likely behaviors.

The concept of sequence point can be used to base a discussion on
A sequence point is a point in time (at the end of the evaluation of a full expression, or at the ||, &&, ?:, or comma operators, or just before a function call) at which the dust has settled and all side effects are guaranteed to be complete.The ANSI/ISO C Standard states that
"Between the previous and next sequence point an object shall have its stored value modified at most once by the evaluation of an expression. Furthermore, the prior value shall be accessed only to determine the value to be stored."

The second sentence can be difficult to understand. It says that if an object is written to within a full expression, any and all accesses to it within the same expression must be for the purposes of computing the value to be written. This rule effectively constrains legal expressions to those in which the accesses demonstrably precede the modification(as above).

Monday, January 09, 2006

cURL -- A tool limited by imagination

A stock ticker is a piece of code which keeps you updated with the latest(as and when) stock quotations of various companies at the stock exchange. Technically to build this one needs the following tools --

  1. XML
  2. RSS
  3. cURL
  4. sed,awk,grep and simple shell scripting knowledge.

1. XML
Need to know just this concepts elements.

2. RSS (Really Simple Syndicate) -- it is really simple.
As I understand this, there is a link like "http://www.xanadb.com/ticker/YHOO" which provides RSS feed for stocks(YHOO- for yahoo, MSFT-microsoft).
Now observe the xml format carefully. All rss feeds essentially have these 3 elements
title,descrption,link.
An RSS reader is one which makes sense of this rss feed.

So to build the stock ticker here is the design
a) Get the contents of "http://www.xanadb.com/ticker/YHOO" in a variable.
b) Just find the “title” tag. Trash the rest.
c) Find the number and thats it.

3. cURL

Now to achieve step (a) mentioned above we have to use a tool which gets us the contents of the page in a variable or a file.

cURL is shipped freely with most of the Linux installations.

Catch hold of one and execute this

curl "http://www.xanadb.com/ticker/YHOO"

Now go through the manual in case you are using proxies, SSL protected site, etc etc etc.

Now the power is all yours. Just think all the stuff possible with this tool and have i told you this. Its a MIT product.

4. sed,grep and other scripting techniques

Here after its child's play and the scripting skills.

curl "http://www.xanadb.com/ticker/YHOO" | grep title | sed s/title//g

I havent tried the above on a machine , but hope you got an idea as to how the attempt is being made to get the stock quote.

Conclusion

No matter how hard web designers may try to force you to surf their sites interactively, there will always be free tools to help automate the process, thus enriching our overall Net experience.
A deliberate attempt has been made only to answer the "How" part of the tools and not the "What" part of them, as they are available in the links suggested.

Next in Line

PODCAST -- what the hell is this

cant use html tags

After writing the article , I just realized that some html tags (like title, link etc in the exact syntax) cant be used in the article. So I could not use the tags correctly.

Thursday, December 29, 2005

Knowledge POOLING

This blog is entirely dedicated to beat the technical thirst in us.
Hope we all appreciate the need for it and also contribute effectively towards it.

There only etiquette to be followed is

"Be Techie"

Oh by the way Arvind came up with this fundu idea again.
Post all the new techie stuf you learn, so that the whole group can leverage your techno abilities. Active discussion on various topics will help us better ourselves than anybody else.
Knowledge only increases by sharing---what say.

Just to inspire

A man is but what he knows.
- Francis Bacon