Tuesday, November 17, 2009

phpBB3 with youtube

To allow users to embed youtube videos in your pbpBB3 forum, do the following:

1. Go to the Administration Control Panel (ACP)

2. Click on the "Posting" tab, click "Add new BBCode".

3. In BBCode usage, enter the following:
[youtube]http://www.youtube.com/watch?v={SIMPLETEXT}{TEXT}[/youtube]

4. In HTML replace, enter the following:
<object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/{SIMPLETEXT}"><param name="wmode" value="transparent"><embed src="http://www.youtube.com/v/{SIMPLETEXT}" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object>

5. In Helpline, put anything you want, I use : Embed youtube links

6. Check "Display on posting page".

7. Submit.

With this, you can embed youtube links like this:
On some sites, the solution requires you to enter only the video id e.g. [youtube]ZGx2Mu2Yaig[/youtube], which is crazy. Which user will carefully select the id and paste it? Users will just copy everything in the address bar and paste it into the forum.

You may have tried other similar solution, and wondered why those do not work. The trick is in the bbcode, we have {SIMPLETEXT}{TEXT}. Often, a user will copy a youtube link with additional parameters (e.g. feature=channel ), which these parameters are handled by the {TEXT} and we throw these parameters away when we display the youtube object on screen. We only want the video id, which is supplied by the "v" parameter.

Friday, November 6, 2009

PHP - killing long running exec process

Was writing a php script to run in commandline to process some files. Part of it is to run a 'whois' command from within PHP, but it hang (ip is 74.220.96.0). I don't know why.

Anyway, I searched and found this:
<?
exec("command & sleep 3 ; kill $!");
?>

Saturday, August 29, 2009

S.M.A.R.T.

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

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.

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.

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.