Open Chinstrap

May 3, 2008

Setting up Anjuta on Ubuntu

Filed under: Linux, Programming, Ubuntu — t-roy @ 8:22 pm

A couple of weeks ago I tried a new IDE called Anjuta. I usually use Eclipse which is a great IDE but I wanted a lightweight IDE for writing Perl scripts and learning how to use C++. Using Anjuta for writing perl scripts was straightforward but getting it to work for C++ development was more involved.

First of all you need to add in the following plugins that come with Anjuta. Select Settings>Plugins . Now select the following plugins:

  • Terminal
  • Tools (External Programs)

You will probably have to install g++ compiler. The first time I tried to compile a C++ I discovered that it was not installed on my copy of (Gutsy) Ubuntu. To set up the g++ compiler you need to install the build-essential package. Use the following command to this:

$ sudo aptitude install build-essential

I tried using the Synaptic Package Manager and then apt-get to install the build-essential package but the install failed due to some dependency issues. The aptitude program handled the dependency issue. Next I used the Tools plugin to execute an external command to compile my c++ programs. Select Tools>Configure from the menu:

Add User Tool

 

 

 

 

 

 

 

Click Add:

C++ Compiler Tool

 

 

 

 

In the above example I create an external tool that calls g++ to compile the current source file that I am working on in Anjuta. It saves the executable as the filename without any extension. In the configuration I also setup a Shortcut key for the tool (Ctrl + 1). Setting up my own external tools was more effective than using the Automake build plugin that comes with Anjuta. You can call a simple program or develop you own scripts for more complicated processes.

Troy

April 12, 2008

Installing Google App Engine SDK on Linux

Filed under: Linux, Ubuntu, Web Development — t-roy @ 10:24 am

You will need to have python 2.5 installed on your system but most distros of Linux already have python installed (just verify what version it is) . First download the the SDK from here. Save the zip file to your home directory in my case I saved it to:

/home/scottt

Now you can unzip the file in the home directroy:

$ unzip google_appengine.zip

Go to the google_appengine directory:

$ cd google_appengine

To test out the installation you can start the dev server and run the simple guestbook application that comes with the SDK:

$ ./dev_appserver.py demos/guestbook

By default the app server uses port 8080. You can access the guestbook application from your browser at:

http://localhost:8080

If you are using a linux server with multiple developers you may need to specify a different port in order to run your application:

$ ./dev_appserver.py -p 8090 demos/guestbook

This time the application will run on port 8090. I you want to install google_appengine on Windows check out this post on my other blog .

Troy

April 11, 2008

Error Installing Perl Tk on Ubunutu

Filed under: Linux, Perl, Ubuntu — t-roy @ 11:26 pm

I received the following error installing Tk from CPAN:

CPAN reported “Problem gettimeofday()” which seems to indicate that I was missing some include files. I found the following post which recommended installing the libx11-dev packages which could include the required development header files:

http://www.perlmonks.org/index.pl?node_id=673577

I used the Synaptic Package manager to install libx11-dev. I then tried installing Tk again using CPAN:

$ sudo cpan -i Tk

The install progressed much further than it did the first time but it still ended up failing with the following error:

make[1]: *** [ClientWin.o] Error 1k …

I discovered a Ubuntu post related to this error that recommended installing TK using apt-get:

$ sudo apt-get -install TK

But when I went to install the package from the command line there was no package called TK. Finally I did a search for Tk using the Synaptic Package manager. I found a package called perk-tk and installed it.

 

 

 

 

Run the following “Hello World” test program from this TK User Guide:

#!/usr/bin/perl -w

use Tk;

use strict;

my $mw = MainWindow->new;
$mw->Label(-text => ‘Hello, world!’)->pack;
$mw->Button(
-text => ‘Quit’,
-command => sub { exit },
)->pack;
MainLoop;

Troy

April 10, 2008

How to Reset Video Settings using dpkg-reconfigure

Filed under: Linux, Ubuntu — t-roy @ 11:23 pm

Below is a link to a great HowTo article from the ubuntuforms:

http://ubuntuforums.org/showthread.php?t=83973&highlight=resolution

The other day I was try to use two monitors on my Dell Latitude D600 with a KVM switch. Athough the mouse and keyboard worked fine it changed my video settings of my laptop (primary monitor) and the secondary monitor didn’t work at all. However the real problem began when I tried to change the resolution back to its original configuration (1440 x 900) using the Screen and Graphics Application (System>Administration>Screen and Graphics). I could only get a resolution of 1280 x 1024.

I just walked through the following steps in the HowTo (see the HowTo for details):

  1. Backup the configuration file (xorg.conf)
  2. Stop the Xorg service for auto detection to work properly
  3. Perform the X Configuration using dbkg-reconfigure
  4. Start Xorg again

Troy

April 7, 2008

Configuring Eclipse EPIC on Ubuntu

Filed under: Apache, Linux, Perl, Ubuntu, Web Development — t-roy @ 7:14 pm

E-P-I-C is a good Perl plugin for Eclipse (Version: 3.3.2 Build id: M20080221-1800) . You can use EPIC to develop perl scripts and Perl CGI (Common Gateway Interface) scripts. To install the plugin you can use the update site located here:

http://e-p-i-c.sf.net/updates

Creating a Perl project is very straight forward: File>New>Perl Project

New Perl Project

 

 

 

I will focus on configuring a CGI script since the regular Perl scripts are fairly straight forward . First we need to create our script by right-clicking on the project folder and selecting New>Perl File:

New Perl File

 

 

 

Name the file test.cgi and copy and paste the following simple CGI script:

#! /usr/bin/perl

print “Content-type: text/plain \n\n”;
print “Hello World!\n”;
print “Script Name: $ENV{SCRIPT_NAME}”;

Save the file (CTRL-s) and now we are ready to set up the Perl CGI Configuration. But before we do that it is important to record the full path of the Perl Eclipse project and remember the name of the script you want to run. Eclipse usually creates a workspace directory in your home directory unless you specify otherwise. In my case my workspace is located in:

/home/scottt/workspace

Therefore my Perl project is located in:

/home/scottt/workspace/perlwebscripts/

And the path to my CGI script is:

/home/scottt/workspace/perlwebscripts/test.cgi

Now that we have this information we can configure our CGI script. Right-click on the project folder or any file in the project and select Run As>Open Run Dialog…. :

Perl CGI Configuration

 

 

 

 

In the Main tab you need to select the project folder name in my case it would be perlwebscripts. The Web Server tab (shown above) contains the following information:

  • HTML Root Directory: /home/scottt/workspace/perlwebscripts
  • HTML Startup File: /home/scottt/workspace/perlwebscripts/test.cgi
  • CGI Root Directory: /home/scottt/workspace/perlwebscripts

All paths are related to your Eclipse CGI project. The final thing to configure is the browser tab which is where the result of the CGI Script is displayed. I used the Firefox adapter. I was not able to get the Internal Perl Browser to work. The Firefox browser works fine but it is a bit of a pain to Alt-Tab between Eclipse and Firefox while you are developing. Hit apply once the configuration is finished and then you can click Run As. Here is a screenshot of the test.cgi script :

CGI Test Script

 

 

 

 

EPIC also provides a good user guide which you can download from here.

Troy

April 5, 2008

Installing Eclipse IDE on Ubuntu

Filed under: Linux, Ubuntu — t-roy @ 9:39 pm

98% of the time when you try to install something on Ubuntu it works very well either by using the Add/Remove Application (has a similar look and feel to the Windows Add/Remove control) or the Synaptic Package Manager.  But when I tried to install the Ubuntu version of Eclipse it didn’t go to well.

However, the Ubuntu documentation provides a good walk through on how to install Eclipse:

https://help.ubuntu.com/community/EclipseIDE

I ended up installing Eclipse  manually be referring to section 5 of the documentation (User Installation).

Troy

April 3, 2008

Using the split function with a Scalar Variable

Filed under: Linux, Perl — t-roy @ 11:27 pm

The split function is very useful for parsing or “splitting” a string into a list of strings based on a regular expression (delimiter). For example you could have a string like this:

“apple, orange, pear”

To parse this list with the split function you would do this:

print split /,/ , “apple, orange, pear”;

This will print a list with 3 elements. If you assign the result of the split function to a scalar you will simply get the number of elements or the count of items in the list. Usually you assign the result of the split function to an array:

@mylist = split /,/, “apple, orange, pear”;

Once you do this you could then assign it to a scalar like this:

$fruit = $mylist[0];

This would assign the value of apple to the $fruit scalar. However, I find that I use the split function to parse one value from a string. For example the url from a web page document:

<a href=”http://mysite.campfirenow.com/”>redirected</a>

In this case I want to parse out the http://mysite.camfirenow.com value using the split function and assign it to a scalar all in one line of code. To accomplish this you can write the code like this:

$address = (split /”/, “<a href=”http://mysite.campfirenow.com/”>redirected</a>”)[1];

In this example it is important to use the second element of the list. The first element ([0]) is undefined or empty. The second element ([1]) contains the url value.

Troy

Making a POST with HTTP::Lite

Filed under: Linux, Perl — t-roy @ 7:45 am

HTTP::Lite is a Perl module that, and as the name implies, it is a lightweight implementation for HTTP support. I wanted to write a program to automate a GET or POST to a website. For example you may want to have a script that runs and logs onto a site with your username and password and then grabs some information like stock or weather data. This data could then be used in a report or loaded into a database.

To try this out you can use any website that allows you to fill out a form. I used my account at www.campfirenow.com . Campfirenow is a web service which provides online chat. You can sign up for a free user account if you want to try it out but any website with a form will work for this example. Make sure that HTTP::Lite is installed on your system:

perl -MHTTP::Lite -e 1

If this does not return an error then the module is installed otherwise you can view this post if you do not know how to install it . Before we dive into the code here is a quick check list for the program

  • Import the HTTP::Lite module
  • Create a hash for the input values in the form (its a good idea to use a simple form)
  • POST the form values to the webpage
  • Display the response from the web site (Display the web page)

# Import the module
use HTTP::Lite;

# Create a hash for the form
# Input: email_address
# Input: password

%login = (
“email_address” => “myemail\@domain.com”,
“password” => “mypassword”
);

$http = new HTTP::Lite;

# Create the POST for the form

$http->prepare_post(\%login);

$req = $http->request(“http://myaccount.campfirenow.com/login”)
or die “Error retrieving URL: $!”;
print “req: $req\n”;

# Display the web page (response)

print $http->body() , “\n”;

Unfortunatley the output from this example is not too exciting. Once the user logs in they are redirected to http://myaccount.campfirenow.com. So the HTML that is displayed is for the redirect. Secondly in order to make additional request to the web site a session_id cookie must be passed for all future requests. In my next post I will discuss how to get and set a cookie from the header using the HTTP::Lite module.

This process is more involved. First I will have to login to the site and then retrieve the session cookie from the response header. When I make another request I will have to set the cookie in the request header or the request will fail (it results in a redirect or a 302 STATUS) . This will allow me to extract data from other web pages on the campfirenow web site.

Troy

Check for Existing CPAN Modules

Filed under: Linux, Perl — t-roy @ 1:48 am

Before installing a CPAN Module it is important to check your system to see if it already exists. In my case I wanted to install the Syntax::Highlight::HTML module . First I run the following command to see if it exists on my system:

$ perl -MSyntax::Highlight::HTML -e 1

If I do not receive an error then the module is already installed. If I receive an error that looks something like this:

Can’t locate Syntax/Highlight/HTML.pm in @INC ….

This could mean that the module is not installed or the module is not in the @INC path.

Check for Existing CPAN Modules

To install the module type:

$ sudo cpan -i Syntax::Highlight::HTML

Install Module with Using cpan

Now the module is installed and ready to use. For more information about installing perl modules type:

$ perldoc perlmodinstall

or try this website

http://theoryx5.uwinnipeg.ca/CPAN/perl/pod/perlmodinstall.html

Troy

March 26, 2008

Installing perldoc on Ubuntu from the Command Line

Filed under: Linux, Perl, Ubuntu — t-roy @ 10:29 pm

perldoc is not installed in Unbuntu 7.10 or at least it is not completely installed.  When I typed:

$ perldoc

I recieved the following message:

You need to install the perl-doc package to run this program.

However, when I type whereis perldoc the system does return the path of the perldoc program.  To install the perldoc package from the command line type:

$ sudo apt-get install perl-doc

perldoc install

Now perldoc should work.

Troy

Next Page »

Blog at WordPress.com.