Archive

Archive for the ‘Programming’ Category

perl modules install and uninstall and list – using cpan

November 24th, 2011 No comments

If you want to install perl module SOAP::Lite using cpan for example, here’s the command line:

perl -MCPAN -e ‘install SOAP::Lite’

To test whether the module has been installed or not, run this:

perl -MSOAP::Lite -e “print \”Module installed.\\n\”;”

Also, what about uninstallation?

Under windows:
if you have the activestate distro, go to shell/command prompt, enter PPM. When PPM opens type
“remove [package name]” this will uninstall that particular package for you. type “help remove” in PPM for more details.
Alternativly if you know what files came with the package, just delete them. Be aware that some modules will rely on other modules been installed so make sure there are no dependencies before you remove delete packages.

Under Linux:
/usr/local/lib/perl5/site_perl/5.8.X/Module/Module.pm
OR
/usr/local/lib/perl5/site_perl/5.8.X/Module.pm
depending on the module. (the path might be different on your system, check: perl -e ‘print join(“\n”, @INC);’ )
Also see:

http://www.cpan.org/misc/cpan-faq.html

Generally there is little reason to remove a module, probably why CPAN doesn’t provide this function.

Optimization of php array_intersect():get repetitive value of arrays

April 17th, 2011 No comments

Imagine that now we have a site that shows users varies kinds of mobile-phones. The search functionality allows our users to find their phones through different kinds of criteria(For example, by OS type, screen resolution, whether the phone has a webcam, etc). Now, we use associate arrays to store the infomation of all mobiles, each key represents one attribute of the cellphones, and the value represents name of them. Then, we can intersect several arrays to get the specified phone.

Imagine that each key contains 1,000 products IDs, let’s get the material for the performance test.

Firstly, let’s test the performance of php built-in function array_intersect():

Before optimizing the function, you must notice one special point of the funcion:

Result:
* array_intersect($param_a, $param_b): 1, 2, 2
* array_intersect($param_b, $param_a): 1, 2

From the result we can conclude that if there are repetitive values in the first array, then the return value of function array_intersect will give all the repetitive values. Based on this, we should think out of a way to remove the repetitive ones.

Below is the function int_array_intersect() which is implemented by custom:
Read more…

Categories: Programming Tags:

Using php pear_mail in kohana php framework

November 23rd, 2010 4 comments

You may have many sites that scatter over several servers.Each site need service mail account to receive and sent letters to your visitors.You may set up mail server on each server one by one,but that’s not very efficiency and have weakness on availability & manageability.For some day,you may imagine,one of your server crash and then all mail accounts on it are destroyed. As a substitution,using dedicated mail servers is a good idea.Even though your httpd servers crash,your mail accounts are still there,with nothing loss.(You may extend this idea to dedicated DB servers,dedicated cache servers,etc.) Read more…

bash shell mark & simulating multi-processing feature

November 13th, 2010 2 comments

The so called multi-processing,means at the very same moment,multi processes are handled by the cpu.In bash shell and other shells(ksh,csh,etc.),mark & has a special simulation of multi-processing except for the widely known running background feature.The below shell snippets is an example for a explanation purpose.It’s very funny,try it!(file name as if.sh and use sh if.sh to run it)
#!/bin/bash #multi-processing

for ((i=0;i<5;i++));do
{
sleep 3;echo 1>>aa && echo “done!”
#you may of course use other more complicated operations here
} &
done
wait
cat aa|wc -l
rm aa

Ok.Now let’s use time command to test the execution time of the script:
time bash if.sh
done!
done!
done!
done!
done!
5

real    0m3.108s #here,5 loop of `sleep 3` costs 3 and some little more time
user    0m0.056s
sys    0m0.092s

What about we ignore the & ?Let’s just try it! Read more…

php session mechanism:files

October 14th, 2010 No comments

Here I’m going to elaborates php session mechanism:files(files mechanism is also the most frequently used one).

In php.ini,session.save_handler = files instruct php using files mechanism in processing session.The files mechanism creates files in directory set by session.save_path in php.ini,and the filename is the cookie value on the client’s side(cookie name is set by session.name in php.ini,PHPSESSID by defaults),for example,70mild37sara2jpa2rk3h8bjg1.To get the cookie value on the client’s side,you go the follow steps in firefox(Or other browsers):Tools-Page Info-Security-View Cookies.Find the cookie name labeled PHPSESSID,click on it,and get the value of it.

On the server side,after the session’s filename is ready,then time for the content of the session.You set the session content in PHP by using the $_SESSION global variable,for example,$_SESSION['email']=’[email protected]’,$_SESSION['firstname']=’ff.Besides,you can use session_id([string $id]) to assign session id manually before session_start() turns up in your code. Read more…

ip ping in bulk batch shell script

September 30th, 2010 1 comment

Imagine,you’ve got a task now to verify a bulk of domains the speed of response and  whether they are active or not.Here a bulk of,means,for example,1,000.On getting this task,what will you do next?Type in every ip in the command line in Microsoft’s cmd and waits for the result?1,000,you must consider it.You may imagine,how tired after you’ve pinged the full 1,000 of the urls.

Here is my implement of the task.Firstly,put the urls in domain.txt,one url per line.Then run the script:sh if.sh.Lastly,waits for the result in ip.txt.During the execution time,you may go out and breath fresh air or have a cup of tea,not type in the Microsoft cmd any more! Read more…