Sep
6
Install Python on Linux Ubuntu
September 6, 2008 | 3 Comments
In this article, I will explain how to install and run Python as a web service anywhere on Linux Ubuntu as localhost.
1. you should have have the latest version of Python installed, to do so, type the following line of code in the terminal:
sudo apt-get install python
2. Now to run it as a web service with Apache, you need Apache mod_python, to install it, type the following line of command in the terminal:
sudo apt-get install libapache2-mod-python
3. Now if you use the default localhost directory - /var/www/, then following the instruction a, if you have previously configured Apache and run localhost at the place other than the default /var/www/, follow the instruction b:
a.
execute the following command in the terminal:
cd /etc/apache2/sites-available/
and execute the following command:
sudo gedit default
now with the file opened, find the code below:
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride AuthConfig
Order allow,deny
allow from all
# Uncomment this directive is you want to see apache2's
# default start page (in /apache2-default) when you go to /
#RedirectMatch ^/$ /apache2-default/
</Directory>
change it to:
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride AuthConfig
Order allow,deny
allow from all
AddHandler mod_python .py
PythonHandler mod_python.publisher
PythonDebug On
# Uncomment this directive is you want to see apache2's
# default start page (in /apache2-default) when you go to /
#RedirectMatch ^/$ /apache2-default/
</Directory>
run in terminal:
sudo gedit /var/www/test.py
in the opened file, type:
def index(req): return "Test successful";
save the file, and it should work
visit http://localhost/test.py and it should say “Test successful” in plain text
b.
execute the following command in the terminal:
sudo gedit /etc/apache2/apache2.conf
assume that you are running Python code from the directory /home/usr/Documents/Host/lab/python/
add the following code to the bottom of the file:
Alias /python/ /home/usr/Documents/Host/lab/python/ <Location /python/> AddHandler mod_python .py PythonHandler mod_python.publisher PythonDebug On </Location>
run in terminal:
sudo gedit /home/usr/Documents/Host/lab/python/test.py
in the opened file, type:
def index(req): return "Test successful";
save the file, and it should work
visit http://localhost/test.py and it should say “Test successful” in plain text
Sep
6
Perl Regex - Find Repeated Words
September 6, 2008 | Leave a Comment
You can use this recipe to find words that appear more than one time in sequence, such as the the.
#!/usr/bin/perl -w
use strict;
my $mystr = $ARGV[0] || die "You must supply a parameter!\n";
if ( $mystr =~ /\b(\w+)\s\1\b/ )
{
print "I think I'm seeing double.\n";
}
else
{
print "Looks okay to me.\n";
}
Sep
6
Joomla PDF Display Problem in IE7 Fix
September 6, 2008 | Leave a Comment
If you have been using Joomla! 1.5 and tested it on IE7, you might find the PDF problem where any PDF file fails to display correctly in IE7. The usual symptom is that the pop-up window is empty.
There are 2 steps:
1. Creata a new file called browser_detection.php and upload it to your Joomla! site.
2. Edit icon.php in 2 places and upload it to your Joomla! site.
STEP 1
Create a php file called browser_detection.php. You can do this in any text editor or Dreamweaver. Copy, paste and save the following in to your new file:
[sourcecode langauge="php"]
/*
Script Name: Simple 'if' PHP Browser detection
Author: Harald Hope, Website: http://TechPatterns.com/
Script Source URI: http://TechPatterns.com/downloads/php_browser_detection.php
Version 2.0.2
Copyright (C) 29 June 2007
Modified 22 April 2008 by Jon Czerwinski
Added IE 7 version detection
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
Get the full text of the GPL here: http://www.gnu.org/licenses/gpl.txt
Coding conventions:
http://cvs.sourceforge.net/viewcvs.py/phpbb/phpBB2/docs/codingstandards.htm?rev=1.3
*/
/*
the order is important, because opera must be tested first, and ie4 tested for before ie general
same for konqueror, then safari, then gecko, since safari navigator user agent id's with 'gecko' in string.
note that $dom_browser is set for all modern dom browsers, this gives you a default to use, unfortunately we
haven't figured out a way to do this with actual method testing, which would be much better and reliable.
Please note: you have to call the function in order to get access to the variables, you call it by this:
browser_detection('browser');
then put you code that you want to use the variables with after that.
*/
function browser_detection( $which_test ) {
// initialize the variables
$browser = '';
$dom_browser = '';
// set to lower case to avoid errors, check to see if http_user_agent is set
$navigator_user_agent = ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) ? strtolower( $_SERVER['HTTP_USER_AGENT'] ) : '';
// run through the main browser possibilities, assign them to the main $browser variable
if (stristr($navigator_user_agent, "opera"))
{
$browser = 'opera';
$dom_browser = true;
}
/*
Test for IE 7 added
April 22, 2008
Jon Czerwinski
*/
elseif (stristr($navigator_user_agent, "msie 7"))
{
$browser = 'msie7';
$dom_browser = false;
}
elseif (stristr($navigator_user_agent, "msie 4"))
{
$browser = 'msie4';
$dom_browser = false;
}
elseif (stristr($navigator_user_agent, "msie"))
{
$browser = 'msie';
$dom_browser = true;
}
elseif ((stristr($navigator_user_agent, "konqueror")) || (stristr($navigator_user_agent, "safari")))
{
$browser = 'safari';
$dom_browser = true;
}
elseif (stristr($navigator_user_agent, "gecko"))
{
$browser = 'mozilla';
$dom_browser = true;
}
elseif (stristr($navigator_user_agent, "mozilla/4"))
{
$browser = 'ns4';
$dom_browser = false;
}
else
{
$dom_browser = false;
$browser = false;
}
// return the test result you want
if ( $which_test == 'browser' )
{
return $browser;
}
elseif ( $which_test == 'dom' )
{
return $dom_browser;
// note: $dom_browser is a boolean value, true/false, so you can just test if
// it's true or not.
}
}
/*
you would call it like this:
$user_browser = browser_detection('browser');
if ( $user_browser == 'opera' )
{
do something;
}
or like this:
if ( browser_detection('dom') )
{
execute the code for dom browsers
}
else
{
execute the code for non DOM browsers
}
and so on.......
*/
?>[/sourcecode]
Upload browser_detection.php to the folder libraries/joomla/utilities/ on your site.
STEP 2
Find the file icon.php in the folder components/com_content/helpers/. Note: Make a copy of this file so you can restore it if needed.
Under the
require_once("libraries/joomla/utilities/browser_detection.php");
Replace this line of code on line 58
[sourcecode lanuage="php"]$attribs['onclick'] = “window.open(this.href,’win2′,’”.$status.”‘); return false;”;[/sourcecode]
with the following code:
$user_browser = browser_detection('browser');
if ($user_browser == 'msie7') {
$attribs['target'] = '_blank';
} else {
$attribs['onclick'] =
"window.open(this.href,'win2','".$status."'); return
false;";
}
Save and upload the file to components/com_content/helpers/.
Note: Your browser’s cache may need to be cleaned before you can see the PDF working.
Sep
6
Enter Special Characters in Vim
September 6, 2008 | Leave a Comment
Some characters are not on the keyboard—for example, the copyright character (©). To type these letters in Vim, you use digraphs, where two characters represent one.
To enter a ©, for example, you hold CTRL key and press K, and then type Co.
To find out the entire list of digraphs that are available, use the following command:
:digraphs
or the shorter version of the command:
:dig
You will see a list of command like the following screen shot:

For instance, in the list, A' Á 193 means that if you want to type Á symbol, you
1. hold CTRL key and press K
2. and then type A'
3. you will get Á
4. 193 is just the character number for your reference.
Hope this helps! :)