Sunday, September 16, 2007

vim note: grep

The handy tool grep from Linux can also be used in VIM, by just typing ":grep PATTERN FILES" in the command mode. It finds the string according to the input pattern from all designated files. Note that FILES needs to be in the format of absolute path. Wildcard, such as "c:\\files\\*.txt" can be used. In version 7.0, "\\" is required for the path splitter under windows. "/" does not seem to work. Regular expression could be used for PATTERN.

By default, only the first search result is shown. Use ":cn" to navigate to the next search result, and use ":cp" to navigate to the previous result. The navigation can jump from one file to another, of course. When multiple buffers (or files) are opened, use ":bn" and ":bp" to jump from one file to the other. Use ":bd" to remove a file from buffers.

Saturday, September 15, 2007

mod_python note: sessions

mod_python has its own modules for Session and Cookies. The mod_python documentation contains consise explanations about the usage. Cookies are used for session maintenance. An introduction can be found here.
Python supports cookies by a built in module, which is probably developed for CGI programming before adopted into Python core. mod_python can use this module as well for cookies.

Python note: using the windows clipboard

The windows clipboard allows HTML content to be processed. A specification about the specific format can be found here.

A python support for the windows clipboard is found in this site package.

A recipe for using the clipboard, written by Phillip Piper, can be found from this web page. I gave a simplified version of putting something into the clipboard at here.

Sunday, September 09, 2007

Apach note: mod_python global objects

The term "global objects" in this article means the objects that exists from the starting of the web server until the shutdown. An example of such global objects is a database proxy, which is initialized at server start, and handles database calls during all the serving session.

At the first look, it appeared to be no place for defining global objects, for mod_python runs on the per-request basis, with each request being mapped to a call.

However, mod_python has the advantage over CGI that a python interpreter is created for one virtual server to handle all requests to server. The interpreter starts when the server starts, and last until the server is shut down. Here is a reference for the multiple interpreter mechanism for the mod_python module.

To take this advantage, global variables can be place in the global namespace for the Python interpreter. For example, it could be intitilized from a module's namespace.

Apache note: set up a mod_python server

Though the building of mod_python can be a little daunting under UNIX, it's quite easy to start a mod_python server with apache under the windows platform.

Suppose that a machine has python installed.

First download the apache http server from the apache web site. (you need to find the download site by following the links from the main site) Current version is 2.2.

Second download the mod_python binaries for windows from the mod_python web site. Current version is 3.3

Third install apache following the instructions.

Fourth install mod_python following the instructions. The information in the last page is important. The LoadModule command must be added to the httpd.conf file for apache so that the http server recognizes mod_python.

The installation test can be found the documentation Note that*.py will work. This is because the request url is handed to as parameters.

Latex note: how to shrink tables

To reduce the size of a table, two general methods can be used.

1. Shrink the the font size.
For example, use \small{content} instead of content in the table cell.

2. Squeeze space between columns.
For example, a table could be written in the following way