How ’bout writing a JavaScript template engine ?

Yea! a minimalistic one, without much xBrowser checks, would be as follows,

function render(o){
	if(!o.o) return;
	var rv = document.createElement(o.o);
	if(o.p){
		var pC = o.p.length - 1;
		for(var i = 0; i < pC; i += 2){
			rv.setAttribute(o.p[i], o.p[i+1]);
		}
	}
	if(o.c){
		var cC = o.c.length;
		for(var i = 0; i < cC; i++)
			rv.appendChild(render(o.c[i]));
			}
	if(o.txt)
		rv.innerHTML = o.txt;
   return rv;
}


Now what the heck is written above ? no wonder, it is just a recursive function which can handle json page structures. Only thing is that the page structuring can go heck and complex, though the renderer is too simple with only just a handful of statements. The var names are intentionally kept at a minimum to make the function lighter.
Continue reading “How ’bout writing a JavaScript template engine ?”

ash.MVC – a simple PHP programming framework

ash.MVC is a simple PHP programming framework proposed by Ash. The basic approach of this framework is to adopt a middle-path approach between faster development cycle, and a robust and scalable application. Moreover, the schemes proposed in the framework stick to the line of simplicity all along.

While encountering this new framework, ash.MVC, one may wonder with various questions, like:

  1. Do we need a framework at the first place?
  2. Why do we need another framework when there are numerous ones available?
  3. Why do we use MVC design pattern for this framework?

All the above questions have been addressed in the FAQs page.

The framework revolves round the concept of MVC design pattern as expected. There are four elements: 1. web browser, 2. Controller, 3. Model, and 4. View. These four elements interact with one another to establish a data-flow that is initiated by HTTP Request from client browser, and is successfully terminated with the receipt of HTTP Response at the client browser.

Web 2.0, Library 2.0, and More

Typically, new software releases bear a version number such as 2.0. The version-numbered releases have new features and capabilities for one specific program. This is not the case with the latest round of 2.0s on the Web. They are a conglomeration of technologies, ideas, and approaches that, at least to some, represent a new way of interacting online. Their meanings are ambiguous and sometimes contradictory. In fact, one of the concepts of the 2.0 movement is being a movement away from new software releases.

Even though much of the 2.0 technologies are the playground for Web designers and programmers, knowing the terminology and sample sites allows the information professional to converse about the new trends and to find both useful sites and new capabilities to integrate into information products. Rather than debate the overall merits of the 2.0 movement, information professionals should explore the territory, techniques, and examples to find the most useful applications in your own work environment.

Read the whole story

Devise Web 2.0 applications with PHP

DHTML is HTML that includes JavaScript code that changes the content or layout of the page in the browser without going back to the server. When you write an HTML page, you’re actually writing an object tree. All the tags — the little <table>s and <p>s — become objects in the JavaScript space. Using JavaScript, you can change their content, Cascading Style Sheets (CSS) styling, and location — all without ever going back to the server. DHTML is the intersection of HTML, CSS, and JavaScript.

The technology to use DHTML has been around since the addition of JavaScript code to the browser, but support for it has been spotty. Microsoft® Internet Explorer did an excellent job early on, but during the same period, Netscape V4 lacked support. Recently, Mozilla and Firefox have stepped up with solid DHTML support, and some believe the pendulum has swung so far that Internet Explorer is now behind the curve.

Read the whole article

Openings in Technopark

The beginning of Saturn is evolved from the passion to excel in the areas of futuristic Technology Solutions delivery. This passion through relentless brainstorming and hard work transformed as Saturn InfoLabs in the luxury of a 100 sq. ft. facility with a Home Computer and the great desire to deliver against all odds. The resolve to stay ahead, to explore, to ideate, to succeed, best define the concept of ‘SATURN’.

From it’s start up in 2003 taking up an innovative project implementation for a reputed regional Newspaper Group in India, we have come a long way to it’s present position of a leading IT organization with Technology and business achievements at par with the IT growth rate around the world. The company is now situated at Technopark, Trivandrum the biggest and greenest IT Park in India with CMMI Level 4 standard.

If you think you have a two plus years non-contiguous exposure in php/mysql with any of the Web 2.0 libraries feel free to drop a line to 91-471-3255001 for an appointment or forward resume to hr@saturn.in. Please refer to this post, when contacting them.

Optimizing Indexes

Designing a database as part of a big project, will need a lot of experience. There are several factors which should be considered before finalizing a database schema. Since once the project starts rollout, there is no going back, other than adding a new index, or adding another field, any major change will affect the whole code base.

Indexing is the most important method you should try first for speeding up queries. Other techniques are  also available, but generally the one thing that makes the most difference is the proper use of indexes. On the MySQL mailing list, people often ask for help in making a query run faster. In a surprisingly large number of cases, there are no indexes on the tables in question, and adding indexes often solves the problem immediately. It doesn’t always work like that, because optimization isn’t always simple. Nevertheless, if you don’t use indexes, in many cases you’re just wasting your time trying to improve performance by other means. Use indexing first to get the biggest performance boost and then see what other techniques might be helpful.

One should take absolute care to optimize the fields by keeping in mind, that larger the indexes, slower the operations. The most common example of a mistake is to add a timestamp field to select the data in chronological order. Now if the total rows is just a handful, this wont be a problem atall, but if the total rows is millions, the timestamp field may have a cardinality of say 50% of the total rows, making the index very huge, and operations slow. But if instead of the timestamp, the data is stored in two fields with date in one, and time is another the cardinality of time will be 86400, ie the no of seconds in a day, and the cardinality of date will also be under control, making the operations faster by an appreciable amount. For varchar fields, creating partial indexes instead of full index helps, reduce the size of the index file, and hence give the server breathing space.

Calculations ? Try and use SQL

Hmm.. yes.. I literally meant it.. for several things you can directly use SQL calculations, though the queries and functions shown here are tested only with mysql, it should work with most other sql servers too. The cliche is if you have the sql server on the same server where your webserver and php interpreter is running. In simple terms, if you connect to mysql on www.jijutm.com, sql can be used to a great extend to do calculations.

Some time back I did read on some other site, where two dates where calculated for the current month, using php mktime and date functions, to be passed in an sql query, for a range selection. I am not for an argument, but it seems more efficient to use the date calculations directly in the sql query, than pre calculating this unless otherwise it is needed to be printed in the output. Even then, the calculation can be done by the sql, and the result returned.

SQL calculations along with SQL session variables, will help a programmer achieve a very high optimization level for the scripts, thereby reducing webserver, and interpreter load.

Date calculations can use date_format, date_sub, unix_timestamp and from_unixtime and other related functions. Aggregates has all complimentary functions like sum, abs and others. By using a combination of these, any calculation can be achieved by sending an sql query.

Quotes – All about variable evaluation

The doubt on whether to use double or single quotes for static strings,  has been a heated discussion on many a discussion groups. As of late I did a small bench mark, and has found that the encapsulation of variables in double quoted string is a slight higher load than concated string, even when the static string is quoted in double, whereas the most efficient is to specify single quotes for quoting static string.

Continue reading “Quotes – All about variable evaluation”

PHP Mime Mail Class

There are a lot out there; but my favourite is been PHPMailer

I was always on the look for a decent php mail class with smtp auth and mime mail support.  Then one day stumbled on this sourceforge project. There it was with other features too which I wished to have

  1. Can send emails with multiple TOs, CCs, BCCs and REPLY-TOs,
  2. Redundant SMTP servers, Multipart/alternative emails for mail clients that do not read HTML email,
  3. Support for 8bit, base64, binary, and quoted-printable encoding,
  4. Uses the same methods as the very popular AspEmail active server (COM) component,
  5. SMTP authentication,
  6. Word wrap,
  7. Address reset functions,
  8. HTML email,
  9. Tested on multiple SMTP servers: Sendmail, qmail, Postfix, Imail, Exchange, etc,
  10. Works on any platform,
  11. Flexible debugging,
  12. Custom mail headers,
  13. Multiple fs, string, and binary attachments (those from database, string, etc),
  14. Embedded image support

Friendly URLs or furl – How to approach

There is been a lot of hype of late about having Friendly URLs, or in short furl. What is so fancy about these ? Oh yeah! they help the search engines, they help your visitors. On an after thought, do they help the search engines? I would say no and a big blatant NO.

Why? First of all, search engines as the biggest of it all claims, they do not have a difference between a url that has a query string or that does not have a query string, other than that bots will be a bit more light on any url with a query string, ie a ‘?‘, with inducing a small delay between queries. And those with query strings will be considered as changing content, whereas those with out query strings are considered as static or stationery content. So by forcing a search bot to index your site using furl, you would be deceiving the bot by showing it the furl, where as internally you would be using dynamic content.

Now a days most of the content management systems, blog packs, and open packages do offer furl as an integrated part.  Most of the packages implement this using some sort of pluggable techniques, but some notably do have neatly planned and implemented furl support. Actually the furl support is provided to help you and not the search engine. Once you enable this in the software, the search bots will be deceived to index your pages as static content, inducing heavy load on your servers. This does not imply that we should avoid using furls, no but we should plan well ahead to make sure that our servers are the least loaded.

For implementing furl in your package or application, either you should design it from the basics, or you should revert to some sort of plugs, but still if you can redo the basic parts of your application, use some global replaces for durls, to corresponding furls, and take the pains to absolute link all media, I mean images, css, swf etc. I would recommend doing so, and giving it a full integrated test before releasing the pack.

Two methods are being practiced the most, though there are other derivatives being used.  The first one being using mod_rewrite (a plug), to change the url into a var=value pair internally. The second one is to force all calls through a single php file, and to parse the QUERY_STRING super global. Still both methods require the durl to furl conversion in the code.