I'm attending the PMP (Project Management Professional) course in the mornings and the NCAP (National Coaching something) in the evenings.
One thing that came up in two very different courses is the concept of S.M.A.R.T. for setting goals.
S - Specific
M - Measurable
A - Achievable
R - Relevant
T - Time bound
Saturday, August 29, 2009
Thursday, August 20, 2009
Threading?
So we have to process a huge amount of data and send them to a different machine. It seems that the sending part (the actual HTTP request in the SOAP call) is slow, and it was suggested to speed things up with multiple threads.
Firstly, my knowledge of PHP is limited on threading, and secondly it seems PHP don't have sophisicated threading APIs like Java or dotNET.
So I came up with a solution that makes multiple SOAP calls to the remote server, but not using threads.
In processing the data, the table has a row id. Simply decide how many concurrent processes you want, and pick out the data to process by the modulus. e.g. if you want to have 2 concurrent processes to send out SOAP messages, pick out the data as such
where id%2=0
and
where id%2=1
Two cron jobs are created, one to call each script with the different parameter (of course, we can do this via a bash script so only one cron job is created).
So there, no race-conditions, no hung threads (ok, maybe hung process), and no headaches.
Friday, July 31, 2009
PHP Read file execution time difference
If you need to read a file into a string, you can use:
$doc = implode(file($this->attachment_file));
or
$doc = file_get_contents($this->attachment_file);
Surprisingly, the first method executes faster. I don't know why.
$doc = implode(file($this->attachment_file));
or
$doc = file_get_contents($this->attachment_file);
Surprisingly, the first method executes faster. I don't know why.
Wednesday, July 29, 2009
Best thing for your CentOS server
If you have a centOS server with ssh exposed on port 22, you can put in a rate limit in the iptables like this (in /etc/sysconfig/iptables):
-A RH-Firewall-1-INPUT -p tcp --dport 22 -i eth0 -m state --state NEW -m recent --name sshattack --set
-A RH-Firewall-1-INPUT -p tcp --dport 22 -i eth0 -m state --state NEW -m recent --name sshattack --rcheck --seconds 60 --hitcount 3 -j LOG --log-prefix "SSH RATELIMIT: "
-A RH-Firewall-1-INPUT -p tcp --dport 22 -i eth0 -m state --state NEW -m recent --name sshattack --update --seconds 60 --hitcount 3 -j DROP
Basically after 3 failed attempts, iptables will block the hacker/robot trying to access your port 22.
-A RH-Firewall-1-INPUT -p tcp --dport 22 -i eth0 -m state --state NEW -m recent --name sshattack --set
-A RH-Firewall-1-INPUT -p tcp --dport 22 -i eth0 -m state --state NEW -m recent --name sshattack --rcheck --seconds 60 --hitcount 3 -j LOG --log-prefix "SSH RATELIMIT: "
-A RH-Firewall-1-INPUT -p tcp --dport 22 -i eth0 -m state --state NEW -m recent --name sshattack --update --seconds 60 --hitcount 3 -j DROP
Basically after 3 failed attempts, iptables will block the hacker/robot trying to access your port 22.
Friday, July 10, 2009
CSS - :hover don't work in IE
I hate IE.
Spent a lot of time trouble shooting my my li:hover does not appear in IE6. Works in FF, Opera, Chrome, IE7.
Anyway, read this:
It points to this:
http://www.xs4all.nl/~peterned/
Now my css will not pass validation. Damn it.
Edit: Ok, went back to basics of using onmouseover and onmouseout. WTF.
Saturday, March 7, 2009
Aptana with cakePHP
Aptana is a pretty good IDE (http://www.aptana.com/) based on Ecplise.
The great thing is that it works with cakePHP.
Just one thing is that cakePHP v1.2 have the views with a ".ctp" extension and Aptana does not handle the code colouring, etc. Luckily this is an easy fix:
Click Window->Preferences...
Select General->Editors->File Associations
Click the "Add.." button and add in *.ctp
*.ctp will appear under "File Types". Click on *.ctp and click the "Add.." button for Associated Editors. Select Aptana PHP Editor.
Done.
Monday, February 23, 2009
Useful Javascript
It's been a while, but I'm doing a bit of javascript again. I have to perform some validation on the user's input and with regular expression it makes the validation much cleaner. The downside is the someone else who comes along and have no idea about regular expression is going to have problem maintaining the code. Oh well.
Validating Email
function validate_email(field) {
var email = document.getElementById(field).value;
return /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)
}
Validating Mobile Number
function validate_mobile(field) {
var mobile_no = document.getElementById(field).value;
return /^[89][0-9]{7}$/.test(mobile_no);
}
Clean and simple.
Subscribe to:
Posts (Atom)