AJAX. Simple AJAX code to read HTML file and display in div
.
A random blog about random tips on programming and etc.
AJAX. Simple AJAX code to read HTML file and display in div
.
DOM.If you have php5
and apache2
installed and DOM is enabled according to phpinfo, but you get following error when you use domxml_open_file($file)
, I get following error
This is due to domxml_open_file
is DOM XML function. DOM XML is now moved to the PECL repository and no longer shipped with PHP 5. If you need DOM functions, you need to use DOM.
Installing LAMP. If you want to use apt-get
install the LAMP layer,
Or you can use one tasksel
try command:
Configuring MySQL. Set password for MySQL. tasksel
will ask you for root password during installation.
Creating database and user
Configuring Apache. If you get following error when you start apache2
server,
you need to add ServerName localhost
in apache2
configuration file.
Here is my very first Python program that I've ever wrote outside of a classroom. Basically, it display informations of all Digg friends.
One thing I need to figure out is how to handle non-ASCII characters. My code throws exception when it encounter Unicode or non-printable characters in full name.
import urllib import xml.etree.ElementTree as ET # You need to changes following lines uname = 'myusername' appkey = urllib.quote('http://my.web.site/') # --------------------------------------------------------- count = 100 offset = 0 class AppURLopener(urllib.FancyURLopener): version = "My-Application/1.0" urllib._urlopener = AppURLopener() optstr = "&count=" + str(count) + "&offset=" + str(offset) diggurl = 'http://services.digg.com/user/' + uname + \ '/friends' + '?appkey=' + appkey + optstr; diggxml = urllib.urlopen(diggurl).read() et = ET.fromstring(diggxml) nfriend = int(et.attrib["total"]) while True: for e in et: name = e.get("name", "") icon = e.get("icon", "") registered = e.get("registered", "") profileviews = e.get("profileviews", "") # Some of names contains non-ASCII character which # I still having figure out how to handle it # fullname = e.get("fullname", "") fullname = "" mutual = e.get("mutual", "") date = e.get("date", "") print name + "|" + icon + "|" + registered + "|" + \ profileviews + "|" + fullname + "|" + \ mutual + "|" + date offset += count if offset >= nfriend: break optstr = "&count=" + str(count) + "&offset=" + \ str(offset) diggurl = 'http://services.digg.com/user/' + uname + \ '/friends' + '?appkey=' + appkey + optstr; diggxml = urllib.urlopen(diggurl).read() et = ET.fromstring(diggxml)
Basic. Simple example using CGI
module:
Virtual Hosts in Ubuntu. The easiest way to create new virtual host is to create a configuration file in /etc/apache2/sites-enabled
. In this directory, you should see a symbolic link to the default virtual host located on /etc/apache2/sites-available/
if default host is enabled.
Usually, you want to do
cd /etc/apache2/sites-available
sudo vim virtualdomain.conf
sudo vim /etc/hosts
127.0.0.1 localhost virtualdomain
sudo a2ensite virtualdomain.conf
sudo /etc/init.d/apache2 reload
a2ensite
is a script that creates the symlink to /etc/apache2/sites-available/virtualdoain.conf
in /etc/apache2/site-enabled
directory. This allows to allows quickly disable or enable the virtual host without deleting or moving the configuration file.
Example of virtual host using IP and Port Note that if the server is not listen to port 81, you need to put Listen 81
.
ServerName Warning. If you get following warning message:
Make sure to add ServerName theservername
in /etc/apache2/apache2.conf
.
If ServerName
directive is not set, then the default virtual host will respond to all request. Hens, the web site will work but the apache2
will return warning message during /etc/init.d/apache2 restart
.
Tips. If you want your server to respond to with/without www.
prefix, try ServerAlias directive.
Basic, Array, Array of Array, String, Session, Authentication, XML DOM
CGI, Data structures, LWP, XML::Simple, Using CPAN
Virtual Hosts Alias, ServerName