Monthly Archives: February 2008

NetSuite BOS SuiteScript

NetSuite, without a surprise since it’s already done by it’s competitor SalesForce, introduced Business Operating System, BOS. When I first read about this and the fact that it had SuiteScript, I was almost screaming “if every SAAS startup starts having it’s own scripting language it’s not good for developers”. Then, by looking at the SuiteFlex Development Guide, and reading “SuiteScript is the NetSuite platform built on JavaScript that enables complete customization and automation of business processes.” I felt much better.

Frankly, these days of the Web 2.0 world, there are a few key advantages going with JavaScript based server side scripting. And they are

* The same developer can contribute to both frontend and backend code. (Note that I am using the word “contribute” and not “do development” because, it really depends. Just knowing javascript doesn’t help one to do effective frontend coding unless CSS & DHTML are also mastered)
* Once all the Web 2.0 fad is gone, then the talent pool with JavaScript knowledge would be plentiful
* As a programming language, JavaScript has some powerful features due to it’s prototyping based object oriented programming, functions as first class entities and providing closures. I think it’s also possible to do continuation passing style (CPS) programming.

1 Comment

Filed under BOS, NetSuite, SAAS, SuiteFlex, SuiteScript

Number Of Downloads, A Stupid Metric

Some of the software companies that adopt open source as a marketing strategy advertise that they have so and so number of downloads. A great example of that is Compiere boasting about 1.3 million downloads at present for example. My question is how many of these downloads are

* specific to each release?
* downloaded by competitors?
* downloaded by developers who are just curious?
* potential customers downloading to evaluate but never proceed beyond that first installation and playing around, if they manage to get to that stage?
* it’s easy to manipulate Alexa traffic range very easily by installing the Alexa Toolbar and reloading a website a few times a day from multiple computers (different ips). So, what makes someone not do the same with a bot and increase the download count on sourceforge.net?

Well, I am not accusing any specific company or community about any malpractice, but number of downloads doesn’t really tell anything about a software product. But I guess, any stupid metric becomes a sensible metric on a relative scale. I for one, won’t bet on the number of downloads to decide if I should invest in a specific software.

Leave a comment

Filed under open source

HTML Markup Of An iPod Touch

Lack of standardized support for round corners in CSS has been a pain and there are more than several dozens of solutions out there on the web that vary in their solution approach

* using images to not using images as background
* even the number of images used
* providing anti-aliasing and the lack of it
* using sprites to create round corners with larger radius

There is also a mozilla specific extension called -moz-border-radius using which round corners can be created, but it’s specific to Firefox.

What if you want to represent an iPhone or an iPod Touch as a HTML markup? At iPodish, a stylish electronics rating website, that’s pretty much the attempt. While it doesn’t look exactly like the photo of an iPod Touch, I guess that’s pretty much what can be done with the current level of round corners support in CSS.

Leave a comment

Filed under css, round corners

User Defined Aggregate Functions

Some databases provide the ability to write custom functions that can be accessed from SQL queries. Usually, this feature goes along with a stored procedures capability. A few databases allows creating user defined aggregate functions.

What are user defined aggregate functions? Functions such as count, sum, min and max are all aggregate functions because they operate on multiple rows and provides a single result. There may be times when the default aggregate functions provided by the database are usually not sufficient. In that case, using the “user defined aggregate functions” feature, it’s possible to write your own aggregate function with whatever semantics you want.

It is important to understand the computational model of user defined aggregate functions. First, aggregates happen with or without a grouping. That is

select count(1) from people where country = 'US'

gives the total count of people within the US. Here, there is only one aggregate computation. However,

select country,count(1) from people group by country

gives the total count of people by each country. Here, the aggregates are computed for each country.

In which type of SQL your user defined aggregate function is used should not matter, except for initialization. Before understanding what I mean by that, first, the aggregate computation does not happen on the entire set of rows in a group at once. I will illustrate this with our own user defined aggregate function called pcount. pcount does the same thing that count does.

So, the signature of pcount when you define it as a function, will not be something like

int pcount(object[] group-of-rows);

but it would be something like

int pcount(object val);

So, the expectation is that you keep receiving the data of each row, one after the other and at the end you return the result. So, the following things have to happen for user defined aggregate functions.

  1. Initialization
  2. Iteration
  3. Final Result

Now, since the function is repeatedly iterated over the list of rows within a group, where do you keep any intermediate state such as the number of rows counted so far? For this reason, it is important that the stored procedures language offers some type of object orientation. With object orientation, it’s possible to create an object (using new or whatever constructor mechanism), then loop through the rows calling a member function of the object and any intermediate state can be captured within the object and finally, call a results function to get the final result. In case of a SQL that returns multiple groups (with a group by syntax), it is possible to use the same object or one object per grouping, the implementation may depend on the database. Depending on that, it may be required to write some initialization code so that the state from the previous group calculations are not compounded.

So, the pcount function of ours, will simply be part of an object as a member function and store the count value in a member variable and keeps incrementing the count each time the function is called (ofcourse, it would ignore the null values and not count them).
At the end, the member variable that is keeping the tally of the count is simply returned.

Note that, by default the aggregate functions don’t get the context of the grouping. In our example, the function is not aware for which country the aggregate is being calculated. In most cases this will not be needed either. That is, your count or sum or any other aggregate function value wouldn’t really depend on for which group you are calculating the aggregate. However, if desired, it should be possible as yet another function parameter. Also, note that it’s possible to pass multiple multiple arguments to your aggregate function. Each parameter would typically be a non-grouping column of the query.

Leave a comment

Filed under Advanced SQL

Stack overflow at line: … in IE

I recently came across a strange issue with IE. All of a sudden one of my pages started giving “Stack overflow at line: 0” and I had no idea why that was happening. This didn’t happen in Firefox though. After a bit of searching, didn’t really come across any valid solution other than some microsoft support page talking about too many modal windows causing such an issue.

He is what I finally found with my page. I have the following code

<body onload="onload(event);">

In one flow, this dynamically generated page has the onload javascript function and that works fine. However, in another flow of the same page, the onload javascript function is not implemented. So, in case of IE, it looks like it’s ending up in recursive loop on itself and hence the stack overflow. Had I written the code to

<body onload="onloadfunc(event);">

then in the second flow, it would have simply thrown a regular javascript error that the function doesn’t exist. Hopefully now this mystery is solved for you!

1 Comment

Filed under IE, javascript

SQLITE: Join And Group By vs Group By And Join

A while back I wrote about MySQL count distinct performance issue. Today I am going to discuss about a performance issue I faced with SQLITE.

First the use case. I am experimenting a bit with online product catalogs. So, I have a products table and a categories table. I wanted to get the list of categories grouped providing the count of the items in each category that matches the search criteria. So, I wrote the query as

select c.name,count(1)
from products p, categories c
where p.category1 = c.category_id
and ...
group by c.name
order 2 desc, 1 collate nocase;

The idea is to sort them such that categories with higher product count appear first and if there are two categories with the same product count, they are displayed in alphabetical order (case insensitive).

This query took a lot of time. So, I changed it to

select c.name,g.*
from categories c
,(select category1,count(1) from products where ... group by c.name)
where c.category_id = g.category1
order by 2 desc, 1 collate nocase;

This worked pretty fast. BTW, in the first case, the CPU also maxed out to 90% and above. The later case is much better.

BTW, this is using SQLITE3 (3.3.12)

3 Comments

Filed under performance tuning, SQL Tuning, SQLITE

DIV:HOVER IN IE

I have a link element that contains a div element. My requirement is to change the background color of the div element whenever the mouse is hovered over the link. So, initially I tried

div:hover {
background-color: #abcdef;
}

This works fine in Firefox. However, IE doesn’t like the hover pseudo class for anything other than an “a” element. So, after a bit of tinkering, I got it working with

a:hover div {
background-color: #abcdef;
}

This works in both IE and Firefox. One thing though, the DIV element starts changing color whenever the mouse is hovered not just on the DIV itself, but on the A element itself. So, if the DIV happens to be covering the entire A area, then it’s not a problem, but otherwise, depending on the usecase, this may or may not be an acceptable solution. In my specific case, it is an acceptable solution. So, I am done further research on how to get the DIV to change the color when only that element has a mouse hover in IE.

12 Comments

Filed under css

HTTP Response Status Code 304

If you have a dynamic website that is search engine friendly, chances are your entire database of some entity such as a list of products is made available that can be easily reached by crawling by the bots. Doing this comes with a cost. The bots keep crawling regularly, even at a slower rate, and you have to render those dynamic pages one after the other costing you both bandwidth and CPU cycles. To avoid this, you can write your dynamic pages such that they are “last modified” aware. That is, say you have a product page that lists the product details as well as any comments by the user. While most of the product details itself is relatively static, content such as comments could be changing every few days especially so for a product that has launched in the first few months. Ofcourse, if you do dynamic pricing, then that’s different. But even then, people seldom search based on the exact price string (people want to know if a product is available below a certain price and not an exact price, so don’t bother to worry that your latest price is not indexed. Besides, by the time it’s indexed to the time it’s available in the search results, your price may have changed yet again).

So, how do you make your dynamic page “last modified” aware? The way it works is, bots use a special http request which is a conditional http GET request that passes a special if-modified-since header with a specific date. So, the bot is essentially asking you to respond with the full content only if the content has modified since a given date. Otherwise, you can just respond with a status code of 304 which tells the bot that there is no change. So, search engine crawlers like that of Google which maintains the last time they have crawled uses these conditional requests so that they can avoid the same bandwidth and cpu cycles as you.

How do you know if you are making use of this functionality? It’s easy. Check in your log files and see if you have any 304 response codes against Google bot or other search engine bot requests. If you always see 200 and never 304, then you are not using this feature.

Leave a comment

Filed under Search Indexing, Tech - Tips

Elastic Database Storage Cloud

In an earlier post on is Amazon EC2 right for SAAS, I wrote briefly on whether it would be possible to have proprietary database files in Amazon S3. Based on a recent announcement by EnterpriseDB and further research, I came across Elastra a company, if I understand correctly, provides some kind of a storage virtualization service on top of Amazon S3. See their architecture**.

This is cool technology because, in addition to having elastic compute cloud, it now becomes possible to have elastic database storage cloud. The key is, “database storage” and not ordinary key-value storage that the regular S3 is supposed to be.

Elastra currently has support for MySQL and PostreSQL, the two most popular open-source databases. With this technology, all of a sudden a large-scale database deployment is available to startups as a utility (or as some are calling it as PAAS, platform as a service).

What does it mean to the big players in the database space, mainly Oracle, IBM and Microsoft? Since Amazon EC2 platform is Linux based, Oracle and IBM should be able to soon roll out their own database PAAS on Amazon Web Services infrastructure. Microsoft probably need to figure out how it can enter into this space, especially if they end up acquiring Yahoo!, they would have to deal with a lot of BSD infrastructure as well!

**These guys are using javascript and ajax to load their various tab pages making it difficult to directly link to their technology page. Sometimes, in the effort to make things cool, website developers don’t realize how that impacts their SEO effort, but that’s a different thing. So, if I can’t directly link to their technology page, the next best thing is to hot-link to the architecture diagram but I didn’t want to hot-link either. So, the 2nd next best thing is to link to their image!

Leave a comment

Filed under Amazon EC2, Amazon S3, amazon web services, PAAS

Hard To Frame Searches

For most purposes, doing keyword search gives pretty good results, especially so with Google. Even otherwise, it’s easy to add/remove a few keywords and refine the search to arrive at the desired results without much effort. But sometimes, it gets difficult and simply no easy way to from the searches appropriately.

Here are two examples I came across on the same day.

1) I use a wireless router and also Gentoo linux on one box and Windows on the other. The linux box seems to have ad-hoc network problems and typically slower than the windows box. It so happened that when I tried to use wget, a file that is larger than half a kb was immediately downloaded, but for another that’s less than half a kb, it just got stuck for a while (not always). So, I vaguely had a theory that may be if the size of the pay load is very low, then there is some issue on the linux box. So, how do I frame this as a search query to get the related articles if any?

2) I use wz_tooltips and it works fine. I also have a poplist and whenever an option is selected in the poplist, a tooltip should show up at the appropriate place where element related to the option is on the page. This seem to have an issue in that, the tooltip doesn’t show up till the mouse is moved after the onchange action. Not sure why this happens, but couldn’t figure out an easy way to be able to frame the search.

Sometimes you feel like explaining your entire problem and then get the most relevant search results rather than trying to figure out which set of keywords are the right to arrive at the results.

Leave a comment

Filed under NLP, Search