September’s Cloud
Posted by mkhairul - September 24, 2008 at 09:09:54 am - No CommentsCategories: blog
I’m doing an experiment. Post my Tag Cloud (from my delicious account) using Wordle every month. And see the progress. Over the months or years.
There might be a pattern that I’m missing.
September’s Cloud
Take a step back and think!
Posted by mkhairul - September 15, 2008 at 11:09:08 am - No CommentsCategories: Troubleshoot
On the weekend, I reviewed the tree traverse function that I did for an ongoing freelance project. Each node have 3 child. I tried to insert 200 records and it took quite a long time to insert the records into the database. 23 seconds.
I am quite sure of the code that I didn’t bother to look at it first and search for other means of alternative on improving the insertion. I googled around for MySQL performance and found a few posts on MySQL Performance Blog. Merge Tables. I need to find out more about this storage engine. I opened up High Performance MySQL, and read up on it.
After an hour reading the book, thinking of ways to implement it and including the constraints of current web host, I thought to myself, this is too hard and complicated, not that I can’t solve hard problems. Haha! I took a few steps back, and try to do something else like watching a funny anime, Gintama. Sometimes taking a break unravel the mind from all the messy thinking being done and makes it easier to think clearly.
Later on I try to think about it again and found out that I’m doing a depth-first search. Which is why it is taking such a long time. I rewrote it to use breadth-first search and it solved my problem for the mean time. I still have to test if it can handle 6165 data insertion.
Check for valid date
Posted by mkhairul - September 11, 2008 at 12:09:57 am - 2 CommentsCategories: blog, code, php
Maybe I’m missing something here. I really think something like this already exist out there. Could not find it so I tried my own.
$pattern = '/^[0-9]{1,2}\/[0-9]{1,2}\/[0-9]{4}$/';
$subject = array();
$subject[] = '30/04/2008'; // valid date
$subject[] = '/30/2008'; // invalid format
$subject[] = '111/30/2008'; // invalid format
$subject[] = '04/30/2008'; // invalid date
foreach($subject as $item)
{
preg_match($pattern, $item, $matches, PREG_OFFSET_CAPTURE);
print_r($matches);
if($matches)
{
list($day, $month, $year) = split('/', $item);
if(!checkdate($month, $day, $year))
{
print "
invalid date: $item";
}
}
else
{
print '
invalid format';
}
print '
';
}
Model Snippet in Komodo Edit for CodeIgniter
Posted by mkhairul - September 10, 2008 at 12:09:48 pm - 1 CommentCategories: blog
I primarily use Komodo Edit for development. Lots of stuffs that I put in the toolbox. Mostly code snippets that generate the best possible code for me at the moment. I tweak in a little bit over time for improvements though.
Here’s a Model Code Snippet / Template that I use when developing stuffs. I have multiple Model snippets. This is one of them.
class [[%w:else:]]_model extends Model {
function [[%w:else:]]_model()
{
parent::Model();
$this->table_name = 'forms';
if(!$this->db->table_exists($this->table_name))
{
$CI =& get_instance();
$CI->load->dbforge();
$CI->dbforge->add_key('id', TRUE);
$fields = array(
'id' => array(
'type' => 'INT',
'constraint' => 11,
'unsigned' => TRUE,
'auto_increment' => TRUE
),
'name' => array(
'type' => 'VARCHAR',
'constraint' => '255',
'null' => FALSE,
),
'uid' => array(
'type' => 'INT',
'constraint' => 11,
'unsigned' => TRUE,
),
'timecreated' => array(
'type' => 'INT',
'constraint' => 11,
'null' => FALSE,
)
);
$CI->dbforge->add_field($fields);
if ($CI->dbforge->create_table($this->table_name))
{
log_message('debug', ucfirst($this->table_name) . " Table Created.");
}
}
}
function get_list()
{
$query = $this->db->get($this->table_name);
if($query->num_rows() > 0)
{
return $query;
}
else
{
return FALSE;
}
}
function get_name($id)
{
if(!$id){ return FALSE; }
$this->db->where('id', $id);
$query = $this->db->get($this->table_name);
if($query->num_rows() > 0)
{
$result = $query->row();
return $result->name;
}
else
{
return FALSE;
}
}
function insert($data)
{
$this->db->set($data);
$this->db->insert($this->table_name);
return $this->db->insert_id();
}
function update($id, $data)
{
$this->db->where('id', $id);
$this->db->set($data);
$this->db->update($this->table_name);
}
}
Retrieve the content of FCKEditor
Posted by mkhairul - September 10, 2008 at 10:09:28 am - No CommentsCategories: Tips, code
Here’s an interesting problem that I faced few days ago on MyQuotes. I wanted to apply a lightbox kind of preview for the content the user put in. I use FCKEditor for the textarea. I have no idea how to retrieve the contents from the textarea (to put it into the lightbox).
After googling around ( I forgot the keyword that I used ), I found it, it can be retrieved using FCKEditor’s API.
oEditor = FCKeditorAPI.GetInstance('quote');
myValue = oEditor.GetXHTML(oEditor.FormatOutput);
The FCKEditor is using BBCode, to minimize abuse (hope it works! LOL). Since I don’t know how to convert the bbcode values retrieved from the content into HTML tags, I use the next best thing. Send it to be converted and tagged up using jQuery’s $.post().
Clean code
Posted by mkhairul - September 9, 2008 at 09:09:09 pm - No CommentsCategories: blog
I’ve just finished reading a sample chapter from Clean Code: A Handbook of Agile Software Craftmanship. I like it so far. Clean code is by far one of the most important aspects of the implementation phase in software development, even more in Web Development, with all the CSS and Javascripts etc.
But to produce clean code, it requires someone who cares or alternatively someone in charge of the code review process who cares about the code.
I could list all of the qualities that I notice in clean code, but there is one overarching quality that leads to all of them. Clean code always looks like it was written by someone who cares. There is nothing obvious that you can do to make it better. All of those things were thought about by the code’s author, and if you try to imagine improvements, you’re led back to where you are, sitting in appreciation of the code someone left for you - code left by someone who cares deeply about the craft.
- Michael Feathres, author of Working Effectively with Legacy Code
The effects on not caring the code, festers into a much bigger problem. It is also called Technical Debt. And as we all know, debt accumulates interest, interest which if not address quickly will tear down the whole system in which the code is part of.
Pragmatic Dave Thomas and Andy Hunt said this a different way. They used the metaphor of broken windows. A building with broken windows looks like nobody cares about it. So other people stop caring. They allow more windows to become broken. Eventually they actively break them. They despoil the facade with graffiti and allow garbage to collect. One broken window starts the process toward decay.
I like how the author explains the situation where the managers pushing the developers to hurry up on schedule and gives a metaphor on it.
To drive this point home, what if you were a doctor and had a patient who demanded that you stop all the silly hand-washing in preparation for surgery because it was taking too much time?2 Clearly the patient is the boss; and yet the doctor should absolutely refuse to comply. Why? Because the doctor knows more than the patient about the risks of disease and infection. It would be unprofessional (never mind criminal) for the doctor to comply with the patient.
I’m eager to see more contents of the book regarding the author’s examples of "clean code" and "bad code". I guess I’ll have to book hunting later this weekend.
Fragmented Task Management
Posted by mkhairul - September 8, 2008 at 01:09:30 am - No CommentsCategories: blog, rants
I keep track of stuffs using Todoist, Task Coach, Google Notebook and Google Calendar. That’s a lot of apps. Here’s a rundown on what I do with it.
Todoist
General stuffs with as little detail as possible. Stuffs like Redesign Blog, Improve MyQuotes, Read <this> book and many more.
Task Coach
Here I keep specific tasks that I have to do. Infiltrate enemy castle with little noise as possible and kill the warlord kind of tasks. The task summary is as detailed as possible but not too detailed to keep it from cluttering the view. Tasks I divide into category for example Work -> MyQuotes. I also filter and sort out the tasks by category and have an overview of priorities. I also keep track of time that I spent on specific tasks with Task Coach.
Google Notebook
This is where all the details goes into. All the steps, all the how-tos, all the references and mechanics of stuffs. IT IS TEH NOTEBOOK! Here lies the secret of the Hammer Fist. One hit, one kill.
Google Calendar
Every now and then I plan stuffs and put it in the calendar. Like holidays and stuffs, going for a trip, hostile territory infiltration, some appointment with local warlords and other sorts of things. It’s just nice, I love it.
There you have it. The fragmented ways of task management. It might be horrifying at first glance but I have come to terms with it. Maybe I could combine them and make a SUPER task managing app. The DOES-IT-ALL. HAHAHA! I’m not gonna fall for that. Thats just too much work. Or is it… ?
Maybe I should learn to manage stuffs and keep it in one app. But then again I get frustrated when that one true app can’t do what I want it to do. The hoops that I have to jump through is just unbearable and I just avoid doing it altogether, which is worse.
New Look
Posted by mkhairul - September 7, 2008 at 04:09:41 pm - No CommentsCategories: blog
Finally I spent the time to give a new look to the site. The old one is getting cluttered and an eyesore. From now on I’m gonna use Syntax Highlighter instead of Geshi. Its just so much more convenient.
So, what’s up?
I’ve been doing lots of office work lately. Especially the Performance Management System which reduces the clutter and makes it easy for the HR Manager to monitor employees on their KPIs.
Other than that, I’ve been using lots of Chrome to surf the interweb. Hoho! It is amazing. But when I develop any apps, I still open up firefox, to use the ever useful Firebug and Web Developer Toolbar.
My Google Notebook is full of drafts on articles and How-To. But none of them are yet published due to many distractions. I have to reserve some time in the future for this else it will just be a draft, FOREVER!
Powered by WordPress with GimpStyle Theme design by Horacio Bella.
Entries and comments feeds.
Valid XHTML and CSS.



