Customize directory listing in Apache server

June 10th, 2011 18 Views 0 Comments

On web server, when there is no index.html file in the folder, the files are listed if the Options Indexes is turned on. Sometimes we want to look like in a different way, i.e. displayed with columns, order by one column, change the width of one column. There is already one module that can do this: autoindex_module. To check this, open the file /etc/init.d/apache2/mods-enabled/autoindex.load on Linux or conf/httpd.conf under the Apache's installation directory, verify if the "load" statement is there. On Linux, it is LoadModule autoindex_module /usr/lib/apache2/modules/mod_autoindex.so. There are many options to the autoindex_module. Open the file /etc/init.d/apache2/mods-enabled/autoindex.conf for more details, i.e. IndexOptions. To set the file listing displayed in certain order of a column, use the directive of IndexOrderDefault. The directive is followed by two parameters: the first one is the direction of the sort: Descending and Ascending; the second one is the name of the field to sort. For example, if you want the files sorted by "last modified date", use the directive of IndexOrderDefault Descending Date. To set the width of one column, there is one example at the top of the autoindex.conf file. It is indicated as one option of IndexOptions directive. It is in the format of ". For example, NameWidth is to specify the width of name column. The value of "*" is given to resize the column to wherever it fits for all texts. That's how the default options work on Linux. Here is the sample of the first line: IndexOptions FancyIndexing VersionSort HTMLTable NameWidth=* DescriptionWidth=* Charset=UTF-8.

Categories: Default Tags:   |

Running Javascript in Emacs interactively with Firefox

June 28th, 2010 21 Views 0 Comments
The javascript mode and moz.el offers the convenience to run the javascript code from within Emacs. Here are steps of the configurations:

Configure Javascript Mode

There are multiple options of javascript mode for emacs, ref here: http://www.emacswiki.org/emacs/JavaScriptMode. Choose one you like. I use the js2-mode. Follow the instructions to install it. Add the following into .emacs:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; enhanced javascript ide mode for emacs (autoload 'js2-mode "js2" nil t) (add-to-list 'auto-mode-alist '("\\.js$" . js2-mode))

Configure Mozilla mode

download the moz.el and put it in your lisp path. Add the following into your .emacs:
;; use moz-repl to work interactively with mozilla browser ;; use following snippets if you are using js2-mode (autoload 'moz-minor-mode "moz" "Mozilla Minor and Inferior Mozilla Modes" t) (add-hook 'js2-mode-hook 'js2-custom-setup) (defun js2-custom-setup () (moz-minor-mode 1))

Install MozRepl Extension

Before it is ready to run the javascript codes in Emacs, an extension of MozRepl for firefox is required. The MozRepl extension is an agent listening the request from Emacs. After the installation, start it from the Tools -> MozRepl -> Start. Now you can run the javascript from within Emacs. The following commands are available to use in javascript mode in Emacs.
  • C-c C-s: open a MozRepl interaction buffer and switch to it
  • C-c C-l: save the current buffer and load it in MozRepl
  • C-M-x: send the current function (as recognized by c-mark-function) to MozRepl
  • C-c C-c: send the current function to MozRepl and switch to the interaction buffer
  • C-c C-r: send the current region to MozRepl
Categories: Web Tags:   |

Mounting Digital Camera

March 11th, 2010 5 Views 0 Comments
Connect the digital camera via usb cable, it is recognized as /dev/sd[a|b][num]. Before the mount, the universal identifier needs to be extracted:
$device="/dev/sdb1" echo "Identifying the device $device ...." out=`sudo blkid $device` echo "Extracting UUID of the device ...."
The $out shows device information of mounted camera, then analyze and extracts the universal identifier:
uuid=`echo $out | awk '{print $3}' | sed 's/UUID=\"//g' | sed 's/\"$//'`
After the $uuid is retrieved, mount the camera with the -U option:
sudo mount -U $uuid $mount_point -o uid=`whoami`
. The -o uid=`whoami` specifies the owner of the mount point. The $mount_point is the folder you mount the device at.

Categories: Debian Linux Tags:   |

Yet Another Sudoku Puzzle Solver using Python

February 16th, 2010 5 Views 0 Comments
This is a follow up of the article about sudoku puzzle solver. The original article is about the solver using awk. I converted it into python version. It mainly uses lookup on dictionary data. It turns out be little faster than query on list.

michael@debian:python$ time awk -f ../shell/solve.awk sudoku01.dat
# Searches=134214
  2 8 3  6 7 1  9 4 5
  9 7 6  5 4 8  2 3 1
  4 1 5  3 9 2  8 7 6

  5 6 7  4 1 9  3 8 2
  8 3 4  2 6 7  1 5 9
  1 9 2  8 3 5  4 6 7

  3 2 1  7 8 6  5 9 4
  7 5 8  9 2 4  6 1 3
  6 4 9  1 5 3  7 2 8

real    0m3.241s
user    0m3.176s
sys    0m0.020s
Here is the result of python version:

michael@debian:python$ time python sudoku.py sudoku01.dat
Search count = 134214

  2 8 3   6 7 1   9 4 5
  9 7 6   5 4 8   2 3 1
  4 1 5   3 9 2   8 7 6

  5 6 7   4 1 9   3 8 2
  8 3 4   2 6 7   1 5 9
  1 9 2   8 3 5   4 6 7

  3 2 1   7 8 6   5 9 4
  7 5 8   9 2 4   6 1 3
  6 4 9   1 5 3   7 2 8

real    0m2.457s
user    0m2.388s
sys    0m0.024s

The algorithm is the same as described in the article. You can download the source code sudoku.py and the data file sudoku.dat

The matrix of the data file is 9x9. You can test it with the other 16x16 matrix and harder ones. However, the algorithm is the same.

Categories: Default Tags:   |

A GTK lib bug for Eclipse3.5

November 20th, 2009 6 Views 0 Comments
When upgraded GTK library to 2.17.x or above, the eclipse has no response on button-click action. It's a bug on gtk library, the temporary solution is to export the environment variable GDK_NATIVE_WINDOWS before launching eclipse:
#!/bin/sh
export GDK_NATIVE_WINDOWS=1
$ECLIPSE_HOME/eclipse


Categories: Debian Java Linux Tags:   |

Quick Script to Compile LaTeX File

July 3rd, 2009 6 Views 0 Comments
When compiling .tex files, you have to compile it with various options or repeatedly for different features of the file in some cases. Here is a list of situations I have to compile the file with different options:
  • when compiling the regular .tex file, you only need to execute the command latex filename to generate .dvi file and then run dvipdf to produce the final pdf file. The commands in sequence is latex, dvipdf
  • For some simple .tex files, you only need to run pdflatex to quickly produce the .pdf file in one step.
  • For the file with bibliography, it gets boring, if you put your bibliography data into a separate bib file, you have to run bibtex command to generate the correct bib database for your article's reference. In this case, you have to run latex, [latex], bibtex, latex to produce the dvi file. The [latex] means it's optional since some previous updates on the bib file may require an extra recompilation to update to the correct references.
  • For some files with multiple separate bib files, you have to run bibtex multiple times to generate the database for each bib file. The command you have to execute in sequence will be latex, [latex], bibtex bu(#), latex, dvipdf. The meaning of [latex] is the same as above. The bibtex bu(#) means you need to run bibtex against each bu(#) generated, like bibtex bu1; bibtex bu2. This is different from the previous situation, so you have to change options to compile different files.
So I wrote the script to process all situations using only one command. It makes my work much easier and more convenient to compiling latex files with only one command. This is how the script works:
  • detect the input file information, and process the name and extension.
  • compile the file using latex, since this is the command required for all .tex files.
  • process the .aux file generated, and execute the corresponding bibtex command to generate the bib database. Currently supports the two situations mentioned above
  • produce the pdf file
The script outputs all verbose logs and warning information into a sub-directory names "logs", so user won't be flooded by all messages filled in his screen and the folder. Only the final pdf file is generated under the current directory. The option of mylatex clean is provided to clean up the files generated by previous compilation. The script file can be downloaded here.
Categories: LaTex Tags:   |

Customize Inlined Verbatim Environment

April 28th, 2009 5 Views 0 Comments
There are many places in paper where I use the inlined verbatim environment for source code: \verb=String s=. In some cases, I need to change the size of the code, so it becomes {\small \verb=String s=}. Here comes the problem, since the code are inlined all through the paper, if you change font size, like Huge, then you have to change all places of \small to \Huge. Therefore the best way is to define a new command containing \verb with font size as optional parameter. However, using \newcommand{\mycode}[1]{\verb!#1!} to redefine \verb won't work, because the verb command is not allowed to be redefined. The alternative is to use lstset environment. So first we define the style of lstset in the preamble part:
\lstdefinestyle{codestyle}{basicstyle=\ttfamily\small}
and then define the new command using lstset style:
\newcommand{\mycode}[1]{{\lstset{style=codestyle}\lstinline!#1!}}
Now, I only use the command \mycode to inline source code through the article. The font size can be easily modified only in preamble in definition of the style at once, changing \small to \Huge, or just remove it if you want it back to normal size.
Categories: LaTex Tags:   |

Complete Setup of Tomcat and Apache

April 28th, 2009 5 Views 0 Comments

Introduction

Apache is the webserver that accepts http request, finds the page requested, and sends back the content to client. However, In some web sites, the webpage is dynamically generated upon user's request. In this situation, the web server Apache needs a Help application to process the request. The Help Application receives the request forwarded by Apache, and sends back the generated webpages to Apache. Then webserver sends back to client (user or browser). This Help application is a standalone container to process dynamic web pages. Tomcat is such container, which is called web container. There are other types of container that processes business logic of application system, we call it business container. Enterprise JavaBean is deployed in business container, JSP and Servlet are deployed in web container. The business container and web container consititues the J2EE application server. Now first we setup the web containers.

Apache installation

The installation of apache is quite easy on Debian:
# apt-get install apache2 apache2-utils apache2.2-common apache2-mpm-prefork
After installation finishes, check out the directory /etc/apache2:
/etc/apache2/conf.d:
This directory is used to save the service's configuration files, for example: svn server, tomcat server.
/etc/apache2/ports.conf
This file specifies the port that apache server listens to. The default port is 80, you can specifiy multiple listening port for your multiple web applications.
/etc/apache2/sites-available
The folder where the applications are saved. The default application is rooted under /var/www/ with listening port 80. You can copy the default file to customize your own application. However, remember to add the port to the list of /etc/apache2/ports.conf if you have a different port for apache server. For example, I specify 8888 for my defalut web application rooted under $HOME/.www_repos/web. Then the /etc/apache2/sites-available/default file looks like this:
<VirtualHost *:8888> ServerAdmin michael@localhost DocumentRoot /home/michael/.www_repos/web <Directory /> Options FollowSymLinks AllowOverride None </Directory> ErrorLog /var/log/apache2/error.log LogLevel warn CustomLog /var/log/apache2/access.log combined </VirtualHost>
The /etc/apache2/ports.conf should be added the port 8888 with following codes:
# for web pages NameVirtualHost *:8888 Listen 8888
Whenever you add an application, you need to enable it in apache to load it in web server:
# a2ensite <name>
The default is enabled by default, you need to enable the new application with your specified name.

Tomcat Installation

Download standalone tomcat package from debian repository:
# apt-get install tomcat5.5 tomcat5.5-admin tomcat5.5-webapps
After finishes the installation, check out the directory structure of tomcat.
  • The default installation directory of tomcat5.5 is:
/usr/share/tomcat5.5
  • The default directory of deployed web application is:
/usr/share/tomcat5.5-webapps
  • The data of user deployed web application is stored at:
/var/lib/tomcat5.5/ /var/lib/tomcat5.5/webapps/
  • The default directory of deployed web application are linked as below:
/usr/share/tomcat5.5/webapps   --> /var/lib/tomcat5.5/webapps/tomcat5.5-webapps /var/lib/tomcat5.5/webapps/tomcat5.5-webapps  --> /usr/share/tomcat5.5-webapps
  • The configuration direcotry is:
/etc/tomcat5.5
Now add a customized user for management and administration, edit the file /etc/tomcat5.5/tomcat-users.xml, add the following line:
<user username="michael" password="michael" roles="tomcat,admin,manager"/>
Edit the file /etc/default/tomcat5.5 to change the security parameter of launching tomcat, change the following line
#TOMCAT5_SECURITY=yes
to
TOMCAT5_SECURITY=no
Setup the environment variables by editing /etc/environment:
JAVA_HOME="/usr/lib/jvm/java-6-sun" ANT_HOME="/usr/share/ant" CATALINA_HOME="/usr/share/tomcat5.5" CATALINA_BASE="/var/lib/tomcat5.5" CATALINA_OPTS="-server -Xms512M -Xmx512M"
Change the security policy by editing the file /etc/tomcat5.5/policy.d/50user.policy, add the following policy:
// to activate the admin-interface // http://lists.alioth.debian.org/pipermail/ // pkg-java-maintainers/2006-November/009749.html grant codeBase "file:/usr/share/struts1.2/struts.jar" { permission java.security.AllPermission; };
Now open your browser to test your tomcat server by going to http://localhost:8180/, if you can see the portal of tomcat, you have installed tomcat successfully. Go to http://localhost:8180/admin, login to the portal using the username added above, if you can login successfully, then you have configured tomcat server successfully.

Install Apache connector to Tomcat

Now it's time to connect the apache to tomcat. First install libapache2-mod-jk from debian repository:
# apt-get install libapache2-mod-jk
The configuration of connector package is at /etc/libapache2-mod-jk, edit the file /etc/libapache2-mod-jk/workers.properties, the parameter value might be different from your system depending on your system settings of tomcat and jdk.
workers.tomcat_home=/usr/share/tomcat5.5 workers.java_home=/usr/lib/jvm/java-6-sun ps=/ worker.list=ajp13_worker worker.ajp13_worker.port=8009 worker.ajp13_worker.host=localhost worker.ajp13_worker.type=ajp13 worker.ajp13_worker.lbfactor=1
Edit the connector's configuration file in apache /etc/apache2/conf.d/jk.conf (creat one if it doesn't exist on your system), the location of workers property file must be the same as above:
<IfModule mod_jk.c> JkWorkersFile /etc/lobapache2-mod-/workers.properties JkLogFile /var/log/apache2/mod_jk.log JkLogLevel error </IfModule>

Create Server Context for Tomcat

As mentioned in first section, we already have a default virtual host for static web pages at port 8888, now we are going to create another virtual host for tomcat container's use at a different port 9999. We create another sub folder tomcat under $HOME/.www_repos/, now the folder looks like this:
$HOME/.www_repos/web: for static web pages $HOME/.www_repos/tomcat: for web applications (jsp, servlet)
Create a file tomcat-host under /etc/apache2/sites-available, write the file with similar content as below (details explained in the first section):
<VirtualHost *:9999> JkMount /*.cfm default JkMount /*.cfc default JkMount /*.jsp default ServerName localhost ServerAdmin michael@localhost DocumentRoot /home/michael/.www_repos/tomcat ErrorLog /home/michael/.www_repos/tomcat/logs/error.log CustomLog /home/michael/.www_repos/tomcat/logs/access.log common <Location /WEB-INF/> AllowOverride None deny from all </Location> </VirtualHost>
Since we specified a different port, we also need to add the port listening to the ports.conf under /etc/apache2:
# for jsp/servlet container NameVirtualHost *:9999 Listen 9999
Now enable the virtual host and reload it by apache:
# a2ensite tomcat-host # /etc/init.d/apache2 reload
Configure tomcat server file of /etc/tomcat5.5/server.xml, set the corresponding parameter value to the same specified above, like appBase, logs:
<!--localhost --> <Host name="localhost" appBase="/home/michael/.www_repos/tomcat" unpackWARs="true" autoDeploy="true"> <Context path="" docBase="htdocs" debug="0" reloadable="true"/> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="/home/michael/.www_repos/tomcat/logs" prefix="tomcat_access_" suffix=".log" pattern="common" resolveHosts="false"/> </Host>
When all are done, restart the tomcat server and reload apache server:
# /etc/init.d/tomcat5.5 restart # /etc/init.d/apache2 restart
Categories: Default Web Web Tags:   |

使用XeTeX处理latex下的中文

September 19th, 2008 7 Views 0 Comments
一直都是在latex下用ieee journal或conf格式写英文,最近想把一些以前的笔记转到latex下做个合集,就有了大量的中文问题,CJK自带的UTF的gbsn和gbkai出来的效果不是特别满意,所以想把STHeiti也能包含进去或者使用windows的simsun或kai字体,尝试过为CJK专门生成这些字体包,发现太麻烦了,而且效果也没有太大改善,于是转到XeTeX下,将simsun,simkai和stheiti加载进去看了下,发现效果不错: 首先找出我的3个中文字体信息
$ fc-list 宋体,SimSun:style=Regular 楷体_GB2312,KaiTi_GB2312:style=Regular STHeiti:style=Regular
进入自己当前用户的配置目录建一个新的字体样式宏包目录,方便管理,比如:
/home/michael/.texmf-var/tex/xelatex/myfontcfg
如果没有就新建一个,进入此目录,新建文件myfontcfg.sty:
% my is the abbreviation of my name "Michael Yang" \ProvidesPackage{myfontcfg} \usepackage{fontspec,xunicode} \XeTeXlinebreaklocale "zh" \XeTeXlinebreakskip = 0pt plus 1pt minus 0.1pt % 分别定义字体名字 \newcommand\fontnamestheiti{STHeiti} \newcommand\fontnamesong{SimSun} \newcommand\fontnamekai{KaiTi_GB2312} \newcommand\fontnamemono{Bitstream Vera Sans Mono} \newcommand\fontnameroman{Bitstream Vera Serif} \setmainfont{\fontnamesong} \setsansfont{\fontnamekai} \setmonofont{\fontnamemono} % 新建字体命令: song, kai \newfontinstance\SONG{\fontnamesong} \newcommand{\song}[1]{{\SONG #1}} \newfontinstance\KAI{\fontnamekai} \newcommand{\kai}[1]{{\KAI #1}} \newfontinstance\HEI{\fontnamestheiti} \newcommand{\stheiti}[1]{{\HEI #1}}
然后更新ls-R数据库
# mktexlsr
测试一个简单文档:
\documentclass[12pt, a4paper]{article} \usepackage{myfontcfg} \begin{document} 测试下中文字体: \song{宋体}\\ \kai{楷体}\\ \stheiti{黑体} \end{document}
编译:
$ xelatex test-xetex.tex
效果图:
Categories: LaTex Linux Tags:   |

编译安装Emacs23

September 16th, 2008 16 Views 0 Comments
Debian源里的Emacs一直还没出现23,也等不及了,于是决定自己cvs下来编译安装一把。 首先装好必要的库和cvs,然后就从cvs库里下载最新源码:
cvs -z3 -d:pserver:anonymous@cvs.savannah.gnu.org:/sources/emacs co emacs
编译安装:
$ ./configure --enable-font-backend --with-x-toolkit --with-xft --with-freetype
在configure时候可能会要求装一些依赖包,主要图形相关的,象libtiff,libxpm之类
$ make bootstrap $ make info $ sudo make install
安装完成后启动emacs23发现之前的模块都加载不了,因为机器上的emacs22还存在没有卸载,都是通过debian源安装的,默认都在/usr下面,而编译emacs23默认的prefix是在/usr/local下,所以为了让两者共存好了,我只好下载的color-theme.el, auctex.el, muse.el的对应源码,重新编译到/usr/local下才使得emacs23正常工作了,先体验下,等一切OK了,再将emacs22给删掉. 配置: 早听说emacs23设置字体很方便,可以给中英文分别设置字体,于是参考了下别人的改写了.emacs:
;; chinese environment setting (UTF-8), font style ;; emacs 23.0.60 (setq current-language-environment "UTF-8") (setq local-coding-system 'utf-8) (set-keyboard-coding-system 'utf-8) (set-terminal-coding-system 'utf-8) (set-selection-coding-system 'utf-8) (prefer-coding-system 'utf-8) (set-fontset-font (frame-parameter nil 'font) 'unicode '("STHeiti" . "unicode-bmp")) (set-fontset-font (frame-parameter nil 'font) 'han '("STHeiti" . "unicode-bmp")) (set-fontset-font (frame-parameter nil 'font) 'symbol '("STHeiti" . "unicode-bmp")) (set-fontset-font (frame-parameter nil 'font) 'cjk-misc '("STHeiti" . "unicode-bmp")) (set-fontset-font (frame-parameter nil 'font) 'bopomofo '("STHeiti" . "unicode-bmp"))
STHeiti是仿MacOS的字体,非常喜欢,能出现在emacs23让人感觉赏心悦目. 现在中文的拷贝粘贴也都没有问题了,不会再出现乱码,以后写中文的笔记和blog更加方便了.
Categories: Debian Linux Tags:   |