this is amazing:
http://www.jsdesk.com/
Saturday, May 30, 2009
Tuesday, May 19, 2009
Medicare levy surcharge
I asked some of my friends and it seems few of them know this 'Medicare levy surcharge' thing. Below is the explanation from ato website:
What is the Medicare levy surcharge (MLS)?
Individuals and families on incomes above the MLS thresholds, who do not have private patient hospital cover pay MLS for any period during 2007-08 that they did not have this cover.
We calculate MLS at the rate of 1% of your taxable income. The MLS is in addition to the 1.5% Medicare levy.
http://www.ato.gov.au/individuals/content.asp?doc=/content/7128.htm
What is the Medicare levy surcharge (MLS)?
Individuals and families on incomes above the MLS thresholds, who do not have private patient hospital cover pay MLS for any period during 2007-08 that they did not have this cover.
We calculate MLS at the rate of 1% of your taxable income. The MLS is in addition to the 1.5% Medicare levy.
http://www.ato.gov.au/individuals/content.asp?doc=/content/7128.htm
Friday, April 3, 2009
Web database design
I believe most of general datbase design principles apply to web database design as well. However, i also believe web database design should have some specific. No matter all, database design is an old subject in computer science while web application, compared with database, is a pretty new area.
I think the biggest headache to web developers is finding a balance between redundancy and normalization, etc, speed and space. Redundancy can minimize the database query times and the need to join tables. However, this obviously violates the 3rd normalization principle, the school theory of database design.
Personally, i don't mind to have some redundancy in my database. But there is one rule: only the redundent information can let you uniquely identify a row, which means, with that redundent field, you can have construct a unique key for the table.
Let's explain with an example. Suppose we have mobile subscription services. Each service have a shortcode. To subscribe these services, a user can send a signup keyword to a shortcode. Obviously, shortcode and signup keyword must be unique. However, one service can have variety of signup keywords.
The shortcode table may be like this
id, shortcode, country_id
The campaign table is
id, name, shortcode_id
The signup keyword table is
id, keyword, campaign_id
Now if a user send a keywork to a shortcode, i need to find out which campaign he is going to subscribe. Based on the above tables, i cannot uniquely identify a keyword, and then find out the campaign. In this situation, i don't mind adding a shortcode_id to the keyword table, so that with keyword and shortcode, we can uniquely identify the keyword, and then identify the campaign.
I think the biggest headache to web developers is finding a balance between redundancy and normalization, etc, speed and space. Redundancy can minimize the database query times and the need to join tables. However, this obviously violates the 3rd normalization principle, the school theory of database design.
Personally, i don't mind to have some redundancy in my database. But there is one rule: only the redundent information can let you uniquely identify a row, which means, with that redundent field, you can have construct a unique key for the table.
Let's explain with an example. Suppose we have mobile subscription services. Each service have a shortcode. To subscribe these services, a user can send a signup keyword to a shortcode. Obviously, shortcode and signup keyword must be unique. However, one service can have variety of signup keywords.
The shortcode table may be like this
id, shortcode, country_id
The campaign table is
id, name, shortcode_id
The signup keyword table is
id, keyword, campaign_id
Now if a user send a keywork to a shortcode, i need to find out which campaign he is going to subscribe. Based on the above tables, i cannot uniquely identify a keyword, and then find out the campaign. In this situation, i don't mind adding a shortcode_id to the keyword table, so that with keyword and shortcode, we can uniquely identify the keyword, and then identify the campaign.
Thursday, March 26, 2009
PHP PDO bug
Today i just tried to do a simple query 'SELECT * FROM content LIMIT 0, 15'. Since i have been extremely on PDO, i wrote the query in this way, 'SELECT * FROM content LIMIT :offset, :limit', $bind = array('offset'=>0, 'limit'=>15). I got this error:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''0', '15'' at line 1
And then i found this is a PHP bug: http://bugs.php.net/bug.php?id=40740&edit=2
Bug #40740 PDO::execute() errors when parameters are used in LIMIT clause
That is ok. For someone like me who uses PHP to an extreme extent, getting some PHP bugs is normal. I've seen another PDO bug before, which had been fixed. That bug only exists in one PHP release.
What really surprises me is submitted at 6 Mar 2007, while at the end of this bug report, i found this 'Still not fixed in the 5.2.8 release'. I am using 5.2.8!
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''0', '15'' at line 1
And then i found this is a PHP bug: http://bugs.php.net/bug.php?id=40740&edit=2
Bug #40740 PDO::execute() errors when parameters are used in LIMIT clause
That is ok. For someone like me who uses PHP to an extreme extent, getting some PHP bugs is normal. I've seen another PDO bug before, which had been fixed. That bug only exists in one PHP release.
What really surprises me is submitted at 6 Mar 2007, while at the end of this bug report, i found this 'Still not fixed in the 5.2.8 release'. I am using 5.2.8!
Friday, March 20, 2009
JQuery & Html Entities
htmlentities() is well known for PHP developers. JQuery can do the same thing at client side. Here is the interesting blog : http://debuggable.com/posts/encode-html-entities-with-jquery:480f4dd6-13cc-4ce9-8071-4710cbdd56cb
Actually, it is quite simple: $('#content').text('This is fun & stuff').html(); // evaluates to "This is fun & a m p ; stuff"
However, i have another issue. I send a json data { myValue: 'AT& a m p ;T' } to jquery. And what jquery is supposed to do is $("#myInput").val(myValue). This, however, will display AT & a m p ;T in the input field, instead of AT&T, the one i really want to show.
Instead of writting your own html entities parser, here is a hacky solution:
var realValue =$("#js_temp").html(myValue).text();
$("#myInput").val(realValue);
Actually, it is quite simple: $('#content').text('This is fun & stuff').html(); // evaluates to "This is fun & a m p ; stuff"
However, i have another issue. I send a json data { myValue: 'AT& a m p ;T' } to jquery. And what jquery is supposed to do is $("#myInput").val(myValue). This, however, will display AT & a m p ;T in the input field, instead of AT&T, the one i really want to show.
Instead of writting your own html entities parser, here is a hacky solution:
var realValue =$("#js_temp").html(myValue).text();
$("#myInput").val(realValue);
Tuesday, March 17, 2009
JQuery event functions do not work for dynamic added elements
$("a").click(function () {
alert("I was clicked");
});
<a href="http://www.blogger.com/post-edit.do">click me</a>
If you click the link, a window will popup. However, if you use JQuery dynamicly add some new <a> elements, they won't work with the click function. For example,
$("p").append("<a href='#'>I am added dynamically</a>"), and if you click the link, you will find that the function doesn't work at all.
alert("I was clicked");
});
<a href="http://www.blogger.com/post-edit.do">click me</a>
If you click the link, a window will popup. However, if you use JQuery dynamicly add some new <a> elements, they won't work with the click function. For example,
$("p").append("<a href='#'>I am added dynamically</a>"), and if you click the link, you will find that the function doesn't work at all.
Monday, March 16, 2009
Zend framework source code learning - Zend_Loader
include 'Zend/Loader.php';
Zend_Loader::registerAutoload();
The above two lines can save us from those long reqire_once list on top of php files. Let's have a look at the registerAutoload().
The method definition is public static function registerAutoload($class = 'Zend_Loader', $enabled = true). If we don't pass any parameters, the default class is Zend_Loader, and $enable is true, which allows the function to call spl_autoload_register.
if (!function_exists('spl_autoload_register')) {
require_once 'Zend/Exception.php';
throw new Zend_Exception('spl_autoload does not exist in this PHP installation');
}
It checks if spl_autoload_register function exists, because the magic autoload relies on this function.
self::loadClass($class);
loadClass() is the sole method of Zend_Loader. It looks through the path and directory, based on the $class name, and tries to load the class file. For example, if the $class is 'Zend_Log_Writer_Stream', it looks through 'Zend/Log/Writer/' and tries to load Stream.php file.
$methods = get_class_methods($class);
if (!in_array('autoload', (array) $methods)) {
require_once 'Zend/Exception.php';
throw new Zend_Exception("The class \"$class\" does not have an autoload() method");
}
spl_autoload_register(array($class, 'autoload'));
The codes check if the class possesses autoload method and tries to register the method.
Zend_Load defines and autoload method, which actually calls the loadClass().
So that is how Zend_Load works. If we call a class not defined, it automatically searchs the class file by its class name in include_path, and load the class file if it is found.
I havn't done the test by myself. But some articles on internet point out that Zend_Loader::registerAutoload() is bad in performance. It is quite possible, based on its code. So the developer must find a balance between speed and convenience.
Zend_Loader::registerAutoload();
The above two lines can save us from those long reqire_once list on top of php files. Let's have a look at the registerAutoload().
The method definition is public static function registerAutoload($class = 'Zend_Loader', $enabled = true). If we don't pass any parameters, the default class is Zend_Loader, and $enable is true, which allows the function to call spl_autoload_register.
if (!function_exists('spl_autoload_register')) {
require_once 'Zend/Exception.php';
throw new Zend_Exception('spl_autoload does not exist in this PHP installation');
}
It checks if spl_autoload_register function exists, because the magic autoload relies on this function.
self::loadClass($class);
loadClass() is the sole method of Zend_Loader. It looks through the path and directory, based on the $class name, and tries to load the class file. For example, if the $class is 'Zend_Log_Writer_Stream', it looks through 'Zend/Log/Writer/' and tries to load Stream.php file.
$methods = get_class_methods($class);
if (!in_array('autoload', (array) $methods)) {
require_once 'Zend/Exception.php';
throw new Zend_Exception("The class \"$class\" does not have an autoload() method");
}
spl_autoload_register(array($class, 'autoload'));
The codes check if the class possesses autoload method and tries to register the method.
Zend_Load defines and autoload method, which actually calls the loadClass().
So that is how Zend_Load works. If we call a class not defined, it automatically searchs the class file by its class name in include_path, and load the class file if it is found.
I havn't done the test by myself. But some articles on internet point out that Zend_Loader::registerAutoload() is bad in performance. It is quite possible, based on its code. So the developer must find a balance between speed and convenience.
Subscribe to:
Posts (Atom)