Saturday, May 31, 2008

 

ebook libraries

books24x7
ebrary
myilibrary
netlibrary
safari books online


Saturday, April 05, 2008

 

configure SSL for apache

We assume Apache2 webserver is already installed on running on your computer, along with PHP.
To add ssl support for Apache2:
1. install openssl package "sudo apt-get install openssl"
2. generate your ssl certificate, run "sudo openssl req $@ -new -x509 -days 365 -nodes -out /etc/apache2/apache.pem -keyout /etc/apache2/apache.pem"
3. secure your .pem file: "sudo chmod 600 /etc/apache2/apache.pem"
4. load apache ssl module:
"sudo ln -s /etc/apache2/modules-available/ssl.* /etc/apache2/modules-enabled/"
5. make a copy of apache configuration file: "sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/ssl"
6. make a symlink to automatically load this configuration file: "sudo ln -s /etc/apache2/sites-available/ssl /etc/apache2/sites-enabled/"
7. edit /etc/apache2/sites-available/ssl and make it start with:
NameVirtualHost *:443
<VirtualHost *:443>
SSLEngine On
SSLCertificateFile /etc/apache2/apache.pem
...
</VirtualHost>
8. make sure Apache2 is listening to port 443, open /etc/apache2/ports.conf and add "Listen 443"
9. restart Apache "sudo /etc/init.d/apache2 restart"
That's it, try out https://servername, it should work.

[Subodomains]
If you've configured Apache to use subdomains, you need to configure explicitly subdomains for port 443 too. Copy your existing virtual host subdomain configuration (with DocumentRoot section) and wrap it into a <VirtualHost *:443> node. Make sure you've added "SSLEngine On" and "SSLCertificateFile [location]" too for each subdomain configuration in your http.conf file, otherwise it won't work. If you intend to use the site on both https and http, you need to configure it for both cases.

Wednesday, April 02, 2008

 

.htaccess apache configuration

Something really weird happened. I added a .htaccess file to a directory, and each time I tried to access this folder:
- if directly, I got a "500 Internal Server Error"
- indirectly, browsing the hierrarchy through the webbrowser up to this folder, this folder had disappeared !!!

1) stay calm, you're not crazy
2) it means that you may have an error in your .htaccess file
(for instance you're calling a module that's not loaded !)
3) if you have access to apache configuration file (httpd.conf), then write your configurations there.
3.1) first this will speed your server (it won't have to load .htaccess on each page call)
3.2) when you restart apache, you will get an error message that will help you find out the pbm

In my case, I was calling RewriteEngine, when in fact mod_rewrite had not been enabled.
To enable mod_rewrite either do the following:
1) in debian, make a symbolic link to the rewrite module:
sudo ln -s /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled/
2) OR directly add the module location ("locate mod_rewrite.so") in httpd.conf:
LoadModule rewrite_module /usr/lib/apache/modules/mod_rewrite.so
#AddModule mod_rewrite.c
3) In any case, restart apache "sudo /etc/init.d/apache2 restart"
Now it should work!

Sunday, March 16, 2008

 

Ubuntu network / lightweight install

If you need to make a network install of ubuntu:
https://help.ubuntu.com/community/Installation/Netboot

Saturday, March 15, 2008

 

system clock in debian linux (clock delay)

I had a clock delay on my debian system (+1 hour). It was ok since I ran ntpd, but when I had no internet connection, I still got this time gap. The problem is that whenever I tried to change the clock (through ntpdate or rdate), any changes were lost after reboot. My clock delay came back.

Pretty annoying, especially since I wanted to replace ntpdate package (synchronizing clock at every startup !) with rdate package (clock synchronization on demand through "sudo rdate -n pool.ntp.org").

I had correctly set the timezone ("sudo dpkg-reconfigure tzdata")

At startup, I also had this annoying msg during boot process:
Setting system clock: ... dev/rtc()... hwclock.sh
* Unable to set system clock to ...

If this happens to you (clock changes lost after reboot + error msg at startup):
1: in both /etc/init.d/hwclock.sh AND /etc/init.d/hwclockfirst.sh, replace "HWCLOCKPARS=" with "HWCLOCKPARS=--directisa"
2: save your changes
3: update your clock (with "sudo date" or better, with rdate package: "sudo rdate -n pool.ntp.org")
4: reboot !
That's it. Your clock should have the correct time (try "date" when logged in) and the error msg during boot time should be gone.
It worked for me.

src: http://ubuntuforums.org/showthread.php?t=594031
http://groups.google.nl/group/linux.debian.user/browse_thread/thread/649e6847e08de6cf

Thursday, March 13, 2008

 

python and unicode

Python is pretty good with unicode. But you need to clearly understand how it works fisrt !

[Two worlds:]
The world is divided in two: 'unicode' and other encodings ('ascii', 'iso-8859-1', 'utf-8', 'utf-16'...)
Unicode and these encodings are completely different.

[Your default encoding:]
- To see your current default encoding, "import sys" then "sys.getdefaultencoding()" from python shell
- you cannot change it at run time, you need to change it with a configuration script.
If you want to set 'utf-8' as default encoding, create a new file called 'sitecustomize.py' and save it under '/usr/lib/python2.5/site-packages/ '. The file name is pretty important so that it is automatically launched at runtime.
In the file, write: "import sys" and "sys.setdefaultencoding('utf-8')"
Restart Python
now "sys.getdefaultencoding" should return "utf-8"

[Encoding of script files:]
- Each script file can have its own encoding.
To do so, make appear "coding: XXX" in either the first or second line of your script file, in a single line comment
ex: # this file encoding: utf-8
By specifying this, Python will automatically treats characters from the file with a utf-8 encoding

more explanation:
- let say your default encoding is 'ascii'
- your script file is in UTF-8 but you do not specify the encoding at the top of the file
- in your script file, you have the following string sequence: "my name is rémy"
If you import this script and run the function with the previous string sequence, you will end up with a UnicodeDecodeError exception

- now if you specify the encoding in the first two lines (ex: # encoding: utf8), then the exception disapeared and you have no more error.

[Create unicode strings:]
You have three ways to create unicode strings:
- prepending "u" to your string
ex: u"hello", u"my name is rémy"
- using unicode() function
This function takes an optional argument which is the encoding of the input text, if different from current default encoding
ex: unicode("hello"), unicode("my name is rémy"), unicode('\xff\xfe\xe9\x00', 'utf-16') # prints "é"
- using the decode() method of any string
ex: "hello".decode(), "my name is rémy".decode(), ''\xff\xfe\xe9\x00".decode('utf-16')

[Unicode usage:]
Once you have a unicode string, you can do everything you do with other strings, including string comparaison with non-unicode string ! everything is transparent, python handles unicode very well.
ex (my default encoding is utf-8 so "à" is an allowed char):
>> a = "à" # utf-8 string
>> b = a.decode() # unicode string
>> a == b
True
>> a
'\xc3\xa0' # correspond to the utf-8 code for "à"
>> b
u'\xe0' # correspond to the unicode code for "à"

Python compared the two strings, independently from their respective encoding, which is the behavior we expected

[From unicode string to encoded string:]
At some point, you may need to convert back from unicode to a specific encoding (to dump content into a file, a stream...).
Simply use the .encode() method available on all string, and specify the encoding you want, otherwise default encoding is used.
>> a = "à" # utf8 encoding
>> b = a.decode() #unicode
>> c = b.encode() # back to utf8
>> d = b.encode('utf-16')
>> c
'\xc3\xa0' # correspond to the utf-8 code for "à", similar output for ">> a"
>> d
'\xff\xfe\xe0\x00" # utf-16 code for "à"

equality check:
>> a == b
True # OK, as said before, python transparently convert to unicode so equality is correct
>> a == c
True # OK, same character in same encoding
>> c == d
False #Interesting !!, the encoding is different, c is in utf-8, d is in utf-16, equality fails ! None of them is unicode, so python does not make any transformation to check for equality

[To remember:]
str.decode([encoding]) = goes from specified/default encoding to unicode
str.encode([encoding]) = goes from unicode to specified/default encoding

[sources:]
src: http://www.pyzine.com/Issue008/Section_Articles/article_Encodings.html
book diveintopython, section 9.4 (freely available at www.diveintopython.org)
http://www.reportlab.com/i18n/python_unicode_tutorial.html
http://www.python.org/dev/peps/pep-0263/

Monday, March 10, 2008

 

from PHP to Python

I recommend to read 'diveintopython', freely available at www.diveintopython.org

Great news: in python, 'x and y or z' does not return True or False, but the last element that permited to evaluate (or not) the expression.
ex: "0 and 'b' or 'c'" returns 'c'
With this particularity, we have an equivalent of "bool ? a : b" that exists in PHP but not in Python ! (provided 'a' does not evaluate to False when 'bool' is true...)
simply write: bool and a or b
if 'a' can evaluates to false, a quick workaround is to write it this way:
"(bool and [a] or [b])[0]"
(taken from diveintopython, section 4.6)

This page is powered by Blogger. Isn't yours?