1/31/2007

Unzip .tar.gz in linux


$ gzip -d httpd-NN.tar.gz
$ tar xvf httpd-NN.tar
$ cd httpd-NN

1/30/2007

Host file in linux

/etc/hosts

1/28/2007

Hack

http://www.informit.com/articles/article.asp?p=603037&seqNum=6&rl=1

How to implement Session in python

According to my research, there are two ways:
1. We can use Session Token (SID). That's an arbitrary string linked to a user. We can save the SID in a database (server) and the cookie file(client). Then we can compare them to make sure the cookie file is a valid one. The expiration date should be specified.
2. We can encrypt the username/password and date to a cookie file which is save on the server side and client side at the same time. Each time we can retrieve the username/password from the encrypted cookie file and compare the server side one and the client side one.

Why do we need to save encrypted password in the database

When someone gets all the informaiton in the database, he still can't know the password so he can't login as the original users. Thus the encrypted passwords can improve the safety of a web site.

1/27/2007

Random string in Python

from whrandom import choice
import string

def GenPasswd():
chars = string.letters + string.digits
for i in range(8):
newpasswd = newpasswd + choice(chars)
return newpasswd

def GenPasswd2(length=8, chars=string.letters + string.digits):
return ''.join([choice(chars) for i in range(length)])

Cookie doesn't work

When I used Python to creat cookies, it didn't work and I tried hard to figure it out. Finally I found that the cookie must be printed out so that it can be sent in the header. For example:
c = Cookie.SimpleCookie()
c["user"]="python"
print c.output()
print "Content-Type: text/html\n"

The following one won't work:
c = Cookie.SimpleCookie()
c["user"]="python"
print "Content-Type: text/html\n"
print c.output()
This is because the c is printed out as html content instead of header.

1/25/2007

innerText doesn't work for Mozilla, Firefox, etc. Just for IE

Create function like innerText
As you may have figured out innerText is IE only. That means that browsers like Mozilla, Firefox, and Netscape will return undefined. If you do not know what innerText does, it strips out all of the tags so you only see the text.

For example, if a div contains the HTML Eric, innerHTML would return Eric while innerText will return Eric.

Now to make innerHTML act the same we need to use some regular expressions with the strings replace() method.

Now the basic pattern we need to match is or or or

Now the regular expression we need to use is /<\/?[^>]+>/gi

If you do not know regular expressions here is a quick explanation:

  • / - Starts the regular expression
  • < - Match the less than sign
  • \/ - Escape the character / so it can be matched (Without the \ you would be saying it is the end of the reg exp.)
  • ? - Match the / character 0 or 1 times
  • [^>] - Match any character but greater than sign
  • + - Match [^>] one or more times
  • > - Match greater than sign
  • / - End the regular expression
  • gi - Tells regular expression to match global and ignore the case
So now the function to replace the text would look like:
http://radio.javaranch.com/pascarello/2005/01/14/1105721395000.html

CSS Properties: Display vs. Visibility

http://www.devx.com/tips/Tip/13638

Internet Explorer uses cache for "get" request

http://en.wikipedia.org/wiki/XMLHttpRequest#Microsoft_Internet_Explorer_cache_issues
If we use XMLHttpRequest, the web page may not be refreshed. In this case, we can add &sid=Math.random() to force the browser to reload.

Get key press event using JavaScript

http://www.geekpedia.com/tutorial138_Get-key-press-event-using-JavaScript.html

1/22/2007

MySQL CHAR and VARCHAR Difference

CHAR and VARCHAR differ in storing and retrieving data values. Both of them use a number (e.g. CHAR(30), VARCHAR(30)) to indicate the length of string that they can hold, but CHAR will use definitely 30 bytes when it stores a string less than 30. VARCHAR will use the actual length of the string, such as 20 bytes (string length) to store (plus 1 byte to store the length, so 21 bytes).

1/21/2007

HTTP Cookies

Cookies are used by Web servers to differentiate users and to operate in a way that depends on the user. Cookies were invented for realizing a virtual shopping basket: this is a virtual device in which the user can "place" items to purchase, so that users can navigate a site where items are shown, adding or removing items from the shopping basket at any time. Cookies allow for the content of the shopping cart to depend on the user's actions.
Allowing users to log in to a website is another use of cookies. Users typically log in by inserting their credentials into a login page; cookies allow the server to know that the user is already authenticated, and therefore is allowed to access services or perform operations that are restricted to logged-in users.
Several websites also use cookies for personalization based on users' preferences. Sites that require authentication often use this feature, although it is also present on sites not requiring authentication. Personalization includes presentation and functionality. For example, the Wikipedia Web site allows authenticated users to choose the webpage skin they like best; the Google search engine allows users (even non-registered ones) to decide how many search results per page they want to see.
Cookies are also used to track users across a website. Third-party cookies and Web bugs, explained below, also allow for tracking across multiple sites. Tracking within a site is typically done with the aim of producing usage statistics, while tracking across sites is typically used by advertising companies to produce anonymous user profiles, which are then used to target advertising (deciding which advertising image to show) based on the user profile.

For those of you who can't use Dell Axim 51v with a bluetooth headset

Please download the package and install it. It rocks!
http://www.aximsite.com/boards/archive/index.php/t-122247.html

1/18/2007

AUTOCOMMIT when using Python MySQLdb module with MySQL database

When you use the MySQLdb module to update a table in MySQL database, you may find that the table is not changed at all. This is because for some reason the autocommit is set to FALSE. To reflect your change, you should set db.autocommit(True)

date --date="Dec 01 03:23:43 PST 2005" +"%s"

A linux command date

MySQL Tutorial

http://www.thescripts.com/serversidescripting/mysql/tutorials/introductiontomysql/index.html

1/17/2007

javascript:void

Sometimes, you may need to call some JavaSript from within a link. Normally, when you click a link, the browser loads a new page (or refreshes the same page).

This might not always be desirable. For example, you might only want to dynamically update a form field when the user clicks a link.

To prevent the load from refreshing, you use the JavaScript void() function and pass a parameter of 0 (zero).

1/15/2007

Python and IIS

Searth by using Google: IIS python
You will find an article in Microsoft Help and Support: http://support.microsoft.com/kb/276494

Note:
In this article, it mentioned the test.py file.
It works well with IE, but it doesn't work with Firefox. You must DELETE the first two lines (print 'Content-type: text/html') to make it work for Firefox.

Why does Internet Information Server (IIS) want a password?

Key words: IIS | Prompt for a password | Firefox | IE | Internet Explorer
Most users who follow the steps in my article how do I host my web site at home? have no trouble setting up Internet Information Server. But a few discover that Internet Information Server demands a username and password whenever someone else tries to access the web site. Usually the administrator can get in just fine - if they use Internet Explorer on the same computer that is running the web server. But Firefox displays the password prompt, and users on other computers see it too. Nothing users do will get them into the site. What's the problem?

99% of the time, this is because Internet Information Server comes with a set of complicated ASP pages by default, pages that are supposed to be for the administrator only. If the webmaster deletes these before installing their own content in the web site home directory, there's no problem. But if these files are left in place, no one else can access the web site.

The simplest way to remove Microsoft's less-than-helpful default files from your web site is to delete the current contents of your web site's home directory, then copy your own content into place.
If you have already created pages of your own, and they only exist in your web site's home directory, don't delete your own work! Obviously, you'll want to remove only the files you don't recognize - Microsoft's files. Hopefully you have another copy of your own work elsewhere and you can just purge the contents of the directory.
Finding And Cleaning Your Web Site's Home Directory
More than likely, your new web site's home directory is C:\Inetpub\wwwroot. But you can check this in the control panel of Internet Information Server:

1. Start -> Settings -> Control Panel -> Administrative Tools

2. Double-click "Internet Information Services"

3. In the tree at left, right-click your web site or "Default Web Site," and pick "Properties"

4. Click on the "Home Directory" tab

5. Note the path in the "Local Path:" setting.

6. Double-click "My Computer" and navigate to your web site's home directory, as found in step 5.

7. Make absolutely sure you are looking at the contents of your web site's home directory, not its parent (C:\Inetpub\wwwroot, NOT C:\Inetpub). Also make sure that you have other copies of files that are important to you, or copy them to safety elsewhere at this time.

8. Use "Select All" to select all of the files in your web site's home directory. You may see warnings that hidden files were not selected. This is OK.

9. Right-click over any of the selected files and select "Delete" to remove all of them.

10. Copy your own content into place. Make sure you have a home page called index.htm (if your pages are in HTML) or default.asp (if your pages are ASP pages). Other names, such as index.html, might not be recognized as a home page for your site.

11. Try accessing the site again with Firefox, or from another computer. You should gain access to your home page.

"Directory Listing Denied" errors
If you see the error message "Directory Listing Denied" when you attempt to visit the home page of your site, you probably haven't created an "index pge." You need to create an HTML page called index.htm, or an ASP page called default.asp, to serve as your site's home page. A freshly installed copy of IIS is smart enough to recognize either of these names as the home page for the entire folder. so that's what you see if you access http://localhost from a web browser running on the server itself.
Granting Anonymous Access To Your Web Site
In rare cases, you may find that user are still denied access or shown password prompts even after you replace Microsoft's content with your own. This is usually a file permissions problem. Or you might not have anonymous access to your web site turned on. Either way, we can fix it!
Turning On Anonymous Access
Turning on anonymous access to your web site is easy. Just follow these steps:

1. Start -> Settings -> Control Panel -> Administrative Tools

2. Double-click "Internet Information Services"

3. In the tree at left, right-click your web site or "Default Web Site," and pick "Properties"

4. Select the "Directory Security" tab

5. Click "Enable anonymous access and edit the authentication methods for this resource"

6. Make sure the "Anonymous access" box is checked. The "User name:" field will be sent to IUSR_COMPUTERNAME, where "computername" will be the name of your computer. The "Allow IIS to control password" box should also be checked. If these settings are correct, don't change them.

When you're satisfied with your settings, click "OK." Other users should be able to access your site now. If not, read on for one more possibility.

Fixing Your Home Directory's Permissions
Now that you know where your web site's home directory is, it's time to fix the permissions so that the files can be accessed anonymously (that is, by users who are not logged in). Normally this happens by default in a web site home directory, but there are occasional exceptions. Just follow these steps.

1. Double-click "My Computer" on your desktop

2. Browse down to the level just above your web site's home directory, right-click your web site's home directory, and select "Properties"

3. Select the "Security" tab. If you do not see the "Security" tab, follow the steps in the box that follows.
If You Do Not See The Security Tab

Windows XP computers that are not part of a domain do not show the security tab by default. This is easy to fix:

A. Go to "My Computer."

B. Select "Folder Options" from the "Tools" menu.

C. Scroll to the bottom of "Advanced settings."

D. UN-check the "Use simple file sharing" box.

E. Click "OK."

Now you're ready to continue following the instructions for making your web site's home directory accessible to anonymous users.
4. You should be looking at the "Security" tab for your web site home directory at this point.

5. Select "Internet Guest Account" from the list of users.

6. Check the "Read & Execute" box. This should grant sufficient access for future files created in your home directory. But we still have some work to do for existing files.

7. Click "OK" to close the Properties dialog box.

If You Still Have Problems
This article addresses the most common causes of password prompts and other unwanted behavior from a newly configured Internet Information Server. Of course, there are other possibilities. For further reading, I recommend the article Troubleshooting IIS Access Problems at the 15seconds web site.