Wednesday, February 4, 2009

Postgresql Spatial Database (GIS) using PostGIS

Postgresql is a open source database that has an add-on module named PostGIS.
PostGis adds support for geographic objects. It allows you to spatial enable your databases.
With the onset of websites like Google maps, having the ability to map locations, map routes, etc, is becoming common place.
With PostGis, I am able to quickly and easily determine distances between 2 locations. I can retrieve longitude and latitude values.

Installing PostGIS

I am using Fedora 8, so I needed to install PostGis from source.

Install from Source Method
1) download, configure, make proj (version 4.6.1)
notes: yum installs files to /usr/share/pgsql/contrib/lwpostgis.sql, postgis_comments.sql, spatial_ref_sys.sql,
from source files get installed to /usr/share/lwpostgis.sql, lwpostgis_upgrade.sql, spatial_ref_sys.sql

2) After compiling proj from source,
a) edit /etc/ld.so.conf
add /usr/local/lib
b) ldconfig
c) recompile PostGis ( if previously installed)

3) Compiling PostGis from source,
a) just run ./configure (without options)
b) then: make
c) make install
4) createlang plpgsql [yourdatabase]
5) psql -d [yourdatabase] -f lwpostgis.sql
6) psql -d [yourdatabase] -f spatial_ref_sys.sql
PostGis is found at http://postgis.refractions.net

Amazon Flexible Payments Service Part 3, Co-branded Flow

In a typical website, you want your customer to have a payment link that starts the process of them paying for services/products that your site has provided to them via Amazon. This typical process end to end is called Co-Branded UI process in Amazon's FPS documentation.
There are 3 roles in the process: Sender, Caller, and Recipient. The sender is the entity sending money. The Caller is the entity calling the Amazon FPS Api. The recipient is the entity who will receives the payment. Amazon uses tokens to provide secure handle to payment instructions.
In this process 3 tokens are used a Caller token, Recipient token, and Sender token. Your web application will need to create a Caller Token, and Recipient Token.
In the Co-Branded UI process , once you customer chooses a product/service and payment amount, they get redirected to Amazon's FPS website where they log in using their Amazon account, select their payment method. It is here in this part of the process on the Amazon site where the Sender token is created. After confirming their payment method, and amount on the Amazon site, the user gets redirect back to you site. When they are redirected back to your site, Amazon passes back to your site the Sender token. Your site will need to acquire this sender token information, and then your site will need to formally request/submit a payment authorization to Amazon FPS Webservice.
Amazon can then notify you when payment was successful either via a scheduled job that you create that queries Amazon FPS, or via Instant Payment Notification which requires you to setup a Web Service that Amazon calls when payment is successful. One of the undocumented Payment Transaction Statuses that I found is "Initiated". In their WSDL file they only define: "Success", "Failure". This can cause issues if you are not expecting to receive this status of "Initiated", and are only expecting to the 2 values of "Success" or "Failure".
The best way to get comfortable with Amazon FPS in my humble opinion is to review and work thru the examples and sample applications.

Amazon Flexible Payments Service Part 2, Setup

In order to use Amazon FPS, you will need to create an aws developer account (Amazon Web Services Account) and sign up for Amazon FPS sandbox account.
Follow the steps in the Amazon FPS Getting Started Guide, http://developer.amazonwebservices.com/connect/entry.jspa?externalID=913&categoryID=125
After completing these steps, you should setup you local development environment, and work thru some of sample applications.
I ended up working thru the Java sample applications and rewriting them in C# to get a solid understanding of Amazon FPS.
It is important know what your requirements for you payment application are ahead of time, so that you can pick which features of Amazon FPS you want use. Do you want to retrieve your payment notification from Amazon in a scheduled job or Do you want know instantly when a payment transaction is completed?
If you want to know instantly when a payment transaction is completed and don't want have to deal with creating a scheduled job, then use Amazon's IPN feature (Instant Payment Notification). IPN requires that you setup a Web Service on your web server that Amazon FPS can access to notify you of payments. If you don't want to setup a Web Service for IPN, you will need to go the scheduled job route.

Wednesday, January 7, 2009

Small addition to John Resig's Bringing the Browser to the Server

After reading John Resig's article: http://ejohn.org/projects/bringing-the-browser-to-the-server which was written over a year ago. I wanted to try out some of things he demonstrated.
By combining Mozilla's Rhino project with a few javascript files, John was able to do
a number of useful things like automated javascript testing and web screen scraping.
He also outlined some pseudo code for creating a web app environment.
The one thing he ran out of time was integrating an html parser into this setup.
At his suggestion I have integrated the nekohtml html parser into this setup.
In order to use this setup you should follow these steps:

1. Get jquery source code . Via SVN at http://jqueryjs.googlecode.com/svn/trunk/. Important get REVISION 2302
2. Get Rhino ( source code optional), site: http://www.mozilla.org/rhino/
3. Get Nekohtml source code, site: http://nekohtml.sourceforge.net/
4. Edit /jquery/jquery/build/runtest/env.js (starting at line 135)
window.DOMDocument = function(file){
this._file = file;
//OLD
//this._dom = Packages.javax.xml.parsers.
// DocumentBuilderFactory.newInstance()
// .newDocumentBuilder().parse(file);

//NEW
var parser = new Packages.org.cyberneko.html.parsers.DOMParser();
var source = new Packages.org.apache.xerces.xni.parser.XMLInputSource(null,null,null,file,"UTF8");
parser.parse(source);
this._dom = parser.getDocument();




if ( !obj_nodes.containsKey( this._dom ) )
obj_nodes.put( this._dom, this );
};

5. You can run your javascript file via the Rhino Debugger App
command line:
java -cp build/nekohtml.jar;build/nekohtmlXni.jar;build/xml-apis.jar;build/xercesImpl.jar;build/xercesSamples.jar;build/js.jar org.mozilla.javascript.tools.debugger.Main filename.js

Note: Some further updates to env.js will be necessary to get it to run the html parser outside the Rhino Debugger App.

Wednesday, December 31, 2008

New and Improved www.endurotracker.com

After 3 months of work, there is a new and improved www.EnduroTracker.com site available.
This site is targeted towards the triathlete or endurance athlete who want to plan and track their training sessions from any available internet enabled device (PC, iphone, blackberry, etc).
If you have friends who do endurance sports like Triathlons, bike races, road races, or swim races refer them to www.endurotracker.com. ( a triathlon training log site )
On a technical note, www.EnduroTracker.com is now using substantial more hardware, and is now using several new redundancy strategies to handle large loads, maximize performance, and deal with hardware disaster scenarios. It uses redundant web servers, and redundant database servers.

Friday, December 19, 2008

Host Names in Linux

Configure the Hostname

On the shoulders of giants, this an excerpt from very detailed post on postfix (smtp software) at

http://souptonuts.sourceforge.net/postfix_tutorial.html

The computer that these examples are taken from is "squeezel.squeezel.com", and it exists on IP address 192.168.1.81. The short name is just squeezel. Another computer, on IP address "192.168.1.155" is "tape.squeezel.com".

     /etc/hosts

# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 localhost.localdomain localhost
192.168.1.81 squeezel.squeezel.com squeezel
192.168.1.155 tape.squeezel.com tape

You may also want to edit "/etc/sysconfig/network" and add or check the following.

    HOSTNAME=squeezel.squeezel.com

Finally, to put all changes into effect now, run the following command with root privileges.

   $ hostname squeezel.squeezel.com

Some of the settings in the postfix "main.cf" file depend upon the hostname.

Monday, December 1, 2008

Amazon Flexible Payments Service (FPS) Part I, An Overview

Amazon Flexible Payments Service (FPS) is a set of web services that allow developers create applications to move money from one entity to another. Payment can be in the form of credit cards, bank account , or Amazon Payments balance.
Requests can be made either via SOAP or REST. In my case I had to use REST because Mono (.Net on Linux) has not implemented WSE 2 or WSE 3.
Another important feature to be aware of is Instant Payment Notification (IPN). This frees up a developer from having to implement a scheduled job that queries Amazon FPS for completion of payments. Because IPN will push (publish) a response to your listening website/webservice for you.

References:
Getting Started Guide: http://docs.amazonwebservices.com/AmazonFPS/2007-01-08/FPSGettingStartedGuide/
Developers Guide: http://docs.amazonwebservices.com/AmazonFPS/2007-01-08/FPSDeveloperGuide/