Python script in the browser

This site shows you how to setup apache2 so you can run python script in the browser (lampp). He shows a method on how to use an html form to fetch date from python using POST.

Running a script directly without POST and using urllib2 to fetch a website:
in the browser type:

import cgi
import cgitb
import urllib2

# Begin HTML generation, must be here
print "Content-Type: text/html; charset=UTF-8" # Print headers
print "" # Signal end of headers

# HTML is pushed to the page with print
# To save time you can use ''' to open and close a print
# statement for block printing

response = urllib2.urlopen('')

print "hello world"

run python script html apache2 server
run python script html
urllib2 execute html

Multiple Sites on One Server – Virtual Hosts

This works for Ubuntu

Go to your site directory and make two folder and
$ mkdir /var/www/ /var/www/

Modify your host file
$ sudo nano /etc/hosts

Add the two lines of code into that file

Make configuration changes to apache by creating 2 files in the /etc/apache2/sites-available directory
$ sudo touch /etc/apache2/sites-available/ /etc/apache2/sites-available/

Put this code in those new created file. file:
<VirtualHost *:80>
DocumentRoot /var/www/
</VirtualHost> file:
<VirtualHost *:80>
DocumentRoot /var/www/

Final configuration commands
$ sudo a2ensite
$ sudo a2ensite
$ sudo service apache2 reload

Now if you put either or in your browser you’ll go to those sites. Now if you own these domain names put you internet IP address with the domain hosting and it will automatically navigate to the specified site location, making accessibility public.

if error:
apache2: Could not reliably determine the server’s fully qualified domain name, using for ServerName

$ sudo nano /etc/apache2/httpd.conf

add the line below:
ServerName localhost


AH00558: apache2: Could not reliably determine the server’s fully qualified domain name, using Set the ‘ServerName’ directive globally to suppress this message

Corrupted dpkg status file fix

Today I was trying to install a program using apt-get install however I kept getting this error

Do you want to continue [Y/n]? Y
Selecting previously unselected package libxmlrpc-core-c3.
(Reading database … 60%dpkg: unrecoverable fatal error, aborting:
reading files list for package ‘intltool-debian’: Input/output error
E: Sub-process /usr/bin/dpkg returned an error code (2)

after hours of research I found out that the reason for this error was the /var/lib/dpkg/status file was corrupted.

I had three options to fix this which were reinstall ubuntu operating system, edit the status files or find a backup status file. I didn’t want to reinstall my operating system so I tried the other two.

(warning: Before trying to edit any file make sure you make a back up of it)

I tried to edit the status file by looking for the package I was trying to install. However I couldn’t find it and I didn’t know what to delete. Luckly there’s dpkg status backupfiles in your system located at /var/backups. I found one that was created a month ago called dpkg.status.3.gz and extracted it and renamed the file status and put into /var/lib/dpkg directory.

Then I tried to install the program using apt-get install and it worked.

Create executable ubuntu icons for python script

First create you python script

#!/usr/bin/env python3

import sys
from PyQt4 import QtGui, QtCore
class HelloQt(QtGui.QDialog):
    def __init__(self):
        self.setWindowTitle("Hello Qt")
        # Vertical layout
        self.layout = QtGui.QVBoxLayout(self)
        # Create widgets
        self.label = QtGui.QLabel("What's your name?") = QtGui.QLineEdit()
        self.output = QtGui.QLineEdit()
        # Add widgets to the layout
        # Connect with self.sayHello(name) when text is changed
        self.connect(, QtCore.SIGNAL("textChanged(const QString&)"), self.sayHello)
    def sayHello(self, name):
        # Set the output text
        self.output.setText("Hello " + name + "!")
if __name__ == "__main__":
        # Create QApplication
        app = QtGui.QApplication(sys.argv)
        # Create a HelloQt window and show it
        helloqt = HelloQt()
        # Run the mainloop

make sure that your python script has the shebang on the first line.
Make an executable file by running
$ chmod +x

Now create the file /usr/share/applications/runPythonIcon.desktop:

[Desktop Entry]
Name=python gui

make this file also executable by running
$ chmod +x runPythonIcon.desktop



Math is so Useful

If you want to know how the world works? Know math. -My College history teacher

Rarely do I use math in PHP but when it comes to circuit building, business and statistics. Math is my best friend.

Ask anyone, what is their favorite subject and rarely will you ever hear math. You’ll hear stuff like “I hate math, why do I have to learn this stuff”. Yeah math is a pain to learn. My Algebra teacher Ms. Kline told me that math is different from any other subject, you’ll actually need to practice it in order to be good.

I was trying to find out which distributors offered a better price at what quantity.  They had different fixed and variable cost. It’s a 2 simple linear equations.  q is the quantity and p is the total price.

Distributer A Distributer B
Price (q) $2 $3
Shipping $5 $0
Equation 2q+5= p 3q=p

I used wolframalpha to solve the equation.

When I solved the equation I get that q=5 and p =15.  This means that when the quantity is 5 both distributor have the same price but when quantity is less than 5 distributor A has the better price and when quantity is more than 5 distributor B has the better price.