<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Fahodzi</title>
	<atom:link href="http://fahodzi.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://fahodzi.wordpress.com</link>
	<description>...there is freedom in knowledge</description>
	<lastBuildDate>Tue, 06 Sep 2011 19:39:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='fahodzi.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Fahodzi</title>
		<link>http://fahodzi.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://fahodzi.wordpress.com/osd.xml" title="Fahodzi" />
	<atom:link rel='hub' href='http://fahodzi.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Generating Even and Odd PostgreSQL Databases for Replication</title>
		<link>http://fahodzi.wordpress.com/2010/11/11/generating-even-and-odd-postgresql-databases-for-replication/</link>
		<comments>http://fahodzi.wordpress.com/2010/11/11/generating-even-and-odd-postgresql-databases-for-replication/#comments</comments>
		<pubDate>Thu, 11 Nov 2010 16:09:34 +0000</pubDate>
		<dc:creator>James Ekow Abaka Ainooson</dc:creator>
				<category><![CDATA[How To do Stuff]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[bucardo]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[postgre]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[replication]]></category>
		<category><![CDATA[rubyrep]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://fahodzi.wordpress.com/?p=233</guid>
		<description><![CDATA[I was recently faced with a problem of replicating two PostgreSQL databases with bucardo. The replication was to be in a master-master fashion so that the databases could be updated on both ends. Although this task can easily be handled &#8230; <a href="http://fahodzi.wordpress.com/2010/11/11/generating-even-and-odd-postgresql-databases-for-replication/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fahodzi.wordpress.com&amp;blog=3071373&amp;post=233&amp;subd=fahodzi&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I was recently faced with a problem of replicating two PostgreSQL databases with bucardo. The replication was to be in a master-master fashion so that the databases could be updated on both ends. Although this task can easily be handled by bucardo it requires that the two different systems generate completely different sets of primary keys. According to the Bucardo website (http://bucardo.org/wiki/Bucardo/Sequences) there are three ways of achieving this difference. <span id="more-233"></span>Their approaches were:</p>
<blockquote><p>If you are using a <a title="Swap sync (page does not exist)" href="http://bucardo.org/mwp3/index.php?title=Swap_sync&amp;action=edit&amp;redlink=1">swap sync</a>,  the best practice is to *not* replicate sequences, but to make sure  that they are different on both sides, such that an insert on database A  will never conflict with an insert on database B. There are three  general ways to do this:</p>
<ol>
<li> Use interleaving sequences. On database A, define the sequence  as START WITH 1 INCREMENT BY 2. On database B, define the sequence as  START WITH 2 INCREMENT BY 2. Thus, the two sequences will never have the  same value.</li>
<li> Use different ranges. For example, database A would use a  sequence of START WITH 1, while database B uses START WITH 100000000.  This is not foolproof, as A can eventually catch up with B, although you  can define A as MAXVALUE 99999999.</li>
<li> Use a common sequence. This relies on one or both of the databases using a function that makes a call to an external sequence</li>
</ol>
</blockquote>
<p>After reading this I decided to go by the first approach so I wrote a script to alter the sequences.</p>
<p><pre class="brush: php;">

// Add the sequences you dont want affected here. The schema doesn't
// really matter.
$exclude = array(
    'client_code_seq',
    'jv_number_seq',
    'pv_number_seq',
);

for ($i = 1; $i &lt; $argc; $i++)
{
    if(substr($argv[$i], 0, 2) == &quot;--&quot;)
    {
        $parameter = substr($argv[$i], 2, strlen($argv[$i]) - 2);
        $i++;
        $$parameter = $argv[$i];
    }
    else
    {
        $tables[] = $argv[$i];
    }
}

$conn = pg_connect(&quot;host=$host port=5432 dbname=$db user=$user password=$password&quot;);

pg_query($conn,&quot;BEGIN&quot;);
$sequences_result = pg_query($conn, &quot;SELECT * FROM information_schema.sequences&quot;);
$sequences = array();
while($sequence = pg_fetch_assoc($sequences_result))
{
    if(array_search($sequence['sequence_name'], $exclude) !== false)
    {
        echo &quot;Skipping &quot; . $sequence['sequence_schema'] . '.' . $sequence['sequence_name'] . &quot;\n&quot;;
        continue;
    }
    $sequence = $sequence['sequence_schema'] . '.' . $sequence['sequence_name'];
    $value = pg_query($conn, &quot;SELECT last_value from $sequence&quot;);
    $value = pg_fetch_assoc($value);

    pg_query($conn, &quot;ALTER SEQUENCE $sequence INCREMENT BY 2&quot;);

    if($value[&quot;last_value&quot;] % 2 == 0 &amp;&amp; $mode == 'odd')
    {
        pg_query($conn, &quot;ALTER SEQUENCE $sequence RESTART WITH &quot; . ($value['last_value'] + 1));
    }
    elseif(($value[&quot;last_value&quot;] % 2 == 1 || $value[&quot;last_value&quot;] == 1) &amp;&amp; $mode == 'even')
    {
        pg_query($conn, &quot;ALTER SEQUENCE $sequence RESTART WITH &quot; . ($value['last_value'] + 1));
    }
}
pg_query($conn,&quot;COMMIT&quot;);
</pre></p>
<p>This script takes five required parameters. The parameters are not validated so if it is wrongly specified the consequences are unknown. <strong>PLEASE BE CAREFUL! </strong>The parameters are:</p>
<ol>
<li> The hostname</li>
<li>The username</li>
<li>The password</li>
<li>The database name</li>
<li> The mode of the change (even or odd)</li>
</ol>
<p>An example usage could be</p>
<p><code>php update_sequences.php --host db1.accra.srv --user postgres --password somepass --db appcore --mode even</code></p>
<p>Hope that helps. Happy Programming!</p>
<p>&nbsp;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fahodzi.wordpress.com/233/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fahodzi.wordpress.com/233/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/fahodzi.wordpress.com/233/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/fahodzi.wordpress.com/233/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/fahodzi.wordpress.com/233/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/fahodzi.wordpress.com/233/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/fahodzi.wordpress.com/233/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/fahodzi.wordpress.com/233/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/fahodzi.wordpress.com/233/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/fahodzi.wordpress.com/233/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/fahodzi.wordpress.com/233/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/fahodzi.wordpress.com/233/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/fahodzi.wordpress.com/233/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/fahodzi.wordpress.com/233/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fahodzi.wordpress.com&amp;blog=3071373&amp;post=233&amp;subd=fahodzi&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fahodzi.wordpress.com/2010/11/11/generating-even-and-odd-postgresql-databases-for-replication/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/cb2e26312d01604c5cb234903c476ef8?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">simpa</media:title>
		</media:content>
	</item>
		<item>
		<title>Getting FLEX-ible with GEdit (Ant Style)</title>
		<link>http://fahodzi.wordpress.com/2010/08/24/getting-flex-ible-with-gedit-ant-style/</link>
		<comments>http://fahodzi.wordpress.com/2010/08/24/getting-flex-ible-with-gedit-ant-style/#comments</comments>
		<pubDate>Tue, 24 Aug 2010 10:37:58 +0000</pubDate>
		<dc:creator>James Ekow Abaka Ainooson</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[adobe]]></category>
		<category><![CDATA[ant]]></category>
		<category><![CDATA[build]]></category>
		<category><![CDATA[external tools]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[gedit]]></category>
		<category><![CDATA[gnome]]></category>
		<category><![CDATA[mxmlc]]></category>
		<category><![CDATA[ria]]></category>

		<guid isPermaLink="false">http://fahodzi.wordpress.com/?p=206</guid>
		<description><![CDATA[A while ago I had a post on this blog which described a crude way of using Gedit as an editor for Flex code. An interesting comment on this post actually got me thinking in another direction I had previously &#8230; <a href="http://fahodzi.wordpress.com/2010/08/24/getting-flex-ible-with-gedit-ant-style/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fahodzi.wordpress.com&amp;blog=3071373&amp;post=206&amp;subd=fahodzi&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>A while ago I had a <a href="../2008/12/22/getting-flex-ible-with-gedit/">post</a> on this blog which described a crude way of using Gedit as an editor for Flex code. An interesting <a href="http://fahodzi.wordpress.com/2008/12/22/getting-flex-ible-with-gedit/#comment-23">comment</a> on this post actually got me thinking in another direction I had previously not thought about &#8230; using a build system. For those of you lost on the whole build system thing, a build system is simply a software which helps you to build source code in an &#8220;easier&#8221; way. This particular comment actually recommended the use of the ant build system. After a little research and some playing around with Gedit, Ant and Flex I kind of figured out this simple way to build flex projects in Gedit using Ant.<br />
<span id="more-206"></span></p>
<h1>Setting up External Tools</h1>
<p>If you have read my previous post you would realize that it took advantage of the External Tools plugin which comes with GEdit. What makes this one even interesting is the fact that the new approach is going to take an external tools script (the build script) which ships with the GEdit External Tools plugin and modify a few lines here and there to get it to work. The build script is written for the make build system so we are just going to modify it to recognize the ant build system instead.</p>
<p>To get started you need to:</p>
<ol>
<li>Open the External Tools plugin and find the build tool.</li>
<li>Locate and copy the script of the build tool. It should look something similar to this<br />
<pre class="brush: bash;">
#!/bin/sh

EHOME=`echo $HOME | sed &quot;s/#/\#/&quot;`
DIR=$GEDIT_CURRENT_DOCUMENT_DIR
while test &quot;$DIR&quot; != &quot;/&quot;; do
    for m in GNUmakefile makefile Makefile; do
        if [ -f &quot;${DIR}/${m}&quot; ]; then
            echo &quot;Using ${m} from ${DIR}&quot; | sed &quot;s#$EHOME#~#&quot; &gt; /dev/stderr
            make -C &quot;${DIR}&quot;
            exit
        fi
    done
    DIR=`dirname &quot;${DIR}&quot;`
done
echo &quot;No Makefile found!&quot; &gt; /dev/stderr
</pre></li>
<li>Create a new tool and call it Ant</li>
<li>Paste the script for the build tool into the empty space provided for the script of the Ant tool</li>
<li>Locate the line which contains:<br />
<pre class="brush: bash;">
for m in GNUmakefile makefile Makefile; do
</pre></p>
<p>(this should be the 6th line) and modify this line so it looks like</p>
<p><pre class="brush: bash;">
for m in build.xml; do
</pre></li>
<li>Locate the line which says:<br />
<pre class="brush: bash;">
make -C &quot;${DIR}&quot;
</pre></p>
<p>and replace it so it says</p>
<p><pre class="brush: bash;">
ant -buildfile &quot;${DIR}/build.xml&quot;
</pre></li>
<li>Finally locate the line which says<br />
<pre class="brush: bash;">
echo &quot;No Makefile found!&quot; &gt; /dev/stderr
</pre></p>
<p>and modify it to look like</p>
<p><pre class="brush: bash;">
echo &quot;No build.xml file found!&quot; &gt; /dev/stderr
</pre></li>
<li>If you want a shortcut you can click on the shortcut button and select your favorite build shortcut.</li>
</ol>
<p>I guess that does it for the Ant shell script. The next part would deal with incorporating the ant build system into your flex project. It is worth noting that this method used here could be used to build just about any program in any language which uses the ant build system.</p>
<h1>Building your Code</h1>
<p>To build your code you need a <code>build.xml</code> file which would describe how ant should build your code. This file is organized in such a way that it represents a series of tasks. A good description of how to write a build.xml file for a flex project could be found <a href="http://livedocs.adobe.com/flex/3/html/help.html?content=anttasks_3.html">here</a> on the Adobe Livedocs website.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fahodzi.wordpress.com/206/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fahodzi.wordpress.com/206/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/fahodzi.wordpress.com/206/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/fahodzi.wordpress.com/206/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/fahodzi.wordpress.com/206/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/fahodzi.wordpress.com/206/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/fahodzi.wordpress.com/206/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/fahodzi.wordpress.com/206/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/fahodzi.wordpress.com/206/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/fahodzi.wordpress.com/206/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/fahodzi.wordpress.com/206/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/fahodzi.wordpress.com/206/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/fahodzi.wordpress.com/206/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/fahodzi.wordpress.com/206/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fahodzi.wordpress.com&amp;blog=3071373&amp;post=206&amp;subd=fahodzi&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fahodzi.wordpress.com/2010/08/24/getting-flex-ible-with-gedit-ant-style/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/cb2e26312d01604c5cb234903c476ef8?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">simpa</media:title>
		</media:content>
	</item>
		<item>
		<title>The Magic of Embedded Webservers</title>
		<link>http://fahodzi.wordpress.com/2010/07/13/the-magic-of-embedded-webservers/</link>
		<comments>http://fahodzi.wordpress.com/2010/07/13/the-magic-of-embedded-webservers/#comments</comments>
		<pubDate>Tue, 13 Jul 2010 07:14:16 +0000</pubDate>
		<dc:creator>James Ekow Abaka Ainooson</dc:creator>
				<category><![CDATA[How To do Stuff]]></category>
		<category><![CDATA[Ideas]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[embedded]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[webserver]]></category>

		<guid isPermaLink="false">http://fahodzi.wordpress.com/?p=173</guid>
		<description><![CDATA[Sometimes non web-based applications you build may be installed on servers which are not physically accessible to you. In such cases you might want to rely on configuration files and log files to find out the status of your application. &#8230; <a href="http://fahodzi.wordpress.com/2010/07/13/the-magic-of-embedded-webservers/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fahodzi.wordpress.com&amp;blog=3071373&amp;post=173&amp;subd=fahodzi&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Sometimes non web-based applications you build may be installed on servers which are not physically accessible to you. In such cases you might want to rely on configuration files and log files to find out the status of your application. This may be cool in cases where you have very few or simple applications to manage. However, when the complexity rises, log files may no longer be easy to read and you may find yourself asking questions about variables in your own configuration files. Trust me these scenarios can get really frustrating and that is why you might want to consider embedded web servers.<span id="more-173"></span></p>
<p>I don&#8217;t really know how recent the technology I&#8217;m going to describe in this post is but it saved my life and I think its worth blogging about. (Afterall I haven&#8217;t written on this blog in a while). Embedded servers are light servers which sit right in the core of your application. The cool thing about these servers is the fact that they are part of your application. This means they have the opportunity (if given) to access all the variables in the very guts of your application. They are able to provide universal graphical user interfaces (web pages) which could easily be viewed accross several devices and platforms without much hassle. Through these interfaces, you can do anything from displaying status information, altering configurations or even issuing real-time commands to the application. The embedded web servers could also be used to add remote procedure call capabilities or other forms of API features to your application. This would make it easy for other developers to use services of your application without having to worry about low level networking protocols.</p>
<h1>A Basic 404 Server</h1>
<p>Lets take a quick look at one embedded web server class library for the Java platform. This class library comes with the <code>com.sun.net.httpserver</code> package. It&#8217;s currently my favourite embedded web server for Java software development. Its powerful enough to allow you to build any kind of web based control mechanism for your application and it is also very easy to develop with. Without talking much lets start coding.</p>
<p><pre class="brush: java;">
import com.sun.net.httpserver.*;
import java.net.InetSocketAddress;
import java.io.IOException;

public class WebServer
{
    public static void main(String[] args)
    {
        HttpServer server;
        InetSocketAddress address = new InetSocketAddress(4500);
        try {
            server = HttpServer.create(address, 0);
            server.start();
        } catch(IOException ex) {
            System.err.println(&quot;Error&quot;);
        }
    }
}
</pre></p>
<p>The code above is a basic embedded webserver. After compiling it on your machine, you can access it through http://localhost:4500. It only displays a 404 Error Message because it has nothing to display. The code basically creates an instance of the <code>HttpServer</code> class by passing an object of the <code>InetSocketAddress</code> class to it. The <code>InetSocketAddress</code> object contains information about which hosts are allowed to access the web server. In this particular instance the object makes it possible for any host to access the web server on the 4500 port.</p>
<h1>Serving Hello World</h1>
<p>To serve content through your embedded web server, you need to create handlers. These handlers are implementations of the<br />
<code>HttpHandler</code> interface from the class library. The interface expects your handler classes which implement it to have a <code>handle</code> method which takes up the job of serving your webpages and interpreting requests. The handle method is passed an object of the HttpExchange class and this object contains information about the request made to the server. It contains the request headers and it gives you the opportunity to set the response headers. It also gives you access to output and input streams for passing the information around. To add a handler to a server you need to add contexts to the server. These contexts represent the paths which need to be invoked in the URL to access the particular context handler. So to access the root or default page of your server you might want to define a context for the  &#8220;/&#8221; path. The handler for this context would then handle the output. Lets take a look at an implementation of a handler.</p>
<p><pre class="brush: java;">
import com.sun.net.httpserver.*;
import java.io.IOException;

class HomePageHandler implements HttpHandler {
    public void handle (HttpExchange exchange)
    {
        String response;

        // Set the response headers
        Headers responseHeaders = exchange.getResponseHeaders();
        responseHeaders.set(&quot;Content-Type&quot;, &quot;text/html&quot;);

        // Set the text for the response
        response = &quot;&lt;html&gt;&lt;head&gt;&lt;title&gt;Hello World&lt;/title&gt;&quot; +
                   &quot;&lt;/head&gt;&lt;body&gt;&lt;h1&gt;Hello World&lt;/h1&gt;&lt;/body&gt;&lt;/html&gt;&quot;;

        // Send the response
        try {
            exchange.sendResponseHeaders(200, response.length());
            exchange.getResponseBody().write(response.getBytes());
        } catch (IOException ex) {

        }
    }
}
</pre></p>
<p>Now we need to define the context in our server.</p>
<p><pre class="brush: java;">
import com.sun.net.httpserver.*;
import java.net.InetSocketAddress;
import java.io.IOException;

public class WebServer
{
    public static void main(String[] args)
    {
        HttpServer server;
        InetSocketAddress address = new InetSocketAddress(4500);
        try {
            server = HttpServer.create(address, 0);
            // Define the context
            server.createContext(&quot;/&quot;, new HomePageHandler());
            server.start();
        } catch(IOException ex) {
            System.err.println(&quot;Error&quot;);
        }
    }
}
</pre></p>
<p>After compiling this code and executing it, you would see the text Hello World written boldly in your browser when you access your local server.</p>
<h1>Handling Form Data</h1>
<p>When user input is required forms are used. There are mainly two ways of handling form data in web applications. With forms which use the GET method, the data is directly sent through the URL. With POST method forms the data is however sent through the body of the request. The code below shows how to access form data through both the POST and GET methods. Once compiled and executed, the code below would provide three contexts. The default context would present two forms, one using the GET method and the other for the POST method. The other contexts handle either the GET or POST forms.</p>
<p><pre class="brush: java;">
import com.sun.net.httpserver.*;
import java.net.InetSocketAddress;
import java.io.IOException;

public class WebServer
{
    public static void main(String[] args)
    {
        HttpServer server;
        InetSocketAddress address = new InetSocketAddress(4500);
        try {
            server = HttpServer.create(address, 0);
            server.createContext(&quot;/&quot;, new HomePageHandler());
            server.createContext(&quot;/get&quot;, new GetRequestHandler());
            server.createContext(&quot;/post&quot;, new PostRequestHandler());
            server.start();
        } catch(IOException ex) {
	    System.err.println(&quot;Error&quot;);
	}
    }
}
</pre></p>
<p><pre class="brush: java;">
import com.sun.net.httpserver.*;
import java.io.IOException;

class HomePageHandler implements HttpHandler {
    public void handle (HttpExchange exchange)
    {
        String response;
        Headers responseHeaders = exchange.getResponseHeaders();
        responseHeaders.set(&quot;Content-Type&quot;, &quot;text/html&quot;);
        response = &quot;&lt;html&gt;&lt;head&gt;&lt;title&gt;Hello World&lt;/title&gt;&quot; +
                   &quot;&lt;/head&gt;&lt;body&gt;&quot;+
                   &quot;&lt;h1&gt;Get Form&lt;/h1&gt;&quot;+
                   &quot;&lt;form action='/get' method='GET'&gt;&quot;+
                   &quot;Firstname &quot;+
                   &quot;&lt;input type='text' name='firstname' /&gt;&lt;br/&gt;&quot;+
                   &quot;Lastname &quot;+
                   &quot;&lt;input type='text' name='lastname' /&gt;&lt;br/&gt;&quot;+
                   &quot;&lt;input type='submit' value='Submit' /&gt;&lt;br/&gt;&quot;+
                   &quot;&lt;/form&gt;&quot;+
                   &quot;&lt;h1&gt;Post Form&lt;/h1&gt;&quot;+
                   &quot;&lt;form action='/post' method='POST'&gt;&quot;+
                   &quot;Firstname &quot;+
                   &quot;&lt;input type='text' name='firstname' /&gt;&lt;br/&gt;&quot;+
                   &quot;Lastname &quot;+
                   &quot;&lt;input type='text' name='lastname' /&gt;&lt;br/&gt;&quot;+
                   &quot;&lt;input type='submit' value='Submit' /&gt;&lt;br/&gt;&quot;+
                   &quot;&lt;/form&gt;&quot;+
                   &quot;&lt;/body&gt;&lt;/html&gt;&quot;;
        try {
            exchange.sendResponseHeaders(200, response.length());
            exchange.getResponseBody().write(response.getBytes());
        } catch (IOException ex) {

        }
    }
}
</pre></p>
<p><pre class="brush: java;">
import com.sun.net.httpserver.*;
import java.io.IOException;
import java.net.URLDecoder;

class GetRequestHandler implements HttpHandler {
	public void handle (HttpExchange exchange)
	{
            String response = &quot;&quot;;
            Headers responseHeaders = exchange.getResponseHeaders();
            responseHeaders.set(&quot;Content-Type&quot;, &quot;text/plain&quot;);
            String[] variables = exchange.getRequestURI().getRawQuery().split(&quot;&amp;&quot;);
             try {
                for(int i = 0; i &lt; variables.length; i++)
            {
                String[] parts = variables[i].split(&quot;=&quot;);
                response += (parts[0] + &quot; = &quot; + URLDecoder.decode(parts[1], &quot;utf8&quot;) + &quot;\n&quot;);
            }
            exchange.sendResponseHeaders(200, response.length());
            exchange.getResponseBody().write(response.getBytes());
        } catch (IOException ex) {
            System.out.println(ex);
        }
    }
}
</pre></p>
<h1>Conclusion?</h1>
<p>I am very sure we have covered enough ground concerning this webserver. There is a lot more that could be done through it. I would advice going through the documentation for this class which could be found here <a href="http://java.sun.com/javase/6/docs/jre/api/net/httpserver/spec/com/sun/net/httpserver/package-summary.html">http://java.sun.com/javase/6/docs/jre/api/net/httpserver/spec/com/sun/net/httpserver/package-summary.html</a>.</p>
<p>Happy Programming!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fahodzi.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fahodzi.wordpress.com/173/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/fahodzi.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/fahodzi.wordpress.com/173/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/fahodzi.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/fahodzi.wordpress.com/173/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/fahodzi.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/fahodzi.wordpress.com/173/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/fahodzi.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/fahodzi.wordpress.com/173/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/fahodzi.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/fahodzi.wordpress.com/173/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/fahodzi.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/fahodzi.wordpress.com/173/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fahodzi.wordpress.com&amp;blog=3071373&amp;post=173&amp;subd=fahodzi&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fahodzi.wordpress.com/2010/07/13/the-magic-of-embedded-webservers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/cb2e26312d01604c5cb234903c476ef8?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">simpa</media:title>
		</media:content>
	</item>
		<item>
		<title>Soft Shadows in OpenOffice.org using Gimp</title>
		<link>http://fahodzi.wordpress.com/2009/12/20/soft-shadows-in-openoffice-org-using-gimp/</link>
		<comments>http://fahodzi.wordpress.com/2009/12/20/soft-shadows-in-openoffice-org-using-gimp/#comments</comments>
		<pubDate>Sun, 20 Dec 2009 07:00:38 +0000</pubDate>
		<dc:creator>James Ekow Abaka Ainooson</dc:creator>
				<category><![CDATA[How To do Stuff]]></category>
		<category><![CDATA[Ideas]]></category>
		<category><![CDATA[diagram]]></category>
		<category><![CDATA[document]]></category>
		<category><![CDATA[draw]]></category>
		<category><![CDATA[drawing]]></category>
		<category><![CDATA[gimp]]></category>
		<category><![CDATA[graphics]]></category>
		<category><![CDATA[office]]></category>
		<category><![CDATA[open]]></category>
		<category><![CDATA[openoffice]]></category>
		<category><![CDATA[openoffice.org]]></category>
		<category><![CDATA[shadows]]></category>

		<guid isPermaLink="false">http://fahodzi.wordpress.com/?p=141</guid>
		<description><![CDATA[There is no doubt about the fact that soft shadows make any piece of graphics stand out. It adds that extra touch of professionalism to any illustration and it makes the illustrations look and feel just right in any document &#8230; <a href="http://fahodzi.wordpress.com/2009/12/20/soft-shadows-in-openoffice-org-using-gimp/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fahodzi.wordpress.com&amp;blog=3071373&amp;post=141&amp;subd=fahodzi&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a class="DiggThisButton DiggMedium" href="http://digg.com/submit?url=http%3A%2F%2Ffahodzi.wordpress.com%2F2009%2F12%2F20%2Fsoft-shadows-in-openoffice-org-using-gimp%2F&amp;title=Soft+Shadows+in+OpenOffice.org+using%26nbsp%3BGimp"></a>There is no doubt about the fact that soft shadows make any piece of graphics stand out. It adds that extra touch of professionalism to any illustration and it makes the illustrations look and feel just right in any document or presentation (if properly used). I have been using Open Office for a while and after several hours of combing Google just to find a way to create soft shadows in OpenOffice, I only came up with this <a href="http://www.openoffice.org/issues/show_bug.cgi?id=64343" target="_blank">page</a> which happens to be a page on the OpenOffice.org issue tracker requesting the same feature. This means that it is still a work in progress (and you can vote for it to give it a higher priority). In the mean time, while we wait for the guys at OOo to code this feature for us, we can actually play around with GIMP and open office to produce some rudimentary soft shadows which also look good.</p>
<p><span id="more-141"></span></p>
<p>Let&#8217;s start with this simple diagram drawn up in OpenOffice.org&#8217;s Draw package.</p>
<p><a href="http://fahodzi.files.wordpress.com/2009/12/diagram1.png"><img class="alignnone size-full wp-image-145" title="Initial Diagram" src="http://fahodzi.files.wordpress.com/2009/12/diagram1.png?w=348&#038;h=306" alt="" width="348" height="306" /></a></p>
<p>Assuming soft shadows are to be added to each of the rounded rectangles, fire up GIMP and draw a rounded rectangle (not necessarily up to the scale and size of what you have in your OOo drawing).</p>
<p><a href="http://fahodzi.files.wordpress.com/2009/12/diagram2.png"><img class="alignnone size-full wp-image-147" title="diagram2" src="http://fahodzi.files.wordpress.com/2009/12/diagram2.png?w=500&#038;h=256" alt="" width="500" height="256" /></a></p>
<p>After the rectangle is drawn, add a little bit of Gaussian blur to it. This is what would actually give the soft shadow effect.</p>
<p><a href="http://fahodzi.files.wordpress.com/2009/12/diagram3.png"><img class="alignnone size-full wp-image-149" title="diagram3" src="http://fahodzi.files.wordpress.com/2009/12/diagram3.png?w=414&#038;h=380" alt="" width="414" height="380" /></a></p>
<p>Next insert the shadow you created from GIMP into your drawing.</p>
<p><a href="http://fahodzi.files.wordpress.com/2009/12/diagram4.png"><img class="alignnone size-full wp-image-152" title="diagram4" src="http://fahodzi.files.wordpress.com/2009/12/diagram4.png?w=340&#038;h=232" alt="" width="340" height="232" /></a></p>
<p>Send the shadow to the back of the drawing &#8230;</p>
<p><a href="http://fahodzi.files.wordpress.com/2009/12/diagram5.png"><img class="alignnone size-full wp-image-153" title="diagram5" src="http://fahodzi.files.wordpress.com/2009/12/diagram5.png?w=474&#038;h=387" alt="" width="474" height="387" /></a></p>
<p>&#8230; and align it properly (as you like). And there you would have a beautiful soft shadow. You can use OOo to adjust the transparency of the shadow till you think its nice enough.</p>
<p><a href="http://fahodzi.files.wordpress.com/2009/12/diagram6.png"><img class="alignnone size-full wp-image-154" title="diagram6" src="http://fahodzi.files.wordpress.com/2009/12/diagram6.png?w=458&#038;h=366" alt="" width="458" height="366" /></a></p>
<p>To make your diagram even nicer you can consider filling your rounded rectangle with a gradient.</p>
<p><a href="http://fahodzi.files.wordpress.com/2009/12/diagram7.png"><img class="alignnone size-full wp-image-155" title="diagram7" src="http://fahodzi.files.wordpress.com/2009/12/diagram7.png?w=453&#038;h=359" alt="" width="453" height="359" /></a></p>
<p>You can also extend the effect to all the other elements in your diagram.</p>
<p><a href="http://fahodzi.files.wordpress.com/2009/12/diagram8.png"><img class="alignnone size-full wp-image-156" title="diagram8" src="http://fahodzi.files.wordpress.com/2009/12/diagram8.png?w=448&#038;h=340" alt="" width="448" height="340" /></a></p>
<p>So there we have it. A few things you could do to this would be to:</p>
<ol>
<li>Group all the elements so that when you resize or scale the group, the shadows and all their corresponding diagrams would also be resized.</li>
<li>Have a folder which contains already made shadows for the common drawing primitives that you use (e.g. circles, rectangles e.t.c). In the cases where your diagrams seem to be a bit more complicated, you can then go into gimp and create a specific shadow for your diagram.</li>
</ol>
<p>Hope you enjoyed this one.</p>
<p>Happy Drawing.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fahodzi.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fahodzi.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/fahodzi.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/fahodzi.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/fahodzi.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/fahodzi.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/fahodzi.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/fahodzi.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/fahodzi.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/fahodzi.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/fahodzi.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/fahodzi.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/fahodzi.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/fahodzi.wordpress.com/141/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fahodzi.wordpress.com&amp;blog=3071373&amp;post=141&amp;subd=fahodzi&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fahodzi.wordpress.com/2009/12/20/soft-shadows-in-openoffice-org-using-gimp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/cb2e26312d01604c5cb234903c476ef8?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">simpa</media:title>
		</media:content>

		<media:content url="http://fahodzi.files.wordpress.com/2009/12/diagram1.png" medium="image">
			<media:title type="html">Initial Diagram</media:title>
		</media:content>

		<media:content url="http://fahodzi.files.wordpress.com/2009/12/diagram2.png" medium="image">
			<media:title type="html">diagram2</media:title>
		</media:content>

		<media:content url="http://fahodzi.files.wordpress.com/2009/12/diagram3.png" medium="image">
			<media:title type="html">diagram3</media:title>
		</media:content>

		<media:content url="http://fahodzi.files.wordpress.com/2009/12/diagram4.png" medium="image">
			<media:title type="html">diagram4</media:title>
		</media:content>

		<media:content url="http://fahodzi.files.wordpress.com/2009/12/diagram5.png" medium="image">
			<media:title type="html">diagram5</media:title>
		</media:content>

		<media:content url="http://fahodzi.files.wordpress.com/2009/12/diagram6.png" medium="image">
			<media:title type="html">diagram6</media:title>
		</media:content>

		<media:content url="http://fahodzi.files.wordpress.com/2009/12/diagram7.png" medium="image">
			<media:title type="html">diagram7</media:title>
		</media:content>

		<media:content url="http://fahodzi.files.wordpress.com/2009/12/diagram8.png" medium="image">
			<media:title type="html">diagram8</media:title>
		</media:content>
	</item>
		<item>
		<title>A JavaScript MP3 Player Tutorial</title>
		<link>http://fahodzi.wordpress.com/2009/11/16/a-javascript-mp3-player-tutorial/</link>
		<comments>http://fahodzi.wordpress.com/2009/11/16/a-javascript-mp3-player-tutorial/#comments</comments>
		<pubDate>Mon, 16 Nov 2009 11:09:14 +0000</pubDate>
		<dc:creator>James Ekow Abaka Ainooson</dc:creator>
				<category><![CDATA[How To do Stuff]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[actionscript3]]></category>
		<category><![CDATA[audio]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[mp3]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://fahodzi.wordpress.com/?p=117</guid>
		<description><![CDATA[Lots of things go on around me yet making the time to write them is quite difficult. Well now I have made it a point to share some knowledge all the time so this time I am going to do &#8230; <a href="http://fahodzi.wordpress.com/2009/11/16/a-javascript-mp3-player-tutorial/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fahodzi.wordpress.com&amp;blog=3071373&amp;post=117&amp;subd=fahodzi&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Lots of things go on around me yet making the time to write them is quite difficult. Well now I have made it a point to share some knowledge all the time so this time I am going to do a little piece about how an MP3 player can be implemented in JavaScript with the help of Adobe Flash, through ActionScript 3. I noticed this trick was being used on several websites. It took me a while to actually figure out that they were using a flash object to handle the playback of the MP3. I thought it was cool and I am sure there are several people out there who want to implement similar ones of their own. So in this post I am only going to help you build a basic player so that you would at least get the Idea. I believe that with the idea firmly understood, you could extend this to do just about anything you would want it to. This sure promises to be fun.</p>
<p><span id="more-117"></span></p>
<p>Okay so without any more talking, this is how we are going to do it. We are going to use the <code>Sound</code>, <code>Sprite</code> and <code>ExtenalInterface</code> classes from ActionScript class library to implement a very simple flash object which has the capabilities to load MP3&#8242;s and play them. We would then use JavaScript as a medium to control the playback from this flash object by talking to it through the <code>ExternalInterface</code> class. In effect we are building a JavaScript wrapper around the ActionScript Sound class. I don&#8217;t really know if there are any security issues related to this but I would investigate.</p>
<p>Lets start coding. I am going to give you the full code for the ActionScript component then I would explain it later.</p>
<p><pre class="brush: as3;">
package
{
    import flash.media.Sound;
    import flash.media.SoundChannel;
    import flash.external.ExternalInterface;
    import flash.net.URLRequest;
    import flash.display.Sprite;

    public class JSMP3 extends Sprite
    {
        private var soundChannel:SoundChannel;
        private var sound:Sound;

        public function JSMP3():void
        {
            // Externalize our interface functions
            // for the load, play and stop
            ExternalInterface.addCallback(&quot;load&quot;,load);
            ExternalInterface.addCallback(&quot;play&quot;,play);
            ExternalInterface.addCallback(&quot;stop&quot;,stop);
        }

        private function load(url:String):void
        {
            // Create a new URLRequest for the mp3 file
            var urlRequest:URLRequest = new URLRequest(url);

            // Try to stop the sound channel if it already
            // playing any audio.
            try
            {
                soundChannel.stop();
            }
            catch(e:Error) {  }

            // Create a new sound object and load the
            // URL into the object
            sound = new Sound();
            sound.load(urlRequest);
        }

        private function play():void
        {
            // Play the sound
            soundChannel = sound.play();
        }

        private function stop():void
        {
            // Try to stop the sound if it is already playing.
            try
            {
                soundChannel.stop();
            }
            catch(e:Error)
            {

            }
        }
    }
}
</pre></p>
<p>You could copy this code into a text file and save it as <code>JSMP3.as</code>. To compile it you must have the Flex 3 SDK installed and from the command line you could execute <code>mxmlc JSMP3.as</code>. That should produce the JSMP3.swf file which would be used for the purpose of playing the MP3 files in your JavaScript program. Lets try to understand the code.</p>
<p>Looking at the source code you see that it is a really simple one. The main package, the imports and the class are all standard ActionScript stuff. The JSMP3 class extends the Sprite class from the flash.display package. Although we are not going to be using any Sprite features, this extension is still necessary because without that our MP3 player cannot be embedded into an HTML page. The constructor uses the ExternalInterface class to expose three methods to the JavaScript. These are the load, play and stop methods. The implementation for these methods are below the constructor and they expect their parameters to be passed from the JavaScripts that are going to be calling them. Well now that we are done with the ActionScript, lets look at the JavaScript / HTML code.</p>
<p><pre class="brush: jscript;">
var JSMP3Player =
{
    player : function()
        {
            if (navigator.appName.indexOf(&quot;Microsoft&quot;) != -1)
            {
                return window[&quot;JSMP3&quot;];
            }
            else
            {
                return document[&quot;JSMP3&quot;];
            }
        },

    play : function(url)
        {
            this.player().load(url);
            this.player().play();
        },

    stop : function()
        {
            this.player().stop();
        }
}
</pre></p>
<p>This JavaScript wraps around the flash object that would be embedded into the HTML page. From the code you can tell that the flash object would have an id or a name JSMP3. The function for doing this wrapping was actually taken from the Flex 3 SDL Language Reference.</p>
<p><pre class="brush: xml;">
&lt;html&gt;
&lt;head&gt;
    &lt;title&gt;MP3 Player Test&lt;/title&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;JSMP3.js&quot;&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;

    &lt;object classid=&quot;clsid:D27CDB6E-AE6D-11cf-96B8-444553540000&quot;
             id=&quot;JSMP3&quot; width=&quot;0&quot; height=&quot;0&quot;
             codebase=&quot;http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab&quot;&gt;
        &lt;param name=&quot;movie&quot; value=&quot;JSMP3.swf&quot; /&gt;
        &lt;param name=&quot;quality&quot; value=&quot;high&quot; /&gt;
        &lt;param name=&quot;bgcolor&quot; value=&quot;#869ca7&quot; /&gt;
        &lt;param name=&quot;allowScriptAccess&quot; value=&quot;sameDomain&quot; /&gt;
        &lt;embed src=&quot;JSMP3.swf&quot; quality=&quot;high&quot; bgcolor=&quot;#869ca7&quot;
             width=&quot;0&quot; height=&quot;0&quot; name=&quot;JSMP3&quot; align=&quot;middle&quot;
             play=&quot;true&quot; loop=&quot;false&quot; quality=&quot;high&quot; allowScriptAccess=&quot;sameDomain&quot;
             type=&quot;application/x-shockwave-flash&quot;
             pluginspage=&quot;http://www.macromedia.com/go/getflashplayer&quot;&gt;
        &lt;/embed&gt;
    &lt;/object&gt;

    &lt;input type=&quot;button&quot; onclick=&quot;JSMP3Player.play('obrafour_nkaseibo.mp3')&quot; value=&quot;Play&quot; /&gt;
    &lt;input type=&quot;button&quot; onClick=&quot;JSMP3Player.stop()&quot; value=&quot;Stop&quot; /&gt;

&lt;/body&gt;
&lt;/html&gt;
</pre></p>
<p>This code adds the flash object to the html page. The object is given a width and a height of 0 so we do not see it. The two input buttons for play and stop actually call the play and stop methods for our JavaScript wrapper which also calls the flash object to either load and play an MP3 file or stop the playback if any.</p>
<p>So there we have it. I have tried to keep it as simple as possible. Several things could be done to extend this player. For instance you could add methods to detect when the audio is buffering, you could add methods to enable the controlling of the volume as well as seek through the playback of the audio. I wish I could have given some form of demonstration. All the same I think the picture should be clear enough if your coding skills are on point (as far as the technologies utilized are concerned). I stand to be corrected if any errors are detected in this post.</p>
<p>Happy Programming.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fahodzi.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fahodzi.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/fahodzi.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/fahodzi.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/fahodzi.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/fahodzi.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/fahodzi.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/fahodzi.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/fahodzi.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/fahodzi.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/fahodzi.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/fahodzi.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/fahodzi.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/fahodzi.wordpress.com/117/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fahodzi.wordpress.com&amp;blog=3071373&amp;post=117&amp;subd=fahodzi&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fahodzi.wordpress.com/2009/11/16/a-javascript-mp3-player-tutorial/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/cb2e26312d01604c5cb234903c476ef8?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">simpa</media:title>
		</media:content>
	</item>
		<item>
		<title>Compiling PortMidi in Windows with Eclipse/MinGW</title>
		<link>http://fahodzi.wordpress.com/2009/09/28/compiling-portmidi-in-windows-with-eclipsemingw/</link>
		<comments>http://fahodzi.wordpress.com/2009/09/28/compiling-portmidi-in-windows-with-eclipsemingw/#comments</comments>
		<pubDate>Mon, 28 Sep 2009 09:24:56 +0000</pubDate>
		<dc:creator>James Ekow Abaka Ainooson</dc:creator>
				<category><![CDATA[How To do Stuff]]></category>
		<category><![CDATA[Ideas]]></category>

		<guid isPermaLink="false">http://fahodzi.wordpress.com/?p=94</guid>
		<description><![CDATA[Why I did this? Over the past few weeks I have been working on this project which in some ways uses MIDI. I have primarily been working in Linux  but I had plans of porting the finished application to windows. &#8230; <a href="http://fahodzi.wordpress.com/2009/09/28/compiling-portmidi-in-windows-with-eclipsemingw/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fahodzi.wordpress.com&amp;blog=3071373&amp;post=94&amp;subd=fahodzi&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h3>Why I did this?</h3>
<p>Over the past few weeks I have been working on this project which in some ways uses MIDI. I have primarily been working in Linux  but I had plans of porting the finished application to windows. In order to convince myself after a while that my approach would work, I decided to try to compile the unfinished app in Windows.<span id="more-94"></span></p>
<p>My toolchain basically contains Autotools &amp; GCC under linux. I however use Eclipse as my IDE and GDB for debugging. What I did was I set up MinGW under windows just so I could mimic the linux environment to some detail. I was able to get precompiled versions of most of the libraries I was using (GTKmm, SDL) except for portaudio and portmidi. So I had to get the sources and build them myself. Portaudio built straight out of the box without any problems but Portmidi sucked. I am pretty sure other people might have this same problem so I am writing just in case &#8230;</p>
<h3>How do you do this?</h3>
<p>Well I just want to assure you that we are not going to be writing any scripts so don&#8217;t worry about that. Before you start ensure that you have Eclipse and MinGW properly installed (such that you can actually compile your C programs in Eclipse with MinGW).</p>
<p>Download a copy of the PortMidi library from here <a href="http://portmedia.sourceforge.net/">http://portmedia.sourceforge.net/</a>.  Extract the archive and <strong>move</strong> the porttime folder out of the portmidi folder. We are going to compile the porttime library separately. It would later be used as a dependency when compiling the port midi library itself. To prep the folder for compilation delete the source files that are not needed for the MS-Windows platform (I know this sounds harsh but that is exactly how I did it). These files are ptlinux.c, ptmacos_cf.c and ptmacos_mach.c. Okay now fire up the Eclipse ide. Create a new C shared library project. Call it porttime or whatever seems right but make sure that you do not use the default location. You should rather point it to the location of the altered porttime directory (d:\blog\porttime in my case).</p>
<div id="attachment_100" class="wp-caption alignnone" style="width: 325px"><img class="size-full wp-image-100" title="Creating the C Project" src="http://fahodzi.files.wordpress.com/2009/05/untitled.png?w=315&#038;h=328" alt="Creating the C Project" width="315" height="328" /><p class="wp-caption-text">Creating the C Project</p></div>
<p>When asked about the type of configuration on the next page, just choose release. Your project should now be ready. But you cant start compiling yet. There are still a few things you have to do. You now have to setup the compilation parameters. Right-click on the project in the project explorer and select the properties option.</p>
<p><img class="alignnone size-full wp-image-102" title="Selecting the properties options" src="http://fahodzi.files.wordpress.com/2009/05/untitled1.png?w=296&#038;h=400" alt="Selecting the properties options" width="296" height="400" /></p>
<p>When the properties dialog opens, edit the <strong>C/C++ Build&gt;&gt;Settings</strong> options. Now this is what you do:</p>
<ol>
<li>Under the Tools Settings tab select the <strong>MinGW C Linker&gt;&gt;Libraries </strong>option and add the <strong>winmm</strong> library, by clicking on the icon with the in Libraries box. This window should look like this after that:<img class="alignnone size-full wp-image-103" title="Setting up the linker" src="http://fahodzi.files.wordpress.com/2009/05/untitled2.png?w=420&#038;h=368" alt="Setting up the linker" width="420" height="368" /></li>
<li>Still under the Mingw C Linker node, select the Shared Library Settings option. Make sure the shared checkbox is active. Set the Shared object name field to libporttime.dll, set the Import library name to libporttime.dll.a and set the DEF file name to libporttime.def. This should also look like so:<br />
<img class="alignnone size-full wp-image-106" title="untitled3" src="http://fahodzi.files.wordpress.com/2009/05/untitled3.png?w=420&#038;h=353" alt="untitled3" width="420" height="353" /></li>
</ol>
<p>That should do it for the configuration of the porttime library. That was easy right? You can now go ahead and compile the library by clicking on the build icon (the one that looks like the hammer). We now have the porttime library built.</p>
<p>The main goal of all these activities was to compile the PortMidi library so now that we have porttime we can go ahead to compile the portmidi library. Its just as easy as building the porttime library. The only thing is this time you have to spend repeating the steps.</p>
<p>Hope You Liked This?</p>
<p>So that&#8217;s all. Hope I helped someone out there. Happy Programming.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fahodzi.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fahodzi.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/fahodzi.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/fahodzi.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/fahodzi.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/fahodzi.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/fahodzi.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/fahodzi.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/fahodzi.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/fahodzi.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/fahodzi.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/fahodzi.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/fahodzi.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/fahodzi.wordpress.com/94/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fahodzi.wordpress.com&amp;blog=3071373&amp;post=94&amp;subd=fahodzi&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fahodzi.wordpress.com/2009/09/28/compiling-portmidi-in-windows-with-eclipsemingw/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/cb2e26312d01604c5cb234903c476ef8?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">simpa</media:title>
		</media:content>

		<media:content url="http://fahodzi.files.wordpress.com/2009/05/untitled.png" medium="image">
			<media:title type="html">Creating the C Project</media:title>
		</media:content>

		<media:content url="http://fahodzi.files.wordpress.com/2009/05/untitled1.png" medium="image">
			<media:title type="html">Selecting the properties options</media:title>
		</media:content>

		<media:content url="http://fahodzi.files.wordpress.com/2009/05/untitled2.png" medium="image">
			<media:title type="html">Setting up the linker</media:title>
		</media:content>

		<media:content url="http://fahodzi.files.wordpress.com/2009/05/untitled3.png" medium="image">
			<media:title type="html">untitled3</media:title>
		</media:content>
	</item>
		<item>
		<title>PHP/HTML Forms Made Easy</title>
		<link>http://fahodzi.wordpress.com/2009/03/05/phphtml-forms-made-easy/</link>
		<comments>http://fahodzi.wordpress.com/2009/03/05/phphtml-forms-made-easy/#comments</comments>
		<pubDate>Thu, 05 Mar 2009 12:18:33 +0000</pubDate>
		<dc:creator>James Ekow Abaka Ainooson</dc:creator>
				<category><![CDATA[How To do Stuff]]></category>
		<category><![CDATA[application]]></category>
		<category><![CDATA[fields]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://fahodzi.wordpress.com/?p=39</guid>
		<description><![CDATA[Introduction I must admit here that one of the most annoying things for me when I was learning how to develop PHP/HTML applications was designing those HTML forms. Point blank, it sucks! It is very painful validating your data and &#8230; <a href="http://fahodzi.wordpress.com/2009/03/05/phphtml-forms-made-easy/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fahodzi.wordpress.com&amp;blog=3071373&amp;post=39&amp;subd=fahodzi&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h3><strong>Introduction</strong></h3>
<p><a class="DiggThisButton DiggMedium" href="http://digg.com/submit?url=http%3A%2F%2Ffahodzi.wordpress.com%2F2009%2F03%2F05%2Fphphtml-forms-made-easy%2F&amp;title=PHP%2FHTML+Forms+Made%26nbsp%3BEasy"></a>I must admit here that one of the most annoying things for me when I was learning how to develop PHP/HTML applications was designing those HTML forms.  Point blank, it sucks! It is very painful validating your data and doing all the other crap that comes along with that HTML chore. Don&#8217;t tell me about DreamWeaver and all those other WYSIWYG editors, they just don&#8217;t work for me.To solve my own problems, I decided to build a library to help me on the whole forms thing. This was actually inspired by the concept of the forms api in the Drupal content management system and the code igniter framework. I just didn&#8217;t use either because I wanted to be able to do something of my own so I could just extend it to do whatever I wanted without going through lenghty documentation. Trust me, the time invested is sometimes worth it. This forms library I am talking about has already been used in a couple of applications already (some by me and others by some very good developer friends of mine). This probably means that it has undergone some amount of testing already. I cannot stick my neck out that it is very secure and I can also not stick my neck out that it is very stable but one thing I can tell you is that it works.</p>
<p><span id="more-39"></span>Before we proceed to look at how the form library works and how it could be incorporated into an application, let&#8217;s spend some time to go through the features of the library. This library does the following things:</p>
<ol>
<li>It automatically generates HTML scripts which represents your forms.</li>
<li>It validates you form data (on the server side).</li>
<li>It provides some form of framework on which complex forms could be built.</li>
<li>It also has some features which allow you to automatically dump the values collected from the form into a table in a MySQL database.</li>
</ol>
<h3><strong>Creating your first form<br />
</strong></h3>
<p>Using this library is quite simple. All you really do is define your form and set a couple of callbacks to handle the data collected from the form. For a quick example lets build a small form which is used to collect data for an address book application. This form would later be configured to dump the data into the database. So here is the code (with the assumption that you have the fapi folder in the correct place):</p>
<p><pre class="brush: php;">
require_once &quot;fapi/fapi.php&quot;;

$form = new Form();

$firstname = new TextField(&quot;Firstname&quot;,&quot;firstname&quot;,&quot;The firstname of the person&quot;);
$form-&gt;add($firstname);

$lastname = new TextField(&quot;Lastname&quot;,&quot;lastname&quot;,&quot;The lastname of the person&quot;);
$form-&gt;add($lastname);

$email = new EmailField(&quot;Email&quot;,&quot;email&quot;,&quot;The primary email address of the person&quot;);
$form-&gt;add($email);

$phone = new TextField(&quot;Phone&quot;,&quot;phone_number&quot;,&quot;Phone number&quot;);
$form-&gt;add($phone);

$form-&gt;render();
?&gt;
</pre></p>
<p>Putting this stub of php code anywhere in your application would cause it to render a form which looks like the form in the image below.</p>
<p><img class="alignnone size-full wp-image-57" title="form1" src="http://fahodzi.files.wordpress.com/2009/02/form1.png?w=372&#038;h=284" alt="form1" width="372" height="284" /></p>
<p>Well you would agree with me that this is ugly but with a bit of CSS styling it could go a long way. I took some time to write a stylesheet for the output. This CSS file is located at<strong> fapi/css/fapi.css</strong>. Include this stylesheet in your HTML header and you should have a form which looks like the one below.</p>
<p><img class="alignnone size-full wp-image-68" title="form22" src="http://fahodzi.files.wordpress.com/2009/02/form22.png?w=546&#038;h=339" alt="form22" width="546" height="339" /></p>
<p>You must have noticed that the input fields in the form extends accross the whole widht of the page. You could limit this by placing your form in a div, a table  or any other HTML tag that would prevent its content from overflowing its boundaries.</p>
<p>Now let me explain the code. For this example we used the Form class, the TextField class and the EmailField class. The constructors of these classes (except that of the Form class) take a similar set of parameters. The first parameter is the label, the second parameter is the name of the field (which we would use for other purposes later) and the last parameter is a brief description you want to be displayed under the field when it is displayed. None of these are compulsory though so you could just instantiate the class without specifying any of the parameters. These type of fields are not the only types available in the library. You have similar stuff for radio buttons, check boxes, selection lists etc.</p>
<h3><strong>A More Advanced Form</strong></h3>
<p>Lets extend our form a bit. We are going to add a few more fields and containers. In this form we are going to have field sets (which are also containers just like forms) on our form and we are going to put the fields into the field set. The code for this form follows.</p>
<p><pre class="brush: php;">
require_once &quot;fapi/fapi.php&quot;;

//forms
$form = new Form();

//name
$name_fieldset = new FieldSet(&quot;Name&quot;);
$form-&gt;add($name_fieldset);

$firstname = new TextField(&quot;Firstname&quot;,&quot;firstname&quot;,&quot;The firstname of the person&quot;);
$name_fieldset-&gt;add($firstname);

$lastname = new TextField(&quot;Lastname&quot;,&quot;lastname&quot;,&quot;The lastname of the person&quot;);
$name_fieldset-&gt;add($lastname);

//internet
$internet_fieldset = new FieldSet(&quot;Internet&quot;);
$form-&gt;add($internet_fieldset);

$email = new EmailField(&quot;Email&quot;,&quot;email&quot;,&quot;The primary email address of the person&quot;);
$internet_fieldset-&gt;add($email);

$secondary_email = new EmailField(&quot;Second Email&quot;,&quot;secondary_email&quot;,&quot;The secondary email address of the person&quot;);
$internet_fieldset-&gt;add($secondary_email);

//phone
$phone_fieldset = new FieldSet(&quot;Phone&quot;);
$form-&gt;add($phone_fieldset);

$home_phone = new TextField(&quot;Home&quot;,&quot;home_phone_number&quot;,&quot;Home phone number&quot;);
$phone_fieldset-&gt;add($home_phone);

$work_phone = new TextField(&quot;Work&quot;,&quot;work_phone_number&quot;,&quot;Work phone number&quot;);
$phone_fieldset-&gt;add($work_phone);

$cell_phone = new TextField(&quot;Cell&quot;,&quot;cell_phone_number&quot;,&quot;Cell phone number&quot;);
$phone_fieldset-&gt;add($cell_phone);

$form-&gt;render();
?&gt;
</pre></p>
<p>If you haven&#8217;t already noticed, you should see that this time the fieldset objects are added to the form and the textfield objects are added to the fieldsets. This causes the fieldsets to be rendered on the form and the textfields to be rendered within the fieldsets. This is what the code above would output.</p>
<h3><strong>An Even More Advanced Form</strong></h3>
<p>Let us step things up a bit higher. We are now going to create a form with tabs. For the tabs to switch we may have to include some javascripts. The needed scripts are the <code>fapi/jscripts/jquery.js</code> and the <code>fapi/jscripts/fapi.js</code>. I guess we are going to fire on all cylinders now. Lets see the code.</p>
<p><pre class="brush: php;">
require_once &quot;fapi/fapi.php&quot;;

//forms
$form = new Form();

//category
$category = new SelectionList(&quot;Group&quot;,&quot;group&quot;,&quot;Which group should this address be stored under&quot;);
$category-&gt;addOption(&quot;Friends&quot;);
$category-&gt;addOption(&quot;Family&quot;);
$category-&gt;addOption(&quot;Business&quot;);
$form-&gt;add($category);

//tabs
$tabs = new TabLayout();
$form-&gt;add($tabs);

$contact_tab = new Tab(&quot;Contact&quot;);
$tabs-&gt;add($contact_tab);

//name
$name_fieldset = new FieldSet(&quot;Name&quot;);
$contact_tab-&gt;add($name_fieldset);

$firstname = new TextField(&quot;Firstname&quot;,&quot;firstname&quot;,&quot;The firstname of the person&quot;);
$name_fieldset-&gt;add($firstname);

$lastname = new TextField(&quot;Lastname&quot;,&quot;lastname&quot;,&quot;The lastname of the person&quot;);
$name_fieldset-&gt;add($lastname);

//internet
$internet_fieldset = new FieldSet(&quot;Internet&quot;);
$contact_tab-&gt;add($internet_fieldset);

$email = new EmailField(&quot;Email&quot;,&quot;email&quot;,&quot;The primary email address of the person&quot;);
$internet_fieldset-&gt;add($email);

$secondary_email = new EmailField(&quot;Second Email&quot;,&quot;secondary_email&quot;,&quot;The secondary email address of the person&quot;);
$internet_fieldset-&gt;add($secondary_email);

//phone
$phone_fieldset = new FieldSet(&quot;Phone&quot;);
$contact_tab-&gt;add($phone_fieldset);

$home_phone = new TextField(&quot;Home&quot;,&quot;home_phone_number&quot;,&quot;Home phone number&quot;);
$phone_fieldset-&gt;add($home_phone);

$work_phone = new TextField(&quot;Work&quot;,&quot;work_phone_number&quot;,&quot;Work phone number&quot;);
$phone_fieldset-&gt;add($work_phone);

$cell_phone = new TextField(&quot;Cell&quot;,&quot;cell_phone_number&quot;,&quot;Cell phone number&quot;);
$phone_fieldset-&gt;add($cell_phone);

//address
$address_tab = new Tab(&quot;Address&quot;);
$tabs-&gt;add($address_tab);

$home_fs = new FieldSet(&quot;Home&quot;,&quot;The home address of the person&quot;);
$address_tab-&gt;add($home_fs);

$home_address = new TextArea(&quot;Address&quot;,&quot;home_address&quot;);
$home_fs-&gt;add($home_address);

$home_city = new TextField(&quot;City&quot;,&quot;home_city&quot;);
$home_fs-&gt;add($home_city);

$home_rsp = new TextField(&quot;Region, State or Provice&quot;,&quot;home_rsp&quot;);
$home_fs-&gt;add($home_rsp);

$home_country = new TextField(&quot;Country&quot;,&quot;home_country&quot;);
$home_fs-&gt;add($home_country);

$work_fs = new FieldSet(&quot;Work&quot;,&quot;The work address of the person&quot;);
$address_tab-&gt;add($work_fs);

$work_address = new TextArea(&quot;Address&quot;,&quot;work_address&quot;);
$work_fs-&gt;add($work_address);

$work_city = new TextField(&quot;City&quot;,&quot;work_city&quot;);
$work_fs-&gt;add($work_city);

$work_rsp = new TextField(&quot;Region, State or Provice&quot;,&quot;work_rsp&quot;);
$work_fs-&gt;add($work_rsp);

$work_country = new TextField(&quot;Country&quot;,&quot;work_country&quot;);
$work_fs-&gt;add($work_country);

//ims
$im_tab = new Tab(&quot;IMs&quot;);
$tabs-&gt;add($im_tab);

$im_google = new TextField(&quot;Google&quot;,&quot;im_google&quot;);
$im_tab-&gt;add($im_google);

$im_yahoo = new TextField(&quot;Yahoo!&quot;,&quot;im_yahoo&quot;);
$im_tab-&gt;add($im_yahoo);

$im_msn = new TextField(&quot;MSN&quot;,&quot;im_msn&quot;);
$im_tab-&gt;add($im_msn);

$im_aol = new TextField(&quot;AOL&quot;,&quot;im_aol&quot;);
$im_tab-&gt;add($im_aol);

$im_irc = new TextField(&quot;IRC&quot;,&quot;im_irc&quot;);
$im_tab-&gt;add($im_irc);

$form-&gt;render();
</pre></p>
<p>You can click here to have a look at this code in action <a title="http://fahodzi.paanoo.com/fapi_tutorial1.php" href="http://fahodzi.paanoo.com/fapi_tutorial1.php" target="_blank">http://fahodzi.paanoo.com/fapi_tutorial1.php<br />
</a></p>
<h3><strong>Elements, Fields and Containers</strong></h3>
<p>After we have done some forms lets see what more we can do. In case you haven&#8217;t noticed already, the whole library is orgarnized into fields and containers. There are actually three major abstract classes which serve as the foundation for the whole library. These are the Element, Field and Container classes. The Element class, which is the base class for most of the classes in the library is responsible for some html services. The Field class is a subclass of the Element class and it is responsible for producing and handling fields like (TextField, RadioButton, Checkboxes and the others). The container class is also a subclass of the element class. It is used for containing other elements. This means it can contain both fields and containers. Some of the contianers are the Form, the Tab, the Box and the Fieldset.</p>
<h3><strong>Validating the form data</strong></h3>
<p>There are several validations you can perform on your fields. First of all you can set some fields as required just by setting the reqired property of the field. This is done by calling the setter method as such:</p>
<p><pre class="brush: php;">
$field-&gt;setRequired(true);
</pre></p>
<p>As soon as you call this method on any of the fields, it would be required for that field to contain data whenever the form is submitted. If there is no data a simple error message is displayed for the user to handle.</p>
<p>Apart from the required validation you can define custom validation functions which are called on your field whenever the data is submitted. The details of this can be figured out from the documentation. The TextField class has an inbuilt regular expression validation method which comes in handy when you want to do more complex validations.</p>
<h3><strong>Getting Using the Form Data<br />
</strong></h3>
<p>After you have collected your data you might want to perform some operations on the form data. In most cases you might want to save the data into a database. Every form has a property called the callback. The call back is a function which takes one parameter. The parameter of the callback function is passed the data that was captured in the form. Another thing that many people find cool about this form library is the automatic data insertion into the database. These are handled by the setDatabaseSchema(), setDatabaseTable() and setPrimaryKey() methods.</p>
<p>If you set the database schema and table and a connection exists to a database, the form class automatically dumps the form data into the table. The field names of your table must correspond with the field names of the fields in the form. If you set the primary key, the form is automatically filled with the form data on rendering so that when submitted, the data is rather updated instead of it being saved again.</p>
<h3><strong>Conclusions</strong></h3>
<p>There are so many things I had wanted to write about but time didn&#8217;t allow me to. I am pretty sure if you really want to use this library, you can go through the little documentation that comes with it and figure things out for your self. It is really not that difficult. All the same, I would like to comment a little about things I personally do not like about this library.</p>
<p>The paramount thing is the one that has to do with form data being saved automatically. This is really not very good and although I liked it initially really do not use it much these days. I rather extracted the code that does the magic and used it to implement some form of active record system and it is even much more simpler (I may write on that in my next post).</p>
<p>Another thing that I would really like to add in future is proper javascript support so that the forms could be submitted through AJAX. Now that would be cool. When I do that I do not want to break the library signatures so that it would be very portable to existing code. But for now this is all I have and unless I really feel the necessity to do that, I am really going to keep this one. Anyway I have added the whole library and a little documentation to this post. You can download it from here <a href="http://fahodzi.paanoo.com/fapi.tar.bz2">http://fahodzi.paanoo.com/fapi.tar.bz2</a> (please bear with me if you find any strange things in the documentation. I made the that one for a client) . Hope you enjoy it. Happy programming.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fahodzi.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fahodzi.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/fahodzi.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/fahodzi.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/fahodzi.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/fahodzi.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/fahodzi.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/fahodzi.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/fahodzi.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/fahodzi.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/fahodzi.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/fahodzi.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/fahodzi.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/fahodzi.wordpress.com/39/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fahodzi.wordpress.com&amp;blog=3071373&amp;post=39&amp;subd=fahodzi&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fahodzi.wordpress.com/2009/03/05/phphtml-forms-made-easy/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/cb2e26312d01604c5cb234903c476ef8?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">simpa</media:title>
		</media:content>

		<media:content url="http://fahodzi.files.wordpress.com/2009/02/form1.png" medium="image">
			<media:title type="html">form1</media:title>
		</media:content>

		<media:content url="http://fahodzi.files.wordpress.com/2009/02/form22.png" medium="image">
			<media:title type="html">form22</media:title>
		</media:content>
	</item>
		<item>
		<title>Getting FLEX-ible With GEdit</title>
		<link>http://fahodzi.wordpress.com/2008/12/22/getting-flex-ible-with-gedit/</link>
		<comments>http://fahodzi.wordpress.com/2008/12/22/getting-flex-ible-with-gedit/#comments</comments>
		<pubDate>Mon, 22 Dec 2008 01:02:25 +0000</pubDate>
		<dc:creator>James Ekow Abaka Ainooson</dc:creator>
				<category><![CDATA[How To do Stuff]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[adobe]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[gedit]]></category>
		<category><![CDATA[gnome]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://fahodzi.wordpress.com/?p=30</guid>
		<description><![CDATA[For a long time I had always wanted to develop for the flash platform but the huge cost of the authouring suite always put me off. I tried a couple of open source ways to develop for the platform but &#8230; <a href="http://fahodzi.wordpress.com/2008/12/22/getting-flex-ible-with-gedit/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fahodzi.wordpress.com&amp;blog=3071373&amp;post=30&amp;subd=fahodzi&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>For a long time I had always wanted to develop for the flash platform but the huge cost of the authouring suite always put me off. I tried a couple of open source ways to develop for the platform but none of them really worked well for me. Earlier this year during a random escapade on the Internet I came accross Flex. <span id="more-30"></span></p>
<p>I realized I had been left behind. I personally decided to get into this but I couldn&#8217;t really get a suitable editor. The Flex Builder is expensive and most of the options out there are targeted more to Windows than to Linux. So I had to make do with what I had and I stuck to one of my personal favorites GEdit. I like to use GEdit a lot because for some reason the Oblivion colour scheme seems to be very friendly to my eyes. Well, this article is intended to help you configure GEdit so you could us it to write codes for flex or ActionScript.</p>
<p><strong>Asumptions</strong></p>
<ol>
<li>I am assuming that you have installed a copy of the Flex SDK and it is accessible through your PATH.</li>
<li>I am assuming that you have some basic understanding of bash sell scripting.</li>
</ol>
<p><strong>Configuring Gedit</strong></p>
<p>In GEdit locate Tools &gt;&gt; External Tools. On the dialog that opens select New Tool. Give the tool a name and go ahead to give it a shortcut (Try to figure those out). In the commands section paste the following:</p>
<p><pre class="brush: bash;">
#!/bin/bash
if (/opt/flex-3.2/bin/mxmlc &quot;$GEDIT_CURRENT_DOCUMENT_PATH&quot;)
then
/opt/flex-3.2/bin/flashplayer &quot;`echo $GEDIT_CURRENT_DOCUMENT_PATH | awk -F.mxml {'print $1'}`.swf&quot;
fi
</pre></p>
<p>Be sure to replace /opt/flex-3.2 with the correct location of your flex SDK and you are good to go. Anytime you hit the shortcut for your external tool your flex compiler would be invoked.</p>
<p>For syntax hilighting you might want to use XML for the MXML files and JAVA for the ActionScript files.</p>
<p><strong>Update</strong></p>
<p>This post has been updated see http://fahodzi.wordpress.com/2010/08/24/getting-flex-ible-with-gedit-ant-style/ for updated post</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fahodzi.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fahodzi.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/fahodzi.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/fahodzi.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/fahodzi.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/fahodzi.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/fahodzi.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/fahodzi.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/fahodzi.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/fahodzi.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/fahodzi.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/fahodzi.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/fahodzi.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/fahodzi.wordpress.com/30/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fahodzi.wordpress.com&amp;blog=3071373&amp;post=30&amp;subd=fahodzi&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fahodzi.wordpress.com/2008/12/22/getting-flex-ible-with-gedit/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/cb2e26312d01604c5cb234903c476ef8?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">simpa</media:title>
		</media:content>
	</item>
		<item>
		<title>Is there really an easy way?</title>
		<link>http://fahodzi.wordpress.com/2008/11/06/is-there-really-an-easy-way/</link>
		<comments>http://fahodzi.wordpress.com/2008/11/06/is-there-really-an-easy-way/#comments</comments>
		<pubDate>Thu, 06 Nov 2008 11:50:48 +0000</pubDate>
		<dc:creator>James Ekow Abaka Ainooson</dc:creator>
				<category><![CDATA[What I think]]></category>

		<guid isPermaLink="false">http://fahodzi.wordpress.com/?p=24</guid>
		<description><![CDATA[I must say that its been quite a while since I expressed myself on this blog. I know this sounds like the regular cliche excuse but I have been busy. I have also been very broke. Sometimes it feels like &#8230; <a href="http://fahodzi.wordpress.com/2008/11/06/is-there-really-an-easy-way/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fahodzi.wordpress.com&amp;blog=3071373&amp;post=24&amp;subd=fahodzi&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I must say that its been quite a while since I expressed myself on this blog. I know this sounds like the regular cliche excuse but I have been busy. I have also been very broke. Sometimes it feels like I am living the broke but almost rich lifestyle. So now that I am done with the excuses I would like to continue with my post. In the past month, I have been working on this crack down of a project with some software development company. Through this project I have had the opportunity to meet a few of the developpers who actually turn the IT wheels here in Ghana (although there are technically three people working on my project and the other two are not related to this articvle). I am trying hard to learn a lot about this &#8220;IT business&#8221; as it is called in Ghana but my first lessons have not been pleasant ones.<span id="more-24"></span></p>
<p>I guess I have seen everything from unneccesary deadlines to poorly developped applications but one thing that I realized in general is that everybody is constantly in search of an easy way to finish something quickly and move on. It might be true that this is how everybody is working around the world (I mean with all the talk going on about rapid application development and all that), but I feel down here most people just have it wrong. We go around trying to find a way that works fast and better yet we end up working with something that is obviously not up to the task in any way. It might sound like I am just trying to air my frustrations on this blog but it is not so (although that is what blogs are for). The real truth is that it is difficult finding a relationship between what one is taught in school and what you meet in the real world. Things are much more different and I guess there are only two choices for me. Either I adapt to the industry or I try to influence it. The first option sounds like the best because the second one is very ambitious. However, the second one is worth giving a try. Well for now I think I just have to shut up and keep all my worries to myself.</p>
<p>Please not that blogs are for self expression. Not everything is written for people to read. But if you read through this and it didn&#8217;t make any sense then &#8230;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fahodzi.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fahodzi.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/fahodzi.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/fahodzi.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/fahodzi.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/fahodzi.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/fahodzi.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/fahodzi.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/fahodzi.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/fahodzi.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/fahodzi.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/fahodzi.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/fahodzi.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/fahodzi.wordpress.com/24/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fahodzi.wordpress.com&amp;blog=3071373&amp;post=24&amp;subd=fahodzi&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fahodzi.wordpress.com/2008/11/06/is-there-really-an-easy-way/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/cb2e26312d01604c5cb234903c476ef8?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">simpa</media:title>
		</media:content>
	</item>
		<item>
		<title>When PHP goes BOM! on Internet Explorer</title>
		<link>http://fahodzi.wordpress.com/2008/06/29/when-php-goes-bom-on-internet-explorer/</link>
		<comments>http://fahodzi.wordpress.com/2008/06/29/when-php-goes-bom-on-internet-explorer/#comments</comments>
		<pubDate>Sun, 29 Jun 2008 11:32:13 +0000</pubDate>
		<dc:creator>James Ekow Abaka Ainooson</dc:creator>
				<category><![CDATA[What I think]]></category>
		<category><![CDATA[ANSI]]></category>
		<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[Internet Explorrer]]></category>
		<category><![CDATA[Opera]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Safari]]></category>
		<category><![CDATA[UTF-8]]></category>

		<guid isPermaLink="false">http://fahodzi.wordpress.com/?p=21</guid>
		<description><![CDATA[I was recently working on a web content management system with a friend and we made a very surprising discovery. We were actually using PHP to include content from another page on our local server unto the page that was &#8230; <a href="http://fahodzi.wordpress.com/2008/06/29/when-php-goes-bom-on-internet-explorer/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fahodzi.wordpress.com&amp;blog=3071373&amp;post=21&amp;subd=fahodzi&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I was recently working on a web content management system with a friend and we made a very surprising discovery. We were actually using PHP to include content from another page on our local server unto the page that was curently being viewed. This thing worked perfectly when I was using the Eclipse editor but when I moved to my friends office and we started using Expression studio (which obviously doesn&#8217;t seem to support PHP), the include statement started introducing unwanted characters. Although most of the browsers on which this was tested (Opera, Safari and FireFox) skipped these characters, IE of all browsers displayed them and messed up our template. Well we started to panic because we didn&#8217;t know what we had done wrong and IE is one browser you don&#8217;t want to mess with because everybody uses it.</p>
<p><span id="more-21"></span></p>
<p>So we started digging on the Internet to find out what was actually wrong with the system. The first hint of our real problem was sensed when we saw a large number of newsgroup posts which described problems similar to what we were facing. Then we realized we were actually playing around with encoding problems. We figured out that saving the files we wanted to include with ANSI encoding saved the day.</p>
<p>The previous encoding format we were using was the UTF-8 format. This format is preceeded with a Byte Order Mark (BOM). This Byte Order Mark is obviously supposed to tell the reader of the format about the byte order of the file it is reading. When the PHP include function was called to include this file it also included the BOM characters which IE decided to display and mess up the template.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/fahodzi.wordpress.com/21/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/fahodzi.wordpress.com/21/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fahodzi.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fahodzi.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/fahodzi.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/fahodzi.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/fahodzi.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/fahodzi.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/fahodzi.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/fahodzi.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/fahodzi.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/fahodzi.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/fahodzi.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/fahodzi.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/fahodzi.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/fahodzi.wordpress.com/21/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fahodzi.wordpress.com&amp;blog=3071373&amp;post=21&amp;subd=fahodzi&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fahodzi.wordpress.com/2008/06/29/when-php-goes-bom-on-internet-explorer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/cb2e26312d01604c5cb234903c476ef8?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">simpa</media:title>
		</media:content>
	</item>
	</channel>
</rss>
