Monday, August 17, 2009

Appending to Your Python Path


Question:

How do you append directories to your Python path?

Answer:

Your path (i.e. the list of directories Python goes through to search for modules and files) is stored in the path attribute of the sys module. Since path is a list, you can use the append method to add new directories to the path.

For instance, to add the directory /home/me/mypy to the path, just do:
    import sys
sys.path.append("/home/me/mypy")


src: Here

Thursday, August 13, 2009

wget with proxy

As a researcher, we often need to crawl the web pages and save a dump in local disk for future use. However, sometimes we use a proxy to connect a specific website for security concerns or performance issue. There are two ways to assign this job, the first method:


  • Create a ~/.wgetrc file: This file can be used as a configuration file for wget command.
    http_proxy=<your http proxy>

    Reference: wget manual

  • Add a environment variable to your ~/.bashrc.
    export http_proxy="...url..."



Either way works well, but how about a proxy through socks proxy?

sorry... I cannot find a solution yet

Monday, August 10, 2009

Set password protection for you web pages


Here is an simple scenario that comes to my mind. I created a website but I would like to protect some sub-directories from viewing by anonymous users. For example, you might created web pages to store all your bookmarks but you don't want to share it to the public but only limit to some close friends. Or, you are a instructor and you would like to share course website only to the students who attend the class. Okay... the solution is simple, you would like to create a password-protect directory through http server.

You will need two files to achieve this goal. First, you need a file, .htaccess to store the user name and authentication type. Secondly, you need a file, .htpasswd, to store the password of the user you created in .htaccess file.

Filename:.htaccess

AuthType Basic
# You can customized your authentication name
AuthName "Chucheng's Research Authentication"
# Where the .htpasswd located
AuthUserFile /home/chucheng/www/Research/.htpasswd
# Assign user name here
Require user chucheng


You can then generate the .htpasswd by typing the following code:
# The same username you used in .htaccess
$ htpasswd -c /home/chucheng/www/Research/.htpasswd chucheng


You can update the .htpasswd by typing the following code:
# The same username you used in .htaccess
$ htpasswd /home/chucheng/www/Research/.htpasswd-users chucheng


You are done! Enjoy your password-protected website :)


VirtuaWin - The Virtual Desktop Manager

Those of you who had ever been Ubuntu must remember the multi-desktop support on GNOME. Unfortunately, neither Windows XP or Vista support this function by default. As an indulgent user of Windows, I soon understand that this function is a great plus to increase my working performance. After googling around, I found this open source project work almost perfect to meet my needs (with very light loading). Try it if you do need a multi-desktops working environment in Windows. Hopefully, Windows 7 can made this function built-in.


Official Site: VirtuaWin Official Site









Copyrights of above pictures belong to the official website

Tuesday, August 4, 2009

Free Python 3.x Tutorial

This article shall be constantly updated to collect useful resource for learning python 3.x .


  1. Dive into Python 3

    I didn't buy this book because while I start this article, it hasn't be published yet, but definitely this is a very very good book. It's much better than the book I bought from amazon, Programming in Python 3 by Mark Summerfield. The book I bought is too difficult to understand, and the only reason I bought it is that it's one of the earliest book published for python 3.x. I'm still waiting for the publication of the Dive into Python 3, and I believe this book is better than the one I owned now.

  2. Official Python v3.1 documentation

    I believe that you can find all the update information from here. Anyway, it's something that you would always check for answers.

Make vim easy to use

These are common VIM setting I use to make vim more easy to use.

The following lines should be inserted to ~/.vimrc

#This can make the comment color become lighter (easy to read)
set bg=dark

#Smartindent is very helpful if you use vim for coding purpose
set smartindent

#4 spaces = 1 tab
set tabstop=4
set shiftwidth=4
set expandtab

#Press F5 to enable spell check
map :setlocal spell! spelllang=en_us

Make the "ls --color" lighter and more readable

In some Linux distribution, the default color skim is quite annoying. The "blue" is too dark of "ls --color" command, and it is almost invisible. Here is one tip to resolve the problem:

open ~/.bashrc and insert the following line:
#This works for BASH shell
export LS_COLORS="no=00:fi=00:di=01;34:ln=00;36:pi=40;33:so=00;35:bd=40;33;00:cd=40;33;00:or=00;05;37;41:mi=00;05;37;41:ex=00;32:*.cmd=00;32:*.exe=00;32:*.com=00;32:*.btm=00;32:*.bat=00;32:*.sh=00;32:*.csh=00;32:*.tar=00;31:*.tgz=00;31:*.arj=00;31:*.taz=00;31:*.lzh=00;31:*.zip=00;31:*.z=00;31:*.Z=00;31:*.gz=00;31:*.bz2=00;31:*.bz=00;31:*.tz=00;31:*.rpm=00;31:*.cpio=00;31:*.jpg=00;35:*.gif=00;35:*.bmp=00;35:*.xbm=00;35:*.xpm=00;35:*.png=00;35:*.tif=00;35:"