Tuesday, 11 September 2007

6th anniversary of 9/11




We will always remember ... ...

Smarty Templates - PHP Presentation Framework




Smarty templates can help to separate php coding from presentation. So, your code looks clean and tidy while the HTML templates are much easier to maintain. The beauty of it is that designers don't break your application code and you never messing with templates.

It is more like to put your php code on a layer beneath its presentation and keep a same logic.
Here is an example explaining how I use smarty:

Step One: Specify the smarty template file structure:
Create a folder named smarty under /home/www, and then create 4 sub-folders as named in the php file below. Make sure you change the file permission to 0777 on the templates_c folder.

/*zSmarty.php*/
<?
require_once('/usr/local/lib/php/Smarty/Smarty.class.php'); //Download it from smarty.org
class zSmarty extends Smarty {
public function __construct () {
$this->template_dir = '/home/www/smarty/templates';
$this->compile_dir = '/home/www/smarty/templates_c';
$this->cache_dir = '/home/www/smarty/cache';
$this->config_dir = '/home/www/smarty/configs';
}
}
?>

Step Two: PHP Code

<?
require_once ("zSmarty.php"); //include smarty template class
$ztpl = new zSmarty(); //create smarty template object
assign('name', "Alex"); //assign a value to {$name} which is on the
template
$ztpl->display('test.tpl'); //display the template
?>


Step Three: Template File (test.tpl)
Store test.tpl in /templates folder.

<html>
<head>
<title>testing</title>
</head>
<body>

Name: {$name}
</body>
</html>

Notes:
If you want to place javascript on your templates, please use {literal} tags. For example:

{literal}<script>... </script>{/literal}

Sunday, 9 September 2007

Google Page Rank Prediction Tools





It has been 132 days since the last google pagerank update, and it is certainly the longest wait in the last 2 years. After weeks of anxious waiting for this update, I start to look for some page rank predicition tools to give myself some fresh air. I've found 2 tools so far, working fine. Give the tools a try while you are making your best guesses for the next update. :-)

  1. Raketforskning
  2. Iwebtool
  3. Siteranks

Saturday, 8 September 2007

AJAX & Web 2.0 Tutorial (Section 5) - Debug & Performance




1. AJAX applications don’t exist in a vacuum, while much of the code can reside on the client, the essence of AJAX applications is the interaction with the server, which necessarily involves load.

2. Debugging AJAX applications can be challenging for a couple reasons, including:
- Browsers suck
- Multiple languages involved
- Development environment probably doesn’t support debuging PHP & JavaScript
- Communication between client and server may notbe visible

3. Debugging Tools

- Firebug - Firefox Extension
(Supports step by step debugging, breakpoints and watches; Handles multiple JavaScript documents concurrently; Gives you somewhat nicer error messages)

- Ethereal/Wireshark (Industry standard tool for packet sniffing)
-Live HTTP Headers and HTTP Inspector
(built into Komondo, acts as a proxy for requests)
-Yahoo! Logger library (YAHOO.log)

Friday, 7 September 2007

Google Reader Gears Up - they have SEARCH Now




Finally ... Google reader adds SEARCH which is too good a feature to miss.


AJAX & Web 2.0 Tutorial (Section 5) - Applications




  1. If you ask someone what Ajax stands for, they might answer it doesn’t stand for anything, or they might say “Asynchronous JavaScript And XML”
  2. Asynchronous means that you’re welcome to send requests one after another, but they’re not guaranteed to return in that order (really, they’re not guaranteed to return at all, but that’s rare)
  3. Server load affects your scripts in two similarbut different ways, including:
    1. Everything gets slower
    2. Different parts of things get slower (So some scripts that originally took similar amounts of time can now take drastically different amounts of time)
  4. While Ajax encourages more communication between client and server, it’s generally the same information you would provide anyways, developers simply need to maintain their normal level of vigilance.
  5. There are many situations within Ajax applications where this is sub-optimal
  1. A user could enter invalid login credentials, then hit the login button. Realize their mistake correct it then hit it again
  2. Select something from a list to have further information populated by Ajax, then select another item
  3. A user could click a button to login, then activate another page element that requires them to have logged in before access

Thursday, 6 September 2007

AJAX & Web 2.0 Tutorial (Section 4) - Yahoo User Interface (YUI )




  1. The Yahoo! User Interface Library is a set of utilities and controls that make your life easier;
  2. They’re released under a BSD style license;
  3. Apart from solving cross browser problems, the library also includes code to do a lot of nifty things;
  4. The library is available at http://developer.yahoo.com/yui/
  5. Please go download the library and set it up in your development environment; :-)
  6. Auto Complete is one of those nice finishing touches that can make most websites just seem better. It’s also a perfect case of supplementing the user experience, rather than providing it, worst case scenario the user doesn’t receivethe drop down.

Sample Code:

<script type="text/javascript">
YAHOO.example.ACFlatData = function(){
var mylogger;
var oACDS;
var oAutoComp0,oAutoComp1,oAutoComp2;
return {
init: function() {
mylogger = new YAHOO.widget.LogReader("logger");
oACDS = new YAHOO.widget.DS_XHR("./sampleAutoComplete.php", ["\n", "\t"]);
oACDS.responseType = YAHOO.widget.DS_XHR.TYPE_FLAT;
oACDS.maxCacheEntries = 60;
oACDS.queryMatchSubset = true;
oAutoComp2 = new YAHOO.widget.AutoComplete
('ysearchinput2','ysearchcontainer2', oACDS);
oAutoComp2.delimChar = ";";
oAutoComp2.queryDelay = 0;
oAutoComp2.prehighlightClassName = "yui-ac-prehighlight";
},

validateForm: function() {
return false;
}
};
}();
YAHOO.util.Event.addListener(this,'load',YAHOO.example.ACFlatData.init);
</script>

Snap Shots is Cool




I signed up for SnapShots today, and really like it. Here is a screenshot:


What it does?

Without clicking a link, you can get a general impression of what the page behind looks like. Very cool, innit? Check this out ...

Latest Features:

  1. Logo changes
  2. Picking a new color theme
  3. Change the Snap Shots icon and/or trigger
  4. And more...as Snap will continually build new features

Wednesday, 5 September 2007

AJAX & Web 2.0 Tutorial (Section 3) - JSON




  1. JSON (JavaScript Object Notation) is a subset of how objects are represented in JavaScript
  2. It’s presented as a lightweight information transfer protocol, similar in many respects to XML
  3. What makes JSON useful in JavaScript is that it can be parsed very easily (eval())JSON can contain any number of elements, nested key value pairs, objects, arrays, etc.
  4. Until a library is introduced the easiest way to transfer data between your script and PHP is to use simple GET & POST based requests for transmission, and JSON for receipt.
  5. Different browsers interpret JavaScript differently, IE in particular goes off in its own direction (xmlHTTP request works differently, it’s difficult to re-use ajax objects, data is stored in linked lists rather than a hash table so it’s notably slower)
  6. You could do some serious research, understand all the little differences, and write your code appropriately, or...


JSON Example:

<script type="text/javascript">
var name = "alex";
httpRequest = new XMLHttpRequest();
httpRequest.open('GET', 'http://localtest.luxplus.net/alfa/
ucase.php?text=' + name);
httpRequest.onreadystatechange = function()
{
if (httpRequest.readyState == 4)
{
responseJSON = eval("(" + httpRequest.responseText + ")");
alert(responseJSON.ucase);
}
}
httpRequest.send(null);
</script>


/* ucase.php */

<?php
$string = isset($_GET['text']) ? strtoupper($_GET['text']) :
strtoupper("default");
$data['ucase'] = $string;
$returnValue = json_encode($data);
echo $returnValue;
?>


Difference between Programmers and Developers




Programmers deliver pieces of code according to the given product descriptions while developers develop objects or solutions based upon their understanding of particular business logics.

AJAX & Web 2.0 Tutorial (Section 2) - Web Services




  1. Web Services are a way for disparate applications to work with each other over the web;
  2. In order for different applications to communicate with each other they need to agree on a protocol, webservices have three common protocols, JavaScript throws a fourth into the mix;
  3. REST - Simple request protocol, looks identical to a form being filled out, response is a basic XML document;
  4. XML-RPC - XML request-response protocol, format chosen is sub-optimal for parsing with DOM tools;
  5. SOAP - Heavy but well defined XML based request-response protocol;
  6. JSON - JavaScript Object Notation - information is passed back and forth in the JavaScript notation;
  7. Ditch SOAP & XML-RPC, (SOAP is too heavy for frequent small requests, XML-RPC is just ugly);
  8. REST - Light weight requests, some basic frameworks are available. Define your own response XML format;
  9. JSON - The JSON format is relatively lightweight but still ‘new’ enough that it’s not too widely supported (JSON support was added in PHP 5.2.0);
  10. It’s critical to remember that HTTP is a stateless protocol, every request must stand alone, independent of each other request. While technologies like sessions help can help when dealing with end users, they are inappropriate when using web services;
  11. When developing web services leverage and re-factor existing code, rather than duplicating;
  12. Objects are rather... different compared to other languages. Rather than defining a specific
    class, than instantiating instances of it, objects are created from functions that pull in their own required methods. This can be done on the fly, or by defining functions inside other functions.