Sunday, August 11, 2013

blackday for yatra.com

I opened yatra.com and it was not the one I was looking for !! What the hell happened??

The message was to renew domain. Even more surprising!! I looked on whois and found yatra.com has expired on 9th Aug! How can a big company like yatra could do such a mistake?? I know Monday it will be alarming for so many companies.

$ dig ns yatra.com

; <<>> DiG 9.8.3-P1 <<>> ns yatra.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: SERVFAIL, id: 2529
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;yatra.com. IN NS

;; Query time: 498 msec
;; SERVER: 202.83.21.12#53(202.83.21.12)
;; WHEN: Sun Aug 11 22:48:07 2013
;; MSG SIZE  rcvd: 27

$ dig +nocmd yatra.com any +multiline +noall +answer
yatra.com. 5421 IN A 208.91.197.132
yatra.com. 141388 IN NS ns2.pendingrenewaldeletion.com.
yatra.com. 141388 IN NS ns1.pendingrenewaldeletion.com.

So from the story so far it appears that as yatra.com was not renewed they pointed it to some random IP from ns2.pendingrenewaldeletion.com pool.

Even though the TTL for yatra.com was low 5 minutes and very zone cache as 3 hours the site it not back from the NS (202.83.21.12 - ACT broadband) I was using. I got it working when I changed to google open DNS.

Does it have something to do with pendingrenewaldeletion.com TTL?

Data from fixed DNS.

$ dig +norec ns yatra.com

; <<>> DiG 9.8.3-P1 <<>> +norec ns yatra.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 9540
;; flags: qr ra; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;yatra.com. IN NS

;; Query time: 9 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Sun Aug 11 23:16:22 2013
;; MSG SIZE  rcvd: 27

$ dig +nocmd yatra.com any +multiline +noall     +answer
yatra.com. 79 IN SOA ns4.netmagicians.com. postmaster.netmagicians.com. (
2013081102 ; serial
10800      ; refresh (3 hours)
3600       ; retry (1 hour)
604800     ; expire (1 week)
300        ; minimum (5 minutes)
)
yatra.com. 79 IN TXT "MS=ms49031691"
yatra.com. 79 IN TXT "v=spf1 a mx ptr a:202.87.58.131 a:202.87.58.132 mx:pps-mx.netmagicians.com ip4:202.87.58.131 ip4:202.87.58.132 -all"
yatra.com. 79 IN MX 10 pps-mx.netmagicians.com.
yatra.com. 79 IN A 202.87.58.26
yatra.com. 79 IN NS ns4.netmagicians.com.
yatra.com. 79 IN NS ns1.netmagicians.com.
yatra.com. 79 IN NS ns2.netmagicians.com.

$ dig +nocmd yatra.com +noall +answer
yatra.com. 197 IN A 202.87.58.26

Any clue?

Monday, June 24, 2013

opencsv and Japanese character


The problem I faced:

opencsv was corrupting my characters in Japanese language.

Myths
- CSV cannot hold all types of unicode characters. (it can. even a notepad can.)
- FileWriter is not good for handling all types of unicode characters.

What was failing?

- The  ResultSetHelperService class of opencsv where there is rs.getString() was corrupting the data.

How?

I need the figure this out :( But ofcourse it must be not encoding it to the correct character set)

What was the solution?

I derived a child class of ResultSetHelperService and overloaded getColumnValues. I copied everything and did a small change.

instead of

value =  rs.getString(colIndex)

I replaced it with

value =  new String(rs.getBytes(colIndex), "UTF-8")

and it worked !!!

I also read with newer version of Java and Oracle it just works. But for mySql 3.0 and JDBC 4 it did't work.

References:

- The classes java.io.InputStreamReader, java.io.OutputStreamWriter, java.lang.String, and classes in the java.nio.charset package can convert between Unicode and a number of other character encodings.(http://docs.oracle.com/javase/6/docs/technotes/guides/intl/encoding.doc.html)

- http://stackoverflow.com/questions/5892163/should-i-be-using-jdbc-getnstring-instead-of-getstring

- http://www.joelonsoftware.com/printerFriendly/articles/Unicode.html

- http://stackoverflow.com/questions/496321/utf8-utf16-and-utf32

Tuesday, April 16, 2013

POI - Ordered List and Unordered List ( number list and bullet list )

This is my first week at Amazon. I haven't started any serious coding yet. This is my first itch here. We needed some unordered list ( bullet points ) in one of our program generated word documents. We are using POI.

I thought it should be some simple task. I am hearing about POI from a lot number of years. I was expected some good documentation or forum support. But dude there is none !!

Anyways, this is how I went ahead and have resolved few issues and do have some open questions and looking for answers.

There are two flavors of all the APIs. e.g. HWPF for the old .doc and XWPF for the new .docx. So you better set your game here. Many support you see in forums are for HWPF. Being the newer, I opted for .docx and so choose XWPF.

This is how I found the document structure like:

XWPFDocument  can have multiple XWPFParagraph. XWPFParagraph can have multiple XWPFRun. A XWPFRun is group of words with same formatting.

Open Questions:

1. Why is there not much support for this library? Is there some other library that is being used?
2. The numId is kind of global. i.e. The numbering continues. Also the behavior of this numbering is not clear.
3. Not able to set the level of list. 1, 1.1, 1.1.2
4. How to pick another type of  bullet image.
5. How to number a, b, c, ..

A little explanation would be helpful.

Important: I was struggling with the numId value to get either bullet point or numbers. I created a document and then saved it into .xml to see the structure. I observed variation in value for bullet and numbering. When I created a document from scratch using POI I was not getting the bullets and I was getting only numbers. Then I observed the full xmls, where there are lot of definitions. Somehow ( may be due to encoding ) those definitions were corrupted in case of the document generated from scratch. So I created a document ( can be a template document ) and then used it to write and got the bullet points after 4 hours of work. But feels good.

Friday, January 18, 2013

Shell Script: Analyze time spent in resource load

The developer tools in the new browsers are very helpful. From, debugging html code, analyze load time to in-line development.

The below script will be helpful when you have to analyze load time for bunch of resources which would be difficult to get done one by one in the browser.

Feel free to make your own changes.

Saturday, January 12, 2013

Sunday, January 6, 2013

PHP: declarative property validation through document

Here is an attempt to define validation rules in document metadata and read it through reflection to validate the property against metadata. The metadata should be a valid json (verify using jsonlint.org).

Keeping it in metadata has the following benefits:

1. keeps it close to the property
2. easier to manage and read ( otherwise a complex structure if specified in another attribute )
3. is cool to do

Having type to php violates the dynamically typed nature of it. This is only in case you need it.

Saturday, January 5, 2013

PHP:json_encode private properties

json_encode( $obj ) works with public properties. In case you have private properties, you can implement jsonSerialize()::JsonSerializable. json_encode for objects of this class will create json with properties or value you specify in jsonSerialize. The output of jsonSerialize should either be array (normal or associative). The below code has a provision to filter attributes added in the $exclude_properties_to_json_arr var.Works with PHP 5.4 and above.