RSS

Category Archives: web

Reading a CSV File line by line

Ever needed to read a CSV file? Typically you can accomplish this in Java(and similar languages) by creating a instance of CSVStreamReader and using the readAll() method to read in the file.Though this may read the full file it causes a heavier IO load on the file system.

Here is a method to read a CSV file line by line that is less IO intensive.

function readCsvLine( reader : CSVStreamReader ) {
     var line : Array = reader.readNext();
     if ( line != null ) {
        for ( var i : Number = 0; i < line.length; i++ )  {
            if ( line[ i ].search( /^”\d+”$/ ) == 0 ) {
                line[ i ] = line[ i ].substr( 1, line[ i ].length-2 );
            }
     }
  }
  return line;
}
Now you can test your reader Implementation by using the follow below. NOTE: this is a hybrid Java and the syntax may be a little different if your using standard J2SE/J2EE etc..
while ( ( fieldValues = readCsvLine(reader)) != null) {
     //process line data here
}
Since we are using the readNext() method to read each line rather than using the read() the IO reads are processed in short bursts during each iteration rather than one lone continuous IO stream waiting for all the data to read. In situation where you are dealing with large amount of data this is a very safe way to ensure IO does not bottleneck.
Advertisements
 
Leave a comment

Posted by on June 9, 2012 in html, javascript, web

 

Sold vs Shipped

“Thursday’s media reports of Kindle Fire sales collapsing after a stellar launch are misleading, a leading analyst says, and an indication that many tech bloggers and journalists don’t understand the difference between “shipments” and “sales” of a product.”

This is good trending advice, do not mistake shipments for sales leads 🙂

See full article at http://www.pcworld.com/article/255074/kindle_fire_sales_didnt_collapse_in_the_first_quarter_of_2012_research_group_says.html

 
Leave a comment

Posted by on May 6, 2012 in amazon, personal, web

 

Kindle Fire Grabs Over 50 Percent of the Android Tablet Market

Glad to be a Kindle Fire owner, looking forward to the Kindle Fire 2

The bewildering array of Android hardware used to mean that no single device had the power to grab a significant market share of the Android tablet market. That all changed as soon as Amazon’s Kindle Fire hit the scene.

According to latest figures from market research firm comScore, in a little over four months following its release, the Amazon’s Kindle Fire has come from nowhere to grab a whopping 54.4 percent of the U.S. Android tablet market. Way behind the Kindle Fire is the Samsung Galaxy Tab with 15.4 percent, and way behind that is the Motorola Xoom with 7 percent market share.

Original Article: http://www.forbes.com/sites/adriankingsleyhughes/2012/04/27/kindle-fire-grabs-over-50-percent-of-the-android-tablet-market/

 
1 Comment

Posted by on April 29, 2012 in amazon, android, web

 

Tags: , , ,

Find out where this JS Alert is invoked

Ever run into a situation where you have an alert popping up from JavaScript and your not sure where it is coming from. Here is a good technique for forcing a stack trace on all alert()‘s by overriding the Alert function.

var old = alert;

alert = function() {
    try {
        throw new Error;
    } catch(e) {
        console.log(e.stack);
    }

    old.apply(window, arguments);
};

Original Article:  http://stackoverflow.com/questions/7808665/how-to-find-out-where-the-alert-is-raised-from

 
Leave a comment

Posted by on April 29, 2012 in html, javascript, personal, web