Friday, January 18, 2013

Shell Script: Analyze time spent in resource load

The developer tools in the new browsers are very helpful. From, debugging html code, analyze load time to in-line development.

The below script will be helpful when you have to analyze load time for bunch of resources which would be difficult to get done one by one in the browser.

Feel free to make your own changes.

Saturday, January 12, 2013

Sunday, January 6, 2013

PHP: declarative property validation through document

Here is an attempt to define validation rules in document metadata and read it through reflection to validate the property against metadata. The metadata should be a valid json (verify using jsonlint.org).

Keeping it in metadata has the following benefits:

1. keeps it close to the property
2. easier to manage and read ( otherwise a complex structure if specified in another attribute )
3. is cool to do

Having type to php violates the dynamically typed nature of it. This is only in case you need it.

Saturday, January 5, 2013

PHP:json_encode private properties

json_encode( $obj ) works with public properties. In case you have private properties, you can implement jsonSerialize()::JsonSerializable. json_encode for objects of this class will create json with properties or value you specify in jsonSerialize. The output of jsonSerialize should either be array (normal or associative). The below code has a provision to filter attributes added in the $exclude_properties_to_json_arr var.Works with PHP 5.4 and above.