Saturday, June 04, 2005

CoLinux with Gentoo

Do you wish to have both XP and Linux at the same time with your notebook anytime anywhere? No, I am not talking about virtual machine, which does't have good performance. Thanks to CoLinux! Now I can have the best of both world : XP for my PsPad, Filezilla, and Putty, plus good looking Chinese fonts without any needs of tweaking. And Gentoo Linux for all my web development needs!

I installed CoLinux with Gentoo inside my Libretto U100 (Japanese page). With my Libretto upgraded to 1G RAM, XP and Gentoo live happily together. Gentoo can even run without any problem after my Libretto wakes up from Standby mode. Very cool. :)

Friday, June 03, 2005

php for Perl Programmer

Just recently started to play with PHP (Little bit late, you may think,eh?). There are many similarities between Perl and PHP, but there are many differences also. This article will try to tell the main difference of PHP from Perl. I will keep updating this article while I learn more.

It doesn't mean to be a complete list, and don't ask me why not include this and that. I don't care. :P

1. Flow Control
1.1 If
More 'C'/'Java' like:

if (expression)
elseif (expression)

Single statment doesn't need bracket {}.

2. Array
2.1 Hash/Array
Perl hash is now PHP array with arbitrary index. No more '@' symbol.

$array1 = array(
0 => 'value1',
'stringkey' => 'value2',
echo $array1[0] . ',' . $array1['stringkey'];

2.2 Append new array element
No need to use 'push'. Just assign it with blank bracket:

$array1[] = 'I will be appended at the end.';

The above only works for simple numeric indexed array. If you use the above type assignment for associative array, PHP will still add to the array, starting with index 0.

If you want to perform similar things for more than one elements, you can use array_push():

array_push($array1, "one value", "two value");

And, if you want to append an array to another array, try array_merge():

$merged_array = array_merge($array1,$array2);

Note that if duplicate keys found in both array, the latter values will overide.

2.3 Loop through array
Do like this:

foreach ($array1 as $value)
echo "value is $value<br>\n";

foreach ($array2 as $key => $value)
echo "key is $key, value is $value<br>\n";

How to create a ftp only + chroot in FreeBSD

1. If the system doesn't have an nologin alike shell, create one: (just a simple shell script)

exit 0

save it to /usr/bin/ftponlyshell (or wherever you want)

Important! Add this file to /etc/shells

2. Create the user as usual, using the above as shell
3. Add the user to /etc/ftpchroot

you're done.

Create user in MySQL

You can easily add mysql new user as follows:

mysql -u root -p mysql
mysql> GRANT ALL PRIVILEGES ON *.* TO 'monty'@'localhost'
mysql> GRANT ALL PRIVILEGES ON *.* TO 'monty'@'%'
mysql> GRANT RELOAD,PROCESS ON *.* TO 'admin'@'localhost';
mysql> GRANT USAGE ON *.* TO 'dummy'@'localhost';

Note: don't know why, the mysql won't complain if you don't supply the -p command switch, even the user really requires password. But even you have reached the mysql prompt, you won't have any further access.

By default, mysqld don't listen on external network interface other than loopback. To add it back,
comment out the following line in /etc/mysql/my.cnf (or whereever it's located)

#bind-address =


OK. That's just my very first post.

For the moment, the purpose of this blog is trying to gather all notes for my development exploration.

See what I will post then.