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 http://127.0.0.1/test/*.py will work. This is because the request url is handed to mptest.py as parameters.
Sunday, September 09, 2007
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
\begin{tabular}
\setlength{\tabcolsep}{1pt}
...
\end{tabular}
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
\begin{tabular}
\setlength{\tabcolsep}{1pt}
...
\end{tabular}
Saturday, August 25, 2007
C++ note: unsigned int
Suppose a is an unsigned int, the expression a>-1 is always false. This is because the type of -1 is decided by the type of a, and it becomes maxint.
Hint: remember the unsigned int variables in the code and do not compare them with a minus number. The comparison itself is not necessary.
Hint: remember the unsigned int variables in the code and do not compare them with a minus number. The comparison itself is not necessary.
Wednesday, August 01, 2007
Linux note: how to disable output
One way is adding a redirection to the command to execute:
command >/dev/null
In the above line, command is executed with its output redirected to /dev/null.
More notes about the above syntax. ">" is the operator to direct the output of command to a file. In this case, the file is the special device /dev/null. The standard output (using ">") and the error output ("2>") can both be redirected. To redirect the standard output and the error output at the same time, use ("&>"), and to append the redirected output to a file, use (">>").
Disabling output is necessary in many situations. For example, when using nohup, the system output is put into the file nohup.out. If the disk space is limited, we may want this file to be as small as possible. Therefore, we may put necessary information into the error output, and redirect the standard output to null.
command >/dev/null
In the above line, command is executed with its output redirected to /dev/null.
More notes about the above syntax. ">" is the operator to direct the output of command to a file. In this case, the file is the special device /dev/null. The standard output (using ">") and the error output ("2>") can both be redirected. To redirect the standard output and the error output at the same time, use ("&>"), and to append the redirected output to a file, use (">>").
Disabling output is necessary in many situations. For example, when using nohup, the system output is put into the file nohup.out. If the disk space is limited, we may want this file to be as small as possible. Therefore, we may put necessary information into the error output, and redirect the standard output to null.
Saturday, June 16, 2007
VIM note: viewport
It's sometimes necessary to split the view of a file into many windows. Below is a cheatsheet copied from here.
:sp will split the Vim window horizontally. Can be written out entirely as :split .
:vsp will split the Vim window vertically. Can be written out as :vsplit .
Ctrl-w Ctrl-w moves between Vim viewports.
Ctrl-w j moves one viewport down.
Ctrl-w k moves one viewport up.
Ctrl-w h moves one viewport to the left.
Ctrl-w l moves one viewport to the right.
Ctrl-w = tells Vim to resize viewports to be of equal size.
Ctrl-w - reduce active viewport by one line.
Ctrl-w + increase active viewport by one line.
Ctrl-w q will close the active window.
Ctrl-w r will rotate windows to the right.
Ctrl-w R will rotate windows to the left.
:sp will split the Vim window horizontally. Can be written out entirely as :split .
:vsp will split the Vim window vertically. Can be written out as :vsplit .
Ctrl-w Ctrl-w moves between Vim viewports.
Ctrl-w j moves one viewport down.
Ctrl-w k moves one viewport up.
Ctrl-w h moves one viewport to the left.
Ctrl-w l moves one viewport to the right.
Ctrl-w = tells Vim to resize viewports to be of equal size.
Ctrl-w - reduce active viewport by one line.
Ctrl-w + increase active viewport by one line.
Ctrl-w q will close the active window.
Ctrl-w r will rotate windows to the right.
Ctrl-w R will rotate windows to the left.
Tuesday, June 12, 2007
C++ note: mix with C code
The easiest way to make use of C modules is including the header files with
extern "C"
{
#include <a_c_module.h>
}
Then the C++ compiler knows that the header defines the structures in the c way, and will compile references in the C++ module in a compatible way.
For the standard libraries name "cblabla", extern "C" is already included in the header files. This is the reason why modules etc can be included directly.
For the linker, different vendors might have different standards to mangle the refernece names. Therefore, it needs to be confirmed that the C modules are compiled in a compatible way as the C++ module.
Making use of C++ modules from C modules is harder than the other way around. For the C++ programmers, it might be possible to turn some necessary C files into the C++ format and then compile the whole project as C++. Many files can be kept as the C modules and linked explicitly.
extern "C"
{
#include <a_c_module.h>
}
Then the C++ compiler knows that the header defines the structures in the c way, and will compile references in the C++ module in a compatible way.
For the standard libraries name "cblabla", extern "C" is already included in the header files. This is the reason why modules
For the linker, different vendors might have different standards to mangle the refernece names. Therefore, it needs to be confirmed that the C modules are compiled in a compatible way as the C++ module.
Making use of C++ modules from C modules is harder than the other way around. For the C++ programmers, it might be possible to turn some necessary C files into the C++ format and then compile the whole project as C++. Many files can be kept as the C modules and linked explicitly.
Monday, June 04, 2007
Javascript note: about the regular expressions
Javascript supports regular expressions as a built in language feature. Regular expressions are enclosed between two "/".
Here is a tutorial.
Here is a tutorial.
Tuesday, May 29, 2007
Thursday, May 24, 2007
C++ note: static variables
C++ is different from Java and csharp in the way classes are defined. The header files in C++ are not actually compiled into the object - they are only an indicator of how the data structures are organized, i.e. the reference to a member is the base address plus how much offside. All variables and functions to appear inside objects must be defined in the cpp files. The methods in header files are treated as inline methods.
Now static variables are those that occur in the heap. They exist from the beginning until the finishing of the running of program. All variables defined in a cpp file are static variables, they are by default external linked. If a variable defined in a cpp file has explicit "static" modifier, it is internal linked and can only be accessed by the module. Static variables can also be defined inside functions and methods, in which case they are still present all through the running of a program; however, they can only be accessed from the name scope in which they are defined. The accessibility is the only difference between static variables. Lastly, constants in header files are also taken as static variables. This is why values can be assigned to them in the header files.
Now static variables are those that occur in the heap. They exist from the beginning until the finishing of the running of program. All variables defined in a cpp file are static variables, they are by default external linked. If a variable defined in a cpp file has explicit "static" modifier, it is internal linked and can only be accessed by the module. Static variables can also be defined inside functions and methods, in which case they are still present all through the running of a program; however, they can only be accessed from the name scope in which they are defined. The accessibility is the only difference between static variables. Lastly, constants in header files are also taken as static variables. This is why values can be assigned to them in the header files.
Tuesday, May 22, 2007
g++ note: don't forget -c option
I made a mistake when writing Makefile today, by missing to put -c for the compile-only step. It led to a lot of unresolved external references.
Monday, May 14, 2007
Latex note: generating letter size papers
latex paper
dvips -t letterSize -Ppdf -G0 paper
ps2pdf -sPAPERSIZE=letter paper.ps
If the last step doesn't work, try the following command:
ps2pdf paper.ps
It should work because the ps file already contains size information.
dvips -t letterSize -Ppdf -G0 paper
ps2pdf -sPAPERSIZE=letter paper.ps
If the last step doesn't work, try the following command:
ps2pdf paper.ps
It should work because the ps file already contains size information.
Thursday, April 12, 2007
Latex note: more on making EPS graphs from MS Office
Please see my previous article about how to generate an eps chart from from MS Excel.
You can also insert Word pictures into eps. The mechanism is the same as Excel. First, make an empty word document or page to draw the vector graphs. Then print the page, using general eps printer. Lastly, modify the page bounding box of the eps file so that it fits the graph.
There is one thing to notice though: the coordinate counts from bottom left to top right! If the four numbers represent top left and bottom right, the picture will still show in latex document, but it will be sqeezed together with text because the size is below zero!
You can also insert Word pictures into eps. The mechanism is the same as Excel. First, make an empty word document or page to draw the vector graphs. Then print the page, using general eps printer. Lastly, modify the page bounding box of the eps file so that it fits the graph.
There is one thing to notice though: the coordinate counts from bottom left to top right! If the four numbers represent top left and bottom right, the picture will still show in latex document, but it will be sqeezed together with text because the size is below zero!
Latex note: use minipage to align a figure of text to center, while keeping text aligned to left
Sometimes we need to align text with multiple lines to the center of page.
\begin{figure}[t]
\centering
this is first line \\
\hspace*{0.5cm} this is second line \\
this is third line \\
this is fourth line
\caption{caption}
\label{l}
\end{figure}
The above may not work because all lines are aligned to center, and they look messy on the left border. The solution is using a minipage to align text inside figure.
\begin{figure}[t]
\centering
\begin{minipage}[t]{0.5\textwidth}
this is first line \\
\hspace*{0.5cm} this is second line \\
this is third line \\
this is fourth line
\end{minipage}
\caption{caption}
\label{l}
\end{figure}
\begin{figure}[t]
\centering
this is first line \\
\hspace*{0.5cm} this is second line \\
this is third line \\
this is fourth line
\caption{caption}
\label{l}
\end{figure}
The above may not work because all lines are aligned to center, and they look messy on the left border. The solution is using a minipage to align text inside figure.
\begin{figure}[t]
\centering
\begin{minipage}[t]{0.5\textwidth}
this is first line \\
\hspace*{0.5cm} this is second line \\
this is third line \\
this is fourth line
\end{minipage}
\caption{caption}
\label{l}
\end{figure}
Wednesday, April 11, 2007
Latex note: protect citations in caption
\caption{xxx \cite{yyy}} won't work, it won't compile with latex sometimes.
use \caption{xxx {\protect \cite{yyy}}} instead.
use \caption{xxx {\protect \cite{yyy}}} instead.
Saturday, March 31, 2007
Python note: os.path.join unexpected result for paths beginning with "/" or "\"
Need to pay attention when joining paths beginning with "/" (or "\" for windows).
os.path.join("c:\abc", "def", "ghi") -> no problem, c:\abc\def\ghi
os.path.join("c:\abc", "\def") -> outputs "\def".
os.path.join("c:\abc", "def", "ghi") -> no problem, c:\abc\def\ghi
os.path.join("c:\abc", "\def") -> outputs "\def".
Friday, March 23, 2007
C++ note: be careful with unsigned
I just made a mistake with an unsigned integer. It took me nearly an hour to debug, just to find that the subtle bug is caused by this:
if (a<b-2) ...
a = 0 b = 1
b is an unsigned integer.
The reason is that b-2 is interpreted as unsigned integer, and therefore the predicate wrong. The conclusion is that we should avoid using many minuses for unsigned.
if (a+2<b) is the solution for this problem
if (a<b-2) ...
a = 0 b = 1
b is an unsigned integer.
The reason is that b-2 is interpreted as unsigned integer, and therefore the predicate wrong. The conclusion is that we should avoid using many minuses for unsigned.
if (a+2<b) is the solution for this problem
Friday, January 12, 2007
Latex note: convert Excel charts to eps files
This tip applies to any chart from MS Office.
In short, in order to insert charts from Excel to your Latex document, you need to (1) print your chart from MS Office into an eps file; (2) modify the bounding box in the output.
You need to install Generic Postscript Printer from Adobe first. Link the printer to the port FILE: . After installation, set its output option from Property -> Printing preferences... -> Advanced -> Postscript options -> Postscript output opion to encapsulated postscript format (eps).
This printer can be used to print the chart to an eps file.
The EPS file contains borders which defines where the chart is. Use postscript to open this EPS file, then use a text editor to open it simultaneously. Tick options -> eps clip from postscript. Then edit the line %%BoundingBox: ... from the text editor. Adjust the size of the chart in eps so that the clip fits well to the chart. Then save EPS.
Now you are done. Insert the chart into latex!
In short, in order to insert charts from Excel to your Latex document, you need to (1) print your chart from MS Office into an eps file; (2) modify the bounding box in the output.
You need to install Generic Postscript Printer from Adobe first. Link the printer to the port FILE: . After installation, set its output option from Property -> Printing preferences... -> Advanced -> Postscript options -> Postscript output opion to encapsulated postscript format (eps).
This printer can be used to print the chart to an eps file.
The EPS file contains borders which defines where the chart is. Use postscript to open this EPS file, then use a text editor to open it simultaneously. Tick options -> eps clip from postscript. Then edit the line %%BoundingBox: ... from the text editor. Adjust the size of the chart in eps so that the clip fits well to the chart. Then save EPS.
Now you are done. Insert the chart into latex!
Tuesday, November 14, 2006
C++ note: be careful with ifstream
The following is the correct and actually standard way of reading something
while(file.good())
{
file >> s;
cout << s;
}
However, the following is wrong:
while(file.good())
{
file.get(t);
cout << t ;
}
it will normally repeat the last char in the file. The reason is that file.good only changes after get() is called. This is the way
while(file.get(t))
{
cout << t ;
}
file.get(t) will return success if the process works.
while(file.good())
{
file >> s;
cout << s;
}
However, the following is wrong:
while(file.good())
{
file.get(t);
cout << t ;
}
it will normally repeat the last char in the file. The reason is that file.good only changes after get() is called. This is the way
while(file.get(t))
{
cout << t ;
}
file.get(t) will return success if the process works.
Wednesday, November 08, 2006
C++ note: TRACE macros
#ifdef DEBUG
#define TRACE(x) { cout << x << endl; cout.flush(); }
#else
#define TRACE(x)
#endif
#ifdef DEBUG
#define RUN_ON_DEBUG(x) x
#else
#define RUN_ON_DEBUG(x)
#endif
#define TRACE(x) { cout << x << endl; cout.flush(); }
#else
#define TRACE(x)
#endif
#ifdef DEBUG
#define RUN_ON_DEBUG(x) x
#else
#define RUN_ON_DEBUG(x)
#endif
Tuesday, October 31, 2006
Python note: the value and the display of a unicode string
Sometimes it is necessary to view the unicode encoding of a special character or to see the display of a certain unicode code. Here is some example code.
print '\xe6\x8d\xae'.decode("utf-8")
<displays the unicode character>
print repr(<the unicode character here>)
'\xe6\x8d\xae'
print '\xe6\x8d\xae'.decode("utf-8")
<displays the unicode character>
print repr(<the unicode character here>)
'\xe6\x8d\xae'
Subscribe to:
Posts (Atom)