Friday, December 07, 2007

Drupal debugging tips

Sometims drupal throw this kind of error:

warning: urldecode() expects parameter 1 to be string, array given in E:\Websites\www\gt\modules\path\path.module on line 142.

One way to debug this issue is insert the following code into where the error is thrown

if(is_array($text)){
printArray($text);
backtrace();
exit();
}

Thi tells you which element of the form cause the error, you can also print out what is the argument in the array by setting condition to the backtrace() function. Such as

If(count($array) == 22){

$args .= printArray($array);

}

I found this very convience and useful. Better more, Make use of the following function when debugging.

//back_trace
function backtrace()
{
$output = "
\n";
$output .= "Backtrace:
\n";
$backtrace = debug_backtrace();

foreach ($backtrace as $bt) {
$args = '';
foreach ($bt['args'] as $a) {
if (!empty($args)) {
$args .= ', ';
}
switch (gettype($a)) {
case 'integer':
case 'double':
$args .= $a;
break;
case 'string':
$a = htmlspecialchars(substr($a, 0, 64)).((strlen($a) > 64) ? '...' : '');
$args .= "\"$a\"";
break;
case 'array':
$args .= 'Array('.count($a).')';
break;
case 'object':
$args .= 'Object('.get_class($a).')';
break;
case 'resource':
$args .= 'Resource('.strstr($a, '#').')';
break;
case 'boolean':
$args .= $a ? 'True' : 'False';
break;
case 'NULL':
$args .= 'Null';
break;
default:
$args .= 'Unknown';
}
}
$output .= "
\n";
$output .= "file: {$bt['line']} - {$bt['file']}
\n";
$output .= "call: {$bt['class']}{$bt['type']}{$bt['function']}($args)
\n";
}
$output .= "
\n";
print $output;
}

Friday, November 16, 2007

Eclipse -> Chnage editor background color

To change the background color of editor,

 

  1. In the editing area, right click then select preferences
  2. In Editor -> Structure Text Editor, in the Appearance tab on the right, where you can change color preference

Thursday, November 01, 2007

Eclipse Update manager

It is good idea to bookmark http://update.eclipse.org/updates/ in eclipse.

  1. Help ->software update
  2. Search for new feature and install
  3. Click new remote site, give it a name and the address as: http://update.eclipse.org/updates/
  4. Click Ok.

 

Some tips about "Return false" on a javascript

Forms are objects; they have their own methods, properties, and event handlers. One event handler that you should know about is onSubmit.

onSubmit gets called in two situations: if a user clicks on a Submit button, or if a user hits Return in a text field. If these actions are not handled in some way, your JavaScript may behave differently than expected. Try clicking on Submit below and see what happens.

In Netscape, clicking on an unhandled Submit button generally leads to reloading the page. In general, you won't want this. In order to block this behavior, you need to do this:

<form onSubmit="return false;">
<input type="submit" value="Submit">
</form>

Try it:

Generally, return false is a way that JavaScript stops your browser from doing what it would otherwise do. Another example of this is stopping an href from going to the URL assigned to it. For example, the link ...

<a href="http://www.webmonkey.com/"
onClick="return false;">mattmarg!</a>

... won't go anywhere because you've returned false on the onClick. Click on this dead link, if you don't believe me.

This may seem like a weird thing to do, but actually it's quite common, especially in the case of forms. Here's an example of using a form to get input from a user. Type something into this text field and hit Return:

Who does the monkey love:

Here's the form:

<form name="text_entry_form" onSubmit="monkeyLove(); return false;">
<b>Who does the monkey love: </b>
<input type="text" name="monkey_love" size="30">
</form>

When you hit Return in the text field, the onSubmit handler gets called. It executes the function monkeyLove(), which changes the value in the text field.

If the return false wasn't in the onSubmit handler, the function monkeyLove() would execute, changing the text field, but then the page would reload, changing the text field back to what it was. To stop this from happening, you need to have that return false in the onSubmit.

Here's the monkeyLove() function for your perusal:

function monkeyLove()
{
  var who_it_is = window.document.text_entry_form.monkey_love.value;
  who_it_is = 'The monkey loves ' + who_it_is;
  window.document.text_entry_form.monkey_love.value = who_it_is;
}

And here's an example of the same form without the return false, just so you can see what happens:

Who does the monkey love:

 

Reference: http://www.webmonkey.com/webmonkey/98/04/index3a_page5.html?

 

 

Friday, October 26, 2007

Sunday, October 21, 2007

Install Drupal the easiest way with MAMP

This is a great article shows how to install Drupal, PHP, Mysql and Apache on your mac with very lease pain.


Want to take the latest, greatest edition of Drupal out for a spin - and run it from the comfort and safety of your very own Mac? Only a few short years ago, that was strictly the domain of the geekier Mac users… but today, it’s a lot easier.

That’s thanks to programs like MAMP, which stands for Macintosh, Apache, MySQL and PHP. MAMP lets you install and launch these powerful tools without ever having to stare a command line in the face. And once you have them up and running (which you will in just a few clicks), you can install all sorts of server-side software on your Mac and access it through your web browser - programs like WordPress, activeCollab and, yes, Drupal.

Why do that? Partly so you can futz around with them even if you aren’t connected to the web, and with the kind of access no web host in their right minds would give you. Partly so you can configure, test and debug web sites on your computer without worrying that the world is watching. But mainly because, come on, this is kind of cool.

So let’s not waste any more time gabbing. We’re going to install Drupal (by the way, you can adapt these instructions for a lot of other server software): not boring old version 4.7, but the exciting new testing version with the very latest features. One of those features is an automatic installer, which is how we’re able to hold this down to five easy steps.

(If you do want to install version 4.7, then instead of step 5, you’d manually edit the settings.php file in Drupal’s sites/install folder, and then run a few MySQL files through PHPMyAdmin. It’s all explained in painful detail in the install.txt file that comes with Drupal.)

1. Get ready:
* Download and install MAMP. (Go to http://www.mamp.info/en/home/ to find it.)
* Then download the latest version of Drupal. (Go to http://drupal.org/project/Drupal+project and pull down “CVS” from the “Filter by version” menu. This will give you the version that includes an installer.)
* Unzip it, and move the files into MAMP’s “htdocs” folder.
2. Launch MAMP and your favourite browser. If the buttons next to “Apache Server” and “MySQL Server” in MAMP aren’t green, click the “Start Servers” button. If that doesn’t turn the servers on, you’ll need to troubleshoot MAMP before you go any further.
3. Create an empty MySQL database for Drupal to use.
* Point your browser to http://localhost:8888/phpMyAdmin/ and click on the “Databases” tab.
* Under “Create a new database”, fill in the information for your database. Give it a name (say, “droopy”) and, in the pulldown menu that says “Collation”, choose “utf8_unicode_ci”. Click “Create.”
4. Create a database user account for Drupal.
* In the left-hand sidebar, click on the home icon. (It looks like a little house.)
* In the main pane, you’ll see two columns. In the left-hand column, click “Privileges”.
* Under the table listing all sorts of users, click “Add a new User”.
* Give the user a name (no spaces - make it a simple name). For “Host”, choose “Use text field” and enter “localhost”. Key in a password, and re-type it.
* Under “Global privileges”, make sure none of the items are checked. Click the “Go” button in the lower right-hand corner.
* The next screen allows you to edit the user. Scroll down to “Database-specific privileges” and, using the pull-down menu, select your Drupal database – in our case, droopy.
* A series of checkboxes appear, just like the “Global privileges” screen a little while ago. This time, click “Check All” and click the “Go” button at the bottom right of the “Database-specific privileges” section.
5. Tell Drupal what database settings to use.
* Point your browser to http://localhost:8888.
* Fill in the information that Drupal asks for: MySQL as the database type, the name of the database (”droopy”, in this case), your user name and your password. Click the “Save” button.

If all went well, you’ll be looking at a screen that congratulates you on installing Drupal, and invites you to click on a link to visit your site. Add content, install modules, start theming - you can do it all. There are a few other things you might like to do (for instance, setting up a regular call to cron.php in crontab, and there you will have to open up Terminal); have a look at Drupal’s install.txt file for a explanation.


This is article is getting from:
http://www.robcottingham.ca/20060830/how-to-install-drupal-on-your-mac-in-five-steps/

Saturday, October 20, 2007

Web 2.0 gnerator

A very useful page where user can find web2.0 generator:

http://www.ifxplus.com/post/More-than-100-Web-20-Online-Generators.aspx

Friday, October 19, 2007

How to kill a process from CMD

We can kill a list of same process from cmd by using:

taskkill /IM $processnName

Tuesday, October 16, 2007

PHP useful get date function


<?php
$now = time();
$tomorrow  = mktime(0, 0, 0, date("m", $now)  , date("d", $now)+1, date("Y", $now));
$lastmonth = mktime(0, 0, 0, date("m", $now)-1, date("d", $now),  date("Y", $now));
$nextyear  = mktime(0, 0, 0, date("m", $now),  date("d", $now),  date("Y", $now)+1);
?>

Tuesday, October 09, 2007

Net send

Net send is a useful function to send immediate message to another computer in the same network. Without using 3rd party software, you can use "net send" command to send message. Below is how to enable net send service.

1. To use net send command, the "Messager" service must be enabled in the window service pane.
2. After the service is enabled, open up a command prompt, then type net send {Computer Name} message
ex: net send leoman hi

Thursday, July 19, 2007

PHP: Date and Time manipulation

In PHP, we can convert timestamp to readable format by using date() function.
Ex: date('y, m, d', timestamp)

To convert a readable format to timestampe using: strtotime();
Ex: $start_time = strtotime($row->date.' '.$row->start_time);

Wednesday, March 14, 2007

Wireless zero config service in winxp

Another example that proves Privacy and Security can not stay along with Convenience, the wireless zero config service in window xp. With this service turn on, an xp machine will automatically search for network from its preferred network list, which was build in the past which the machine used to connect to the internet. To find this network, the machine will periodically send out prone request that with SSID from teh preferred list in order to try connect the the network. The problem is, if someone sniffing and catch this wi-fi packet, he would know all these SSID, which is not cool at all.

Yeah, it is true that the wirelss zero configure brought convenience that it helps a user to reconnect to the internet automatically; however, it can also expose all the SSID to the outside world. It would be better to turn this service off.

Download this update from microsoft to turn it off: Wireless Client Update for Windows XP with Service Pack 2

Monday, March 12, 2007

To find prime number


public class prime{
public static void main(String args[]){
for(int i = 0; i <= 100; i++){
if(isPrime(i))
System.out.println(i);
}
}

public static boolean isPrime(int checkNumber) {
double root = Math.sqrt(checkNumber);
for (int i = 2; i <= root; i++) {
if (checkNumber % i == 0)
return false;
}
return true;
}
}

Wednesday, March 07, 2007

Check if a string is parlidrom


bool isparlidrom( char* str){

if(str == null){
return false
}
char* endStr = str;
while(*endStr != '\0'){
endStr++;
}
endStr--;

while(endStr > str){
if( *endStr ! = *str){
return false;
}
endStr--;
str++;
}
return true;
}

Monday, March 05, 2007

Open wireless access point

Last time I went to Toronto with my friend and we discovered that there are so many open wireless access point in downtown Toronto. I am glad that people were such generous that they willing to share bandwidth with others; however, open WAP may post serious security issue.
Why I saying this is because WAP acts like a hub in the network, anyone who put a "packet sniffer" onto the wire can monitor all traffic going in and out. The result is everything you do will be transparent.
I believe that it is necessary to encrypt our wireless network once we set the network up using WEP or WPA. But what if in the airport or coffee shop, where wireless connection is available but not encrypted? One approach is to turn on your local firewall. And possibly to use SSL or VPN.

Stwitch vs. Hubs

Switch and Hub is very similar but they are in fact different. Switch is more intelligence and bandwidth efficiency than hubs.

When packets get to a hub, a hub COPY and BROADCAST all received traffic.




When packets get to a switch, a switch only forward the traffic to its destination.

Thursday, March 01, 2007

Hardware DEP

Turn your hardware DEP on to protect your computer. DEP --> Data Executable Prevention. Nowadays, many computers has hardware DEP build=in; however, not many of us know about it. With DEP enable, a computer can at some point prevent from being control by malicious hackers. One example use of DEP is to make the stack as non-executable such that prevent buffer overflow exploit.

Wednesday, January 24, 2007

Email security issue

In Security Now episode 61, Leo and Steve talked about some of the security and privacy issue with ISP. The concern is that our ISP may be able to keep track and monitor what we are doing on the web IF we don't secure the our communication channel such as using SSL or VPN.
One interested topic get my attention is about sending secure email. You may not know that even if you encrypt your email data through SSL and send it, you still not secure your data because SSL encrypts the data at start point and decrypts the data at the end point. Therefore, your message is decrypted at your ISP, and then your ISP foward your DECRYPTED message to the destination. Notices that the link between your ISP to the destination is NOT encrypted, and your data is at risk of being exposed.

Saturday, January 20, 2007

Browser Security

First post in 2007, some thoughs about browser security.

Ever since Microsoft developed the so called AtiveX (an dll program, origin from OLAP )which enabled executable code run on client machine, the security issue that relate to IE increase aggressively.

Unlike traditional scripting language such as VB script, Java script who run within the sandbox environment ( executable code is restrict inside the interpreter, like JVM ), AtiveX code can run on the client machine freely. By which mean, ativeX opens a big door for the attackers to take over control the user's computer. Although, many modern technology make sure of activex to bring cool effect, such as the Macromedia Flash; the downside of activeX is incredible overhead. I surely believe people known a the spy ware called the Gator. Thanks to activeX.

Traditional internet concept is only to deliver TEXTUAL static page to the client; however, nowadays, server will even deliver executable codes to the client. Man~~~ that too danger... because there are many malicious code out there on the web. If I am you, I will shied myself up by setting my browser security as high as possible to avoid possible attack.

The browser is like a pioneer, it take you to any place on the web everyday. Imaging that you are exploring a new territory where you never been to before ("Good luck!! hold your breath~~). Will you scare that you be attacked by wild animal. Same concept apply to today's world wide web. Therefore, better shied yourself up while browsing the web.

A little tips from Steve Gibson, an highly intelligent security guy, teaches you to shied up yourself in IE. In IE, there's something call the zone level setting in the preference. User can set that level to the highest level, once you do that, you are disabling all the executable scripting from running in your computer. and then there is a thing called "Trusted zone", where you can specify which sites you will trust and allow it to run executable script.