« Posts under code

TextMate – Search in project

Several issues I would suggest to the developer:
1) When searching, there is no status/progress indicator (or the button flashing very lightly that I do not notice, but a turning icon would be much nicer). For a large project with over 1000 files, one would wonder if these are all the result or it’s still searching.
2) There is no total/summary that let you know how many matches found.
3) The Replace All option is very nice, however, it does not save the files yet and the icon will be grayed out (if you open its folder). Otherwise, you would not know. Some files are not saved, even if you close all the file windows. You would need to click Save All to save the changes. Even though it should not save the file automatically and an explicit user action is required, an indicator of the project status would be nice.
4) If the result has a long text line, there is no horizontal scroll bar

It’s a great editor and I quite easy to work with.

First snippet customization in TextMate

After reading the manual and view the bundle, customization is quite powerful in TextMate. This class declaration should be trigger by typing “class”, then press Tab key. It automatically your full name using finger/whoami and set the date. Pretty neat eh!

CakePHP – Simple User Registration

After doing some initial readings on different PHP frameworks, including CakePHP, CodeIgniter, Symphony, Zend. I’m digging deeper into CakePHP with an open eyes for fresh ideas and other developments. To start, CakePHP is slow, quite slow (backed up by Rasmus’s benchmark at froscon). It also has not taken advantage of more object-oriented syntax and methods. That said, there are many neat ideas in CakePHP that we can learn to incorporate into our in-house high performance framework (but with less features and automagic).

Framework Performance

To those who says that “slow frameworks is acceptable or understandable”: good framework scales both in term of performance and functionality. It should be easily extensible from its tiny core. Software that does not use any framework cannot scale to provide more functionality and can offer good performance only at a simple task. Enough rants, let’s get dirty.

First App

This is a simple user registration. Cake does have its way of doing things and you might or might not like it. I’m not a big fan of $validate, $uses, and such. I do hope CakePHP will use more PHP5 and OOP the sooner the better since it’s a good framework.

User Model

User Controller

View – register.ctp

Related keywords & spelling suggestion API

Google Toolbar Auto Complete

Replace your own “q=keywords”:

Google SOAP Search API


Yahoo Related Keywords API


Yahoo Spelling Suggestion API


Check username availability via AJAX with jQuery



Server-side check.php

jQuery eq() typical mistake

With all the open/close quote, you might write this code:

var i = 123;

Since the selector string is within the quotes, the correct statement should be:


Linear Regression PHP Class

This PHP 5 class accepts an array of data as input, performs linear regression analysis and returns the trend line. The result is the same as in Excel (Tools/Data Analysis/Regression)

Sample Usage

In this example, we assume it’s a very simple case. For a better forecasting method, there are many, including this multiplicative forecasting method that takes into account seasonality, irregularity and also the growth trend.