<?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>Talking with a Lisp</title>
	<atom:link href="http://z0ltan.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://z0ltan.wordpress.com</link>
	<description>Technical z0ltanspeak</description>
	<lastBuildDate>Tue, 03 Jan 2012 20:48:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='z0ltan.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Talking with a Lisp</title>
		<link>http://z0ltan.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://z0ltan.wordpress.com/osd.xml" title="Talking with a Lisp" />
	<atom:link rel='hub' href='http://z0ltan.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Serialization Issues with Quartz and PostgreSQL &#8211; Invalid Header Stream!</title>
		<link>http://z0ltan.wordpress.com/2012/01/04/serialization-issues-with-quartz-and-postgresql-invalid-header-stream/</link>
		<comments>http://z0ltan.wordpress.com/2012/01/04/serialization-issues-with-quartz-and-postgresql-invalid-header-stream/#comments</comments>
		<pubDate>Tue, 03 Jan 2012 20:42:55 +0000</pubDate>
		<dc:creator>z0ltan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://z0ltan.wordpress.com/?p=158</guid>
		<description><![CDATA[I have been working on a prototype using the Quartz Scheduler for my current work assignment. It has been an interesting week and I have had quite a few learning experiences that will make for more than a couple of blog posts. This is especially important to share since there seems to be a paucity [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=z0ltan.wordpress.com&amp;blog=3901691&amp;post=158&amp;subd=z0ltan&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I have been working on a prototype using the Quartz Scheduler for my current work assignment. It has been an interesting week and I have had quite a few learning experiences that will make for more than a couple of blog posts. This is especially important to share since there seems to be a paucity of useful information for troubleshooting Quartz issues online. I had a tough time figuring out stuff for myself what with the schedule deadlines always looming over my head! Nevertheless it made for a wholesome learning endeavor.</p>
<p>For this first blog on using the Quartz Scheduler and how to solve some live issues that will be encountered, I want to concentrate on a tricky error that I encountered while trying to implement a Persistent JobStore implementation of the Quartz Scheduler for my prototype. Here are the details of environment being used for the prototype</p>
<p><strong>Quartz Scheduler 1.8.3, JDK 1.6.0_23, PostgreSQL 9.0.1</strong></p>
<p>Now I know that Quartz Scheduler 2.1 is the latest stable version but due to project constraints, I had to use version 1.8.3 for my prototype. Ironically, I first learnt the Quartz Scheduling package using version 2.1! However, the issue that I was faced with is also present in basically any version of Quartz Scheduler. Alright, enough of foreplay, let’s get down to the dirty bit!<br />
For some background,in brief, Quartz Scheduler allows jobs to be stored either in memory (<strong>RAMJobStore</strong>) or in persistent storage (<strong>JobStoreTX</strong>, <strong>JobStoreCMT</strong>). The problem with RAMJobStore is that once the JVM is shut down, all the jobs and triggers that were present in the RAMJobStore instance are lost. This is obviously not ideal for a real production quality implementation of scheduling. Of the other two types of storage, JobStoreTX is basically used to persist jobs and associated triggers (plus a bunch of other stuff that the Quartz Scheduler requires for proper functioning) in database tables (12 tables for version 1.8.3, 12 for the 2.1 version). JobstoreCMT does the same. The main difference is that JobStoreTX is ideal for stand-alone applications which handle their own database transactions whereas JobStoreCMT (as the CMT in the name suggests) is meant for applications deployed in Application Containers (such as JBoss, WebLogic et al) so that database transactions are handled by the Container itself. For my project, however, I was constrained to use the Apache Tomcat Server (6.0.24) so I had to make do with JobStoreTX. For more information, refer to the official documentation on <a href="http://quartz-scheduler.org/">Quartz site</a>.<br />
So onto the problem which a lot of people might face but be flummoxed by, since the error message is not exactly intuitive. My prototype code is shown below. First off, the code that loads the scheduler and schedules the Job:</p>
<p><pre class="brush: java;">
package com.z0ltan.scheduling.prototype.jobstoretx;

import java.text.ParseException;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

import org.apache.log4j.Logger;
import org.quartz.CronExpression;
import org.quartz.CronTrigger;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerMetaData;
import org.quartz.impl.StdSchedulerFactory;

import com.z0ltan.scheduling.prototype.jobstoretx.job.StatefulLogTimeJob;

public class JobStoreTXTestScheduler {
	private static final Logger logger = Logger
			.getLogger(JobStoreTXTestScheduler.class);

	public static void main(String[] args) {
		JobStoreTXTestScheduler jsts = new JobStoreTXTestScheduler();
		Scheduler scheduler = null;

		try {
			scheduler = jsts.getScheduler();

			logger.info(&quot;Starting scheduler&quot;);
			scheduler.start();
			logger.info(&quot;Scheduler started at &quot; + new Date());

			logger.info(&quot;Scheduling jobs&quot;);
			jsts.scheduleJob(scheduler, &quot;StatefulLogTimeJob&quot;,
					&quot;StatefulLogTimeJobGroup&quot;, StatefulLogTimeJob.class, 5);

			try {
				Thread.sleep(24 * 60 * 1000);
			} catch (InterruptedException ex) {

			}

		} catch (SchedulerException ex) {
			logger.error(ex.getLocalizedMessage());
		} finally {
			try {
				if (scheduler != null &amp;&amp; !scheduler.isShutdown()) {
					scheduler.shutdown(true); // Wait for all running jobs
												// to be
												// completed
				}
			} catch (SchedulerException exc) {
				logger.error(exc.getLocalizedMessage());
			}
		}

	}

	private Scheduler getScheduler() throws SchedulerException {
		Scheduler scheduler = null;
		StdSchedulerFactory factory = new StdSchedulerFactory();
		factory.initialize(&quot;com/z0ltan/prototype/properties/jobstoretxscheduler.properties&quot;);

		scheduler = factory.getScheduler();

		// Log Scheduler Metadata
		SchedulerMetaData metadata = scheduler.getMetaData();
		logger.info(&quot;\tScheduler Name = &quot; + metadata.getSchedulerName());
		logger.info(&quot;\tScheduler ID = &quot; + metadata.getSchedulerInstanceId());
		logger.info(&quot;\tThreadPool class = &quot; + metadata.getThreadPoolClass());
		logger.info(&quot;\tThreadPool size = &quot; + metadata.getThreadPoolSize());
		logger.info(&quot;\tJobStore class = &quot; + metadata.getJobStoreClass());

		return scheduler;
	}

	private void scheduleJob(Scheduler scheduler, String jobName,
			String jobGroup, Class jobClass, int noOfOccurrences) {
		JobDetail job = new JobDetail(jobName, jobGroup, jobClass);
		job.getJobDataMap().put(&quot;ITER_COUNT&quot;, &quot;1&quot;);
		job.getJobDataMap().put(&quot;NO_OF_OCCURRENCES&quot;,
				Integer.toString(noOfOccurrences));
		job.setDurability(true);

		int dayOfMonth = 30;
		GregorianCalendar cal = new GregorianCalendar();
		int year = cal.get(Calendar.YEAR);
		CronTrigger trigger1 = null;

		try {
			String cronExpressionString = &quot;0 30 15 &quot; + dayOfMonth + &quot; * ?&quot;;
			CronExpression cron = new CronExpression(cronExpressionString);

			CronTrigger trigger = new CronTrigger();
			trigger.setName(jobName + &quot;-Trigger&quot;);
			trigger.setGroup(jobGroup + &quot;-TriggerGroup&quot;);
			trigger.setCronExpression(cron);
			trigger.setStartTime(new Date());
			trigger.setVolatility(false);
			scheduler.scheduleJob(job, trigger);
			logger.info(&quot;Job &quot; + jobName + &quot; scheduled successfully&quot;);
			logger.info(trigger.getNextFireTime().toString());

			// Register additional triggers for special cases
			// In the case of monthly recurrence pattern, if the day of month
			// selected is 29, 30 or 31 special care has to be taken
			switch (dayOfMonth) {
			case 29:
				if (!cal.isLeapYear(year)) {
					trigger1 = new CronTrigger();
					trigger1.setName(jobName + &quot;-Trigger1&quot;);
					trigger1.setGroup(jobGroup + &quot;-TriggerGroup&quot;);
					CronExpression cron1 = new CronExpression(&quot;0 30 15 L FEB ?&quot;);
					trigger1.setCronExpression(cron1);
					trigger1.setStartTime(new Date());
					trigger1.setJobName(jobName);
					trigger1.setJobGroup(jobGroup);
					trigger1.setVolatility(false);
					scheduler.scheduleJob(trigger1);
				}
				break;

			case 30:
				trigger1 = new CronTrigger();
				trigger1.setName(jobName + &quot;-Trigger1&quot;);
				trigger1.setGroup(jobGroup + &quot;-TriggerGroup&quot;);
				trigger1.setCronExpression(&quot;0 30 15 L FEB ?&quot;);
				trigger1.setStartTime(new Date());
				trigger1.setJobName(jobName);
				trigger1.setJobGroup(jobGroup);
				trigger1.setVolatility(false);
				scheduler.scheduleJob(trigger1);
				break;

			case 31:
				trigger1 = new CronTrigger();
				trigger1.setName(jobName + &quot;-Trigger1&quot;);
				trigger1.setGroup(jobGroup + &quot;-TriggerGroup&quot;);
				trigger1.setCronExpression(&quot;0 30 15 L FEB,SEP,APR,JUN,NOV ?&quot;);
				trigger1.setStartTime(new Date());
				trigger1.setJobName(jobName);
				trigger1.setJobGroup(jobGroup);
				scheduler.scheduleJob(trigger1);// This is how we add additional
												// triggers to an existing job
			}
		} catch (ParseException ex) {
			logger.error(&quot;Failed to schedule Job &quot; + jobName
					+ &quot; because of errors in the Cron Expression&quot;);
			return;
		} catch (SchedulerException exc) {
			logger.error(&quot;Failed to schedule Job &quot; + jobName);
		}
	}
}

</pre></p>
<p>And the corresponding Quartz properties file to customize the scheduler:</p>
<p><pre class="brush: java;">
#Scheduler
org.quartz.scheduler.instanceName = JOBSTORETX_SCHEDULER
org.quartz.scheduler.instanceID = AUTO

#ThreadPool
org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 24
org.quartz.threadPool.threadPriority = 5

#JobStore
org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.PostgreSQLDelegate
org.quartz.jobStore.useProperties = false #PostgreSQL 9.0
org.quartz.jobStore.dataSource = myDS
org.quartz.jobStore.tablePrefix = QRTZ_
org.quartz.jobStore.misfireThreshold = 120000
org.quartz.jobStore.maxMisfiresToHandleAtATime = 20
org.quartz.jobStore.dontSetAutoCommitFalse = false
org.quartz.jobStore.selectWithLockSQL = SELECT * from {0}LOCKS where LOCK_NAME=? FOR UPDATE
org.quartz.jobStore.txIsolationLevelSerializable = true

#DataSource
org.quartz.dataSource.myDS.driver = org.postgresql.Driver
org.quartz.dataSource.myDS.URL = jdbc:postgresql://localhost:2377/mydatasource
org.quartz.dataSource.myDS.user =evapa_system
org.quartz.dataSource.myDS.password =password
org.quartz.dataSource.myDS.maxConnections = 25
</pre></p>
<p>As can be seen in the properties file above, I have used the JobStoreTX class for persistence and pointed it to a <strong>DataSource </strong>with the URL <strong>jdbc:postgresql://localhost:2377/mydatasource</strong>. All seems about right at this stage. The code for the job that I am using is shown below for completion:</p>
<p><pre class="brush: java;">
package com.z0ltan.scheduling.prototype.test.job.stateful;

import java.util.Date;
import java.util.logging.Logger;

import org.quartz.JobDetail;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.StatefulJob;
import org.quartz.Trigger;

public class StatefulLogTimeJob implements StatefulJob {
	private static final Logger logger = Logger.getLogger(&quot;StatefulLogTimeJob&quot;);

	public void execute(JobExecutionContext context)
			throws JobExecutionException {
		JobDetail jobDetail = context.getJobDetail();
		Trigger trigger = context.getTrigger();

		String jobName = jobDetail.getName();
		String triggerName = trigger.getName();
		String triggerGroup = trigger.getGroup();
		int iterCount = jobDetail.getJobDataMap().getInt(&quot;ITER_COUNT&quot;);
		int noOfOccurrences = jobDetail.getJobDataMap().getInt(
				&quot;NO_OF_OCCURRENCES&quot;);

		if (iterCount &gt;= (noOfOccurrences + 1)) { // Since the first iteration
													// starts from 1 and not 0
			logger.info(&quot;Job &quot;
					+ jobName
					+ &quot; has been stopped since it has reached the maximum no. of executions.&quot;);
			logger.info(&quot;Removing trigger for &quot; + jobName
					+ &quot; from the Scheduler&quot;);

			Scheduler scheduler = context.getScheduler();

			if (scheduler != null) {
				try {
					scheduler.unscheduleJob(triggerName, triggerGroup);
				} catch (SchedulerException ex) {
					throw new JobExecutionException(ex, false); // do not
																// restart job
				}
			}
			return;
		}

		logger.info(&quot;Starting execution of Job &quot; + jobName + &quot; Iteration &quot;
				+ iterCount);
		logger.info(&quot;\tCurrent Time = &quot; + new Date());
		logger.info(&quot;Finished execution of Job &quot; + jobName + &quot; Iteration &quot;
				+ iterCount);
		jobDetail.getJobDataMap().put(&quot;ITER_COUNT&quot;, (iterCount + 1));
	}
}
</pre></p>
<p>I start the scheduler and it hums along nicely. The job and the trigger are getting stored in the tables and I can see them in pgAdminIII. Then when I try to add the second trigger to the already scheduled job, as done in the line of code shown below,</p>
<p><pre class="brush: java; first-line: 133; highlight: [133];">
scheduler.scheduleJob(trigger1);
</pre></p>
<p>The whole scheduler comes crashing with the following exception message:</p>
<p><strong>org.quartz.JobPersistenceException: Couldn&#8217;t store trigger &#8216;StatefulLogTimeJob-Trigger1&#8242; for &#8216;StatefulLogTimeJob&#8217; job:invalid stream header: BB656430 [See nested exception: java.io.StreamCorruptedException: invalid stream header: BB656430]<br />
</strong></p>
<p>What I did then is attach the source code for the Quartz JAR file (quartz-1.8.3.jar) and start debugging the whole code flow. As could be seen in the properties file, the scheduler is configured to use the <strong>PostgreSQLDelegate </strong>class that comes bundled with Quartz as the delegate class to handle database transactions peculiar to PostgreSQL. As I was debugging, I found out the issue occurs when the scheduler tries to add the additional trigger because the scheduler is unable to retrieve the job details from the database! It was a simple Serialization issue. Still, I was stuck with no resolution in hand. I tried the <strong>StdJDBCDelegate </strong>class but no luck there either. At last I realized that perhaps the issue was with the PostgreSQL server itself. And boy was I right! A little intuitive poking around the <a href="http://www.postgresql.org/docs/9.0/static/datatype-binary.html">PostgreSQL documentation</a> for the <strong>bytea </strong>datatype (the datatype used for binary strings or blobs in common parlance) revealed a gory picture – the documentation blatantly claimed that PostgreSQL 9.0 had changed the default behavior of the bytea datatype to <strong>hex </strong>format, which earlier versions of PostgreSQL do not support (they use the ‘<strong>escape format</strong>’ instead). This was still alright but the clincher is that they allow hex or escape formats while inserting into the database but return only hex by default while retrieving from the same table! Whoa, Nelly. So I jumped up and checked the project settings in Eclipse:<br />
<a href="http://z0ltan.files.wordpress.com/2012/01/java_build_path_original.jpg"><img class="aligncenter size-full wp-image-165" title="Java_Build_Path_Original" src="http://z0ltan.files.wordpress.com/2012/01/java_build_path_original.jpg?w=700&#038;h=506" alt="" width="700" height="506" /></a></p>
<p>Et voila! There was the issue – the project was configured to use an older version of PostgreSQL JDBC driver (<strong>postgresql-8.4-701.jdbc4</strong>) whereas the correct version would be <strong>postgresql-9.0-802.jdbc4</strong> (or above as I found out by experimentation). So how was the rest of the project code working fine till now? Simple – none of the tables actually persisted Serializable objects. However, for Quartz, since a job is represented by the <strong>JobDetail </strong>class which itself has a Serializable component – <strong>JobDataMap </strong>the Quartz job retrieval code would always fail since it was trying to deserialize the binary stream retrieved from the qrtz_job_details table into a JobDataMap object. This exquisitely explains the weird error message shown before. Whew! So the fix was ultimately as simple as updating the PostgreSQL JDBC database driver to the correct version!<br />
In conclusion, it is imperative to ensure that any updates on existing projects (in this case, the project had been updated to use PostgreSQL 9.0.1 from PostgreSQL 8.4) should also have updates for all ancillary and related libraries, environment properties and other software dependencies. Also, PostgreSQL sucks. Heh.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/z0ltan.wordpress.com/158/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/z0ltan.wordpress.com/158/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/z0ltan.wordpress.com/158/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/z0ltan.wordpress.com/158/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/z0ltan.wordpress.com/158/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/z0ltan.wordpress.com/158/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/z0ltan.wordpress.com/158/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/z0ltan.wordpress.com/158/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/z0ltan.wordpress.com/158/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/z0ltan.wordpress.com/158/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/z0ltan.wordpress.com/158/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/z0ltan.wordpress.com/158/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/z0ltan.wordpress.com/158/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/z0ltan.wordpress.com/158/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=z0ltan.wordpress.com&amp;blog=3901691&amp;post=158&amp;subd=z0ltan&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://z0ltan.wordpress.com/2012/01/04/serialization-issues-with-quartz-and-postgresql-invalid-header-stream/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/50c8ab7cc3d29321eb4fc1f7db23d8ea?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">z0ltan</media:title>
		</media:content>

		<media:content url="http://z0ltan.files.wordpress.com/2012/01/java_build_path_original.jpg" medium="image">
			<media:title type="html">Java_Build_Path_Original</media:title>
		</media:content>
	</item>
		<item>
		<title>Adding users to a PostgreSQL server</title>
		<link>http://z0ltan.wordpress.com/2011/12/27/adding-users-to-a-postgresql-server/</link>
		<comments>http://z0ltan.wordpress.com/2011/12/27/adding-users-to-a-postgresql-server/#comments</comments>
		<pubDate>Tue, 27 Dec 2011 09:35:38 +0000</pubDate>
		<dc:creator>z0ltan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://z0ltan.wordpress.com/?p=144</guid>
		<description><![CDATA[Recently one of my colleagues faced a simple and yet interesting problem. He was trying to install a new PostgreSQL database (version 9.0.1-1). The problem was that the original Postgresql DBMS was intended to be installed as part of another software package and the installer for that software package automatically did all the pre-configuration necessary [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=z0ltan.wordpress.com&amp;blog=3901691&amp;post=144&amp;subd=z0ltan&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Recently one of my colleagues faced a simple and yet interesting problem. He was trying to install a new PostgreSQL database (version 9.0.1-1). The problem was that the original Postgresql DBMS was intended to be installed as part of another software package and the installer for that software package automatically did all the pre-configuration necessary in terms of users, roles, database et al. However he already had a debug environment setup on his machine and wanted to install the DBMS as a separate package.</p>
<p>Consider for instance that the user that the specific PostgreSQL instance that the software package installed is &#8216;<strong>username</strong>&#8216; with password &#8216;<strong>password</strong>&#8216;. The database that the software package created had this user as the owner and required the same credentials for the application to access this database. Now, the PostgreSQL installer does not give an option to configure additional users (aside from the default &#8216;postgres&#8217; account) during installation. This was a source of confusion since after installation, there was no option from pgAdminIII to configure any new users! We tried to create a new entry in the <strong>pgpass.conf</strong> file by opening it via pgAdminIII and adding a new entry with &#8216;username&#8217; and &#8216;password&#8217; as the credentials. This, of course, did not work. This was fine but the irksome bit was that the error message was quite misleading, as can be seen below:</p>
<p><a href="http://z0ltan.files.wordpress.com/2011/12/new_server_postgresql.jpg"><img src="http://z0ltan.files.wordpress.com/2011/12/new_server_postgresql.jpg?w=700" alt="" title="new_server_postgresql"   class="aligncenter size-full wp-image-154" /></a></p>
<p><a href="http://z0ltan.files.wordpress.com/2011/12/error_message_postgresql.jpg"><img src="http://z0ltan.files.wordpress.com/2011/12/error_message_postgresql.jpg?w=700" alt="" title="error_message_postgresql"   class="aligncenter size-full wp-image-149" /></a></p>
<p>So I did a bit of research into the PostgreSQL documentation and found that I could add a new user only via a tool called &#8216;<strong>createuser.exe</strong>&#8216; (on Windows). The documentation did not specify that clearly and only mentioned &#8216;CREATEUSER&#8217; as a command with some options that could be used to assign different privileges to the new role. My first thought was that this could be achieved on the <strong>psql.exe</strong> command shell but that was a total dud! Quite expectedly so indeed. It was only when I checked the contents of the bin folder that I discovered the &#8216;<strong>createuser.exe</strong>&#8216; tool! Long story short, here&#8217;s how you add a new user with superuser privileges to your PostgreSQL server (note: this was checked on PostgreSQL 9.0.1-1 but this should work with at least as far back as PostgreSQL 8.3):</p>
<p><a href="http://z0ltan.files.wordpress.com/2011/12/createuser_postgresql.jpg"><img src="http://z0ltan.files.wordpress.com/2011/12/createuser_postgresql.jpg?w=700" alt="" title="createuser_postgresql"   class="aligncenter size-full wp-image-151" /></a></p>
<p><a href="http://z0ltan.files.wordpress.com/2011/12/createuser_invoke_postgresql.jpg"><img src="http://z0ltan.files.wordpress.com/2011/12/createuser_invoke_postgresql.jpg?w=700&#038;h=335" alt="" title="createuser_invoke_postgresql" width="700" height="335" class="aligncenter size-full wp-image-152" /></a></p>
<p>with the options explained as follows:</p>
<p><strong>-d</strong> informs PostgreSQL to allow the new user to be able to create new databases<br />
<strong>-s</strong> informs PostgreSQL to assign superuser privileges to the new user<br />
<strong>-P</strong> intimates PostgreSQL that the new user should have a password, which will be supplied by the user</p>
<p>The following options are for the PostgreSQL server itself:</p>
<p><strong>-h </strong>provides the hostname of the PostgreSQL server<br />
<strong>-U </strong>provides the username of the PostgreSQL server (default user &#8216;postgres&#8217; is used here)<br />
<strong>-p</strong> supplies the port on which the PostgreSQL server is listening<br />
<strong>-W</strong> intimates PostgreSQL that it must use the supplied password (for the default user &#8216;postgres&#8217; to connect to the server)</p>
<p>Et voila! The database is now installed beautifully and works like a charm:</p>
<p><a href="http://z0ltan.files.wordpress.com/2011/12/testdb_created_postgresql.jpg"><img src="http://z0ltan.files.wordpress.com/2011/12/testdb_created_postgresql.jpg?w=700" alt="" title="testdb_created_postgresql"   class="aligncenter size-full wp-image-153" /></a></p>
<p>And the properties of the server (and correspondingly the database within it) also shows the new user as the owner of the server instance:</p>
<p><a href="http://z0ltan.files.wordpress.com/2011/12/testdb_properties.jpg"><img src="http://z0ltan.files.wordpress.com/2011/12/testdb_properties.jpg?w=700" alt="" title="testdb_properties"   class="aligncenter size-full wp-image-155" /></a></p>
<p>The takeaway from this exercise is that the PostgreSQL documentation sucks but given enough time, patience and mental acuity, we can yet tame this free and solid quality beast.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/z0ltan.wordpress.com/144/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/z0ltan.wordpress.com/144/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/z0ltan.wordpress.com/144/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/z0ltan.wordpress.com/144/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/z0ltan.wordpress.com/144/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/z0ltan.wordpress.com/144/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/z0ltan.wordpress.com/144/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/z0ltan.wordpress.com/144/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/z0ltan.wordpress.com/144/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/z0ltan.wordpress.com/144/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/z0ltan.wordpress.com/144/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/z0ltan.wordpress.com/144/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/z0ltan.wordpress.com/144/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/z0ltan.wordpress.com/144/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=z0ltan.wordpress.com&amp;blog=3901691&amp;post=144&amp;subd=z0ltan&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://z0ltan.wordpress.com/2011/12/27/adding-users-to-a-postgresql-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/50c8ab7cc3d29321eb4fc1f7db23d8ea?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">z0ltan</media:title>
		</media:content>

		<media:content url="http://z0ltan.files.wordpress.com/2011/12/new_server_postgresql.jpg" medium="image">
			<media:title type="html">new_server_postgresql</media:title>
		</media:content>

		<media:content url="http://z0ltan.files.wordpress.com/2011/12/error_message_postgresql.jpg" medium="image">
			<media:title type="html">error_message_postgresql</media:title>
		</media:content>

		<media:content url="http://z0ltan.files.wordpress.com/2011/12/createuser_postgresql.jpg" medium="image">
			<media:title type="html">createuser_postgresql</media:title>
		</media:content>

		<media:content url="http://z0ltan.files.wordpress.com/2011/12/createuser_invoke_postgresql.jpg" medium="image">
			<media:title type="html">createuser_invoke_postgresql</media:title>
		</media:content>

		<media:content url="http://z0ltan.files.wordpress.com/2011/12/testdb_created_postgresql.jpg" medium="image">
			<media:title type="html">testdb_created_postgresql</media:title>
		</media:content>

		<media:content url="http://z0ltan.files.wordpress.com/2011/12/testdb_properties.jpg" medium="image">
			<media:title type="html">testdb_properties</media:title>
		</media:content>
	</item>
		<item>
		<title>Nifty little Christmas easter egg in VLC Player</title>
		<link>http://z0ltan.wordpress.com/2011/12/25/nifty-little-christmas-easter-egg-in-vlc-player/</link>
		<comments>http://z0ltan.wordpress.com/2011/12/25/nifty-little-christmas-easter-egg-in-vlc-player/#comments</comments>
		<pubDate>Sun, 25 Dec 2011 12:12:00 +0000</pubDate>
		<dc:creator>z0ltan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://z0ltan.wordpress.com/?p=139</guid>
		<description><![CDATA[I have been using VLC player for years now and I just noticed today (Christmas Day) that the VLC icon was a little different! Apparently VLC player has a nice easter egg in that the VLC icon at the top left corner of the player changes to the original one capped by a cute Santa [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=z0ltan.wordpress.com&amp;blog=3901691&amp;post=139&amp;subd=z0ltan&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I have been using VLC player for years now and I just noticed today (Christmas Day) that the VLC icon was a little different! Apparently VLC player has a nice easter egg in that the VLC icon at the top left corner of the player changes to the original one capped by a cute Santa hat!</p>
<p><a href="http://z0ltan.files.wordpress.com/2011/12/vlc_christmas_icon.jpg"><img src="http://z0ltan.files.wordpress.com/2011/12/vlc_christmas_icon.jpg?w=700&#038;h=239" alt="" title="VLC_Christmas_Icon" width="700" height="239" class="aligncenter size-full wp-image-140" /></a></p>
<p>How very germane of VLC! <img src='http://s0.wp.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /><br />
(I am using VLC player 0.9.8a Grishenko).</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/z0ltan.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/z0ltan.wordpress.com/139/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/z0ltan.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/z0ltan.wordpress.com/139/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/z0ltan.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/z0ltan.wordpress.com/139/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/z0ltan.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/z0ltan.wordpress.com/139/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/z0ltan.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/z0ltan.wordpress.com/139/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/z0ltan.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/z0ltan.wordpress.com/139/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/z0ltan.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/z0ltan.wordpress.com/139/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=z0ltan.wordpress.com&amp;blog=3901691&amp;post=139&amp;subd=z0ltan&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://z0ltan.wordpress.com/2011/12/25/nifty-little-christmas-easter-egg-in-vlc-player/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/50c8ab7cc3d29321eb4fc1f7db23d8ea?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">z0ltan</media:title>
		</media:content>

		<media:content url="http://z0ltan.files.wordpress.com/2011/12/vlc_christmas_icon.jpg" medium="image">
			<media:title type="html">VLC_Christmas_Icon</media:title>
		</media:content>
	</item>
		<item>
		<title>Changing the encoding in Eclipse to UTF-8 &#8211; howto</title>
		<link>http://z0ltan.wordpress.com/2011/12/25/changing-the-encoding-in-eclipse-to-utf-8-howto/</link>
		<comments>http://z0ltan.wordpress.com/2011/12/25/changing-the-encoding-in-eclipse-to-utf-8-howto/#comments</comments>
		<pubDate>Sun, 25 Dec 2011 11:59:38 +0000</pubDate>
		<dc:creator>z0ltan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://z0ltan.wordpress.com/?p=126</guid>
		<description><![CDATA[Eclipse on Windows chugs along fine with its default encoding of Cp1252 (Cp1252 is basically a superset of the ISO-8859-1 encoding scheme, read more here) till we reach the world of unicode. And then it crashes and burns &#8211; horribly. Arguably, the most popular and useful encoding in the programming world today is the UTF-8 [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=z0ltan.wordpress.com&amp;blog=3901691&amp;post=126&amp;subd=z0ltan&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Eclipse on Windows chugs along fine with its default encoding of Cp1252 (Cp1252 is basically a superset of the ISO-8859-1 encoding scheme, read more <a href="http://en.wikipedia.org/wiki/Windows-1252">here</a>) till we reach the world of unicode. And then it crashes and burns &#8211; horribly. Arguably, the most popular and useful encoding in the programming world today is the <a href="http://en.wikipedia.org/wiki/UTF-8">UTF-8</a> encoding scheme well at least in the Web world. It is still baffling as to why Eclipse continues to have Cp1252 as its default encoding mechanism and make changing to UTF-8 such a pain! In fact there is even a bug with a very long interesting discussion on the same &#8211; <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=108668">Eclipse default encoding bug</a>.</p>
<p>Even though the discussion in the bug history argues about &#8216;compatibility&#8217; issues being the main concern dissuading the Eclipse team from shifting to UTF-8 as the default, most of us would still like to work in UTF-8. Changing to UTF-8 encoding is simple in Eclipse but is extremely buggy and the random unpredictable behavior can be really irksome. In most cases, one or more of the following changes should suffice. If you are still getting an error while changing the encoding scheme, the best bet would be to close the workspace and restart the IDE! Seriously, no kidding.</p>
<p>I am using Eclipse Galileo as the base IDE but these steps should work on most version of Eclipse with minor differences (by the way, I am using the JAVA EE version).</p>
<p>For all the various options mentioned below, the first step is to traverse to the settings page as</p>
<p><strong>Windows -&gt; Preferences</strong></p>
<p>1. Changing the entire workspace&#8217;s encoding scheme:</p>
<p><a href="http://z0ltan.files.wordpress.com/2011/12/eclipse_galileo_encoding_workspace.jpg"><img src="http://z0ltan.files.wordpress.com/2011/12/eclipse_galileo_encoding_workspace.jpg?w=300" alt="" title="Eclipse_Galileo_Encoding_Workspace" width="300" height="300" class="aligncenter size-full wp-image-127" /></a></p>
<p>2. Changing the Text Editor&#8217;s encoding scheme (also works for the Java editor):</p>
<p><a href="http://z0ltan.files.wordpress.com/2011/12/eclipse_galileo_encoding_general.jpg"><img src="http://z0ltan.files.wordpress.com/2011/12/eclipse_galileo_encoding_general.jpg?w=300" alt="" title="Eclipse_Galileo_Encoding_General" width="300" height="268" class="aligncenter size-full wp-image-128" /></a></p>
<p>3. Changing the CSS editor&#8217;s encoding scheme:<br />
<a href="http://z0ltan.files.wordpress.com/2011/12/eclipse_galileo_encoding_css.jpg"><img src="http://z0ltan.files.wordpress.com/2011/12/eclipse_galileo_encoding_css.jpg?w=300" alt="" title="Eclipse_Galileo_Encoding_CSS" width="300" height="277" class="aligncenter size-full  wp-image-129" /></a></p>
<p>4. Changing the HTML editor&#8217;s encoding scheme:<br />
<a href="http://z0ltan.files.wordpress.com/2011/12/eclipse_galileo_encoding_html.jpg"><img src="http://z0ltan.files.wordpress.com/2011/12/eclipse_galileo_encoding_html.jpg?w=300" alt="" title="Eclipse_Galileo_Encoding_HTML" width="300" height="277" class="aligncenter size-full wp-image-130" /></a></p>
<p>5. Changing the JSP editor&#8217;s encoding scheme:<br />
<a href="http://z0ltan.files.wordpress.com/2011/12/eclipse_galileo_encoding_jsp.jpg"><img src="http://z0ltan.files.wordpress.com/2011/12/eclipse_galileo_encoding_jsp.jpg?w=300" alt="" title="Eclipse_Galileo_Encoding_JSP" width="300" height="272" class="aligncenter size-full  wp-image-131" /></a></p>
<p>And there you go! Now you can start coding in your favorite encoding scheme!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/z0ltan.wordpress.com/126/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/z0ltan.wordpress.com/126/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/z0ltan.wordpress.com/126/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/z0ltan.wordpress.com/126/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/z0ltan.wordpress.com/126/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/z0ltan.wordpress.com/126/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/z0ltan.wordpress.com/126/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/z0ltan.wordpress.com/126/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/z0ltan.wordpress.com/126/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/z0ltan.wordpress.com/126/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/z0ltan.wordpress.com/126/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/z0ltan.wordpress.com/126/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/z0ltan.wordpress.com/126/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/z0ltan.wordpress.com/126/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=z0ltan.wordpress.com&amp;blog=3901691&amp;post=126&amp;subd=z0ltan&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://z0ltan.wordpress.com/2011/12/25/changing-the-encoding-in-eclipse-to-utf-8-howto/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/50c8ab7cc3d29321eb4fc1f7db23d8ea?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">z0ltan</media:title>
		</media:content>

		<media:content url="http://z0ltan.files.wordpress.com/2011/12/eclipse_galileo_encoding_workspace.jpg?w=300" medium="image">
			<media:title type="html">Eclipse_Galileo_Encoding_Workspace</media:title>
		</media:content>

		<media:content url="http://z0ltan.files.wordpress.com/2011/12/eclipse_galileo_encoding_general.jpg?w=300" medium="image">
			<media:title type="html">Eclipse_Galileo_Encoding_General</media:title>
		</media:content>

		<media:content url="http://z0ltan.files.wordpress.com/2011/12/eclipse_galileo_encoding_css.jpg?w=300" medium="image">
			<media:title type="html">Eclipse_Galileo_Encoding_CSS</media:title>
		</media:content>

		<media:content url="http://z0ltan.files.wordpress.com/2011/12/eclipse_galileo_encoding_html.jpg?w=300" medium="image">
			<media:title type="html">Eclipse_Galileo_Encoding_HTML</media:title>
		</media:content>

		<media:content url="http://z0ltan.files.wordpress.com/2011/12/eclipse_galileo_encoding_jsp.jpg?w=300" medium="image">
			<media:title type="html">Eclipse_Galileo_Encoding_JSP</media:title>
		</media:content>
	</item>
		<item>
		<title>Wow, I really must be out of touch &#8211; wordpress source code highlighting feature</title>
		<link>http://z0ltan.wordpress.com/2011/12/18/wow-i-really-must-be-out-of-touch-wordpress-source-code-highlighting-feature/</link>
		<comments>http://z0ltan.wordpress.com/2011/12/18/wow-i-really-must-be-out-of-touch-wordpress-source-code-highlighting-feature/#comments</comments>
		<pubDate>Sun, 18 Dec 2011 16:25:25 +0000</pubDate>
		<dc:creator>z0ltan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://z0ltan.wordpress.com/?p=121</guid>
		<description><![CDATA[I just got done with my previous blog and then I realized, as always, WordPress seemed not to like my source code and was chunking off arbitrary portions off of it! A little bit of Googling gave me the solution &#8211; simple and elegant and supports a wide range of languages. So now I get [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=z0ltan.wordpress.com&amp;blog=3901691&amp;post=121&amp;subd=z0ltan&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I just got done with my previous blog and then I realized, as always, WordPress seemed not to like my source code and was chunking off arbitrary portions off of it! A little bit of Googling gave me the solution &#8211; simple and elegant and supports a wide range of languages. So now I get not just automatic HTML escaping but also syntax highlighting and a nifty format for the source code display! Here is the link with the details &#8211; <a href="http://en.support.wordpress.com/code/posting-source-code/" title="">WordPress Source Code Highlighting support</a>.</p>
<p>I guess I need to make out some time to update my previous blogs now. It&#8217;s well worth it.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/z0ltan.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/z0ltan.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/z0ltan.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/z0ltan.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/z0ltan.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/z0ltan.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/z0ltan.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/z0ltan.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/z0ltan.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/z0ltan.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/z0ltan.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/z0ltan.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/z0ltan.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/z0ltan.wordpress.com/121/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=z0ltan.wordpress.com&amp;blog=3901691&amp;post=121&amp;subd=z0ltan&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://z0ltan.wordpress.com/2011/12/18/wow-i-really-must-be-out-of-touch-wordpress-source-code-highlighting-feature/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/50c8ab7cc3d29321eb4fc1f7db23d8ea?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">z0ltan</media:title>
		</media:content>
	</item>
		<item>
		<title>Java&#8217;s HttpURLConnection is broken!</title>
		<link>http://z0ltan.wordpress.com/2011/12/18/javas-httpurlconnection-is-broken/</link>
		<comments>http://z0ltan.wordpress.com/2011/12/18/javas-httpurlconnection-is-broken/#comments</comments>
		<pubDate>Sun, 18 Dec 2011 16:09:33 +0000</pubDate>
		<dc:creator>z0ltan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://z0ltan.wordpress.com/?p=102</guid>
		<description><![CDATA[Continuing from the last post, I was experimenting on some prototypes for attaching documents (PDF, CSV, XML etc.) using the JavaMail 1.4 API. The basic modus operandi of the whole process is quite simple: 1. Obtain the URL of the document as served out by Tomcat server. 2. Use this URL as the DataSource for [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=z0ltan.wordpress.com&amp;blog=3901691&amp;post=102&amp;subd=z0ltan&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Continuing from the last post, I was experimenting on some prototypes for attaching documents (PDF, CSV, XML etc.) using the <strong>JavaMail 1.4</strong> API. The basic modus operandi of the whole process is quite simple:</p>
<p>1. Obtain the URL of the document as served out by Tomcat server.</p>
<p>2. Use this URL as the DataSource for the JavaMail API.</p>
<p>3. Munge the URL for the file name and insert the URL as a link in the message body and, finally</p>
<p>4. Attach the document (if below the user-configured attachment limit) to the mail and e-mail it to the recipients.</p>
<p>All in all pretty simple, right? Wrong. The code was working smoothly until the document was either UTF-8 encoded and/or the document name contained white-spaces as well as a smorgasbord of other characters (as allowed by the Windows file system) such as the tilde character(~) or the backquote character (`) or even something such as the addition symbol (+). This caused the whole mechanism to come crashing down&#8230;and bad! This interesting development led me to a whole afternoon of researching and hacking which was quite tiring but enjoyable. I can honestly say that I learnt more about encoding and the way Java&#8217;s API&#8217;s conform (or not) to the standards, through this simple error, than I could have by devouring the RFC&#8217;s and API documentation!</p>
<p>So, first off, the problem description -</p>
<p>1. The URI specification (which is basically a superset of the URL specification) is drafted in a variety of RFC&#8217;s &#8211; RFC 2396, 3986, 5785 et al. However, most modern browsers conform to the new IRI (Internationalized Resource Identifiers) as specified by <a href="http://www.ietf.org/rfc/rfc3987.txt">RFC 3987</a>. This means that a whole variety of previously disallowed characters are now kosher for URI&#8217;s/URL&#8217;s/IRI&#8217;s. However, Java has failed to keep up with the trend and their IRI support is broken. See. This opens a whole can of worms.</p>
<p>2. In my code, the main &#8220;context path&#8221; of the URL that my module receives for a specified document is basically localized/internationalized. For instance, consider as URL of the form:</p>
<p><strong>http://localhost:9999/examples/servlets/`~!@^()_-+={[ }] &#8216;,. test 1 サンプルファイル 999.CSV.PDF</strong></p>
<p>In the URL above, the context portion is &#8220;http://localhost:9999/examples/servlets/&#8221;. So I just had to resolve the encoding problems with the file name portion (i.e., &#8220;`~!@^()_-+={[ }] &#8216;,. test 1 サンプルファイル 999.CSV.PDF&#8221;). In this respect, a variety of tools are purportedly provided by the JDK suite itself &#8211; URLEncoder, URI and the URL class. For instance, the following were the options that I tried, in order:</p>
<p>a). Use the <strong>java.net.URLEncoder</strong> class&#8217; <strong>encode(String s, String enc)</strong> method to try and encode the complete URL. Bad idea. For the sample URL above, it returns a wholly encoded form as follows:</p>
<p><strong>http%3A%2F%2Flocalhost%3A9999%2Fexamples%2Fservlets%2F%60%7E%21%40%5E%28%29_-%2B%3D%7B%5B+++%7D%5D+%27%2C.+test+1+%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AB%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB++++++999.CSV.PDF</strong></p>
<p>Whoa! This cannot be parsed by either the browser or by JavaMail&#8217;s <strong>URLDataSource</strong> handler (or even by JDK&#8217;s <strong>HttpURLConnection</strong>/<strong>HttpsURLConnection</strong> classes). Trashed.</p>
<p>b). Okay, so now I just try and encode the filename portion (since the context path is guaranteed by contract to be properly encoded). The output?</p>
<p><strong> http://localhost:9999/examples/servlets/%60%7E%21%40%5E%28%29_-%2B%3D%7B%5B+++%7D%5D+%27%2C.+test+1+%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AB%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB++++++999.CSV.PDF</strong></p>
<p>Hmmm. Slightly better but still completely non-functional as before. At this point, I decided to dig into the JDK source code (using the <a href="http://openjdk.java.net/"><strong>OpenJDK Java 7</strong> codebase</a>). There was the problem! It was basically encoding whitespaces as &#8216;+&#8217; instead of encoding it into &#8216;%20&#8242; as expected. Plus a whole bunch of other characters were being ignored when they should have been encoded. At this point I was almost decided in my mind to implement my own UTF-8 encoder.</p>
<p>c). Upon suggestion by an acquaintance, I decided to try the <strong>java.net.URI</strong> class constructor to generate a proper URI and then invoke the <strong>toURL()</strong> method to obtain a properly encoded URL. Sounds exquisitely standards-conformant but this totally bombed when it encountered UTF-8 characters (though it handled whitespace just fine). Firefox Opera and Opera seemed to like this just fine.The URL generated was not usable by JavaMail&#8217;s URLDataSource handler (or HttpURLConnection/HttpsURLConnection classes). Plus on some e-mail clients (Gmail), the links were pretty much broken and the user would have to manually copy-and-paste the link into the browser to access the document.</p>
<p>The solution?</p>
<p>I implemented a simple UTF-8 encoder which basically encodes every non-alphanumeric character into UTF-8, shown belowpackage com.z0ltan.mail.encoder;</p>
<p><pre class="brush: java;">
package com.z0ltan.mail.encoder;

import java.nio.charset.Charset;

public class MyUTFEncoder {
	private static final String HEX_CHARS = &quot;0123456789ABCDEF&quot;;

	public static String encode(String data) {

		if (data != null) {
			StringBuffer buffer = new StringBuffer();

			byte[] dataBytes = MyUTFEncoder.getUTFBytes(data);

			for (int i = 0; i &lt; dataBytes.length; i++) {
				char c = (char) dataBytes[i];

				if ((c &gt;= 'a' &amp;&amp; c &lt;= 'z')
					|| (c &gt;= 'A' &amp;&amp; c &lt;= 'Z')
					|| (c &gt;= '0' &amp;&amp; c &lt;= '9')) {
					buffer.append(c);
				} else {
					buffer
					 .append('%');
					buffer
					 .append(HEX_CHARS.charAt((c &amp; 0xF0) &gt;&gt; 4));
					buffer
					 .append(HEX_CHARS.charAt((c &amp; 0x0F)));
				}
			}

			return buffer.toString();
		}
		return null;
	}

	private static byte[] getUTFBytes(String data) {
		if (data != null) {
			return data.getBytes(Charset.forName(&quot;UTF-8&quot;));
		}
		return null;
	}
}
</pre></p>
<p>The code is pretty self-explanatory. The URL&#8217;s generated may not be pretty to look at but they are equally liked by the browser, Java&#8217;s URLConnection API&#8217;s, JavaMail&#8217;s URLDataSource handler as well as E-mail clients such as MS Outlook and Gmail (no more broken links, yay!).</p>
<p>For the representative URL shown at the beginning of this blog, the output is as follows:</p>
<p><strong>http://localhost:9999/examples/servlets/%60%7E%21%40%5E%28%29%5F%2D%2B%3D%7B%5B%20%20%20%7D%5D%20%27%2C%2E%20test%201%20%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AB%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB%20%20%20%20%20%20999%2ECSV%2EPDF</strong></p>
<p>Yes, pretty ugly, but in most browsers that I tested it on, the browser automatically displays it in a more user-friendly format (with no encoding). The best part? This URL works well with JDK, JavaMail, e-mail clients as well as the browser! Plus, to rid it of some ugliness, I actually insert the attached document&#8217;s name without the encoding &#8211; such as <strong>`~!@^()_-+={[ }] &#8216;,. test 1 サンプルファイル 999.CSV.PDF</strong>. This saves the user some confusion about the veracity of the attached document (Note: The file name may still be encoded into weird forms by the e-mail client, if not properly configured but that is beyond the purview of my application).</p>
<p>All in all, an afternoon well spent. Slainte!</p>
<p>PostScript</p>
<p><strong>JDK 1.6</strong>, <strong>JavaMail 1.4</strong>, <strong>Firefox 8.0.1</strong>, <strong>IE 7</strong> and <strong>Opera 11.52</strong>, <strong>MS Outlook</strong> and <strong>Gmail client</strong> used for testing.</p>
<p>Now I am poring over the RFC&#8217;s to gain a wholesome understanding of the whole wonderfully twisted domain of encoding/decoding!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/z0ltan.wordpress.com/102/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/z0ltan.wordpress.com/102/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/z0ltan.wordpress.com/102/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/z0ltan.wordpress.com/102/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/z0ltan.wordpress.com/102/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/z0ltan.wordpress.com/102/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/z0ltan.wordpress.com/102/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/z0ltan.wordpress.com/102/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/z0ltan.wordpress.com/102/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/z0ltan.wordpress.com/102/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/z0ltan.wordpress.com/102/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/z0ltan.wordpress.com/102/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/z0ltan.wordpress.com/102/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/z0ltan.wordpress.com/102/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=z0ltan.wordpress.com&amp;blog=3901691&amp;post=102&amp;subd=z0ltan&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://z0ltan.wordpress.com/2011/12/18/javas-httpurlconnection-is-broken/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/50c8ab7cc3d29321eb4fc1f7db23d8ea?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">z0ltan</media:title>
		</media:content>
	</item>
		<item>
		<title>How to read the file size of a document served at an HTTP/S URL using Java</title>
		<link>http://z0ltan.wordpress.com/2011/12/04/how-to-read-the-file-size-of-a-document-served-at-an-https-url-using-java/</link>
		<comments>http://z0ltan.wordpress.com/2011/12/04/how-to-read-the-file-size-of-a-document-served-at-an-https-url-using-java/#comments</comments>
		<pubDate>Sun, 04 Dec 2011 15:05:14 +0000</pubDate>
		<dc:creator>z0ltan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://z0ltan.wordpress.com/?p=88</guid>
		<description><![CDATA[Recently I was assigned some work where I had to read reports from a custom HTTP (development) or HTTPS (production) URL and e-mail them accordingly, attaching the report to the e-mail if it did not exceed the user configured maximum SMTP attachment size. The problem I had was that even though the reports were actually [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=z0ltan.wordpress.com&amp;blog=3901691&amp;post=88&amp;subd=z0ltan&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Recently I was assigned some work where I had to read reports from a custom HTTP (development) or HTTPS (production) URL and e-mail them accordingly, attaching the report to the e-mail if it did not exceed the user configured maximum SMTP attachment size.</p>
<p>The problem I had was that even though the reports were actually stored on the web server&#8217;s local file system, I did not have access or permission to access the reports from the file system. All I had was the web URL of the report document. Thus I had no choice but to read the file size somehow from the URL , check it against the configured maximum SMTP attachment size and then e-mail the report. The prototype that I developed is posted at this location &#8211; <a href="http://pastebin.com/KnsUuAhG">http://pastebin.com/KnsUuAhG</a></p>
<p>As can be seen, I have used JavaMail for the actual e-mail dispatch. The interesting bit is in the<em> isAttachmentSmallerThanMaxSmtpSize</em>  method:</p>
<pre>private static boolean isAttachmentSmallerThanMaxSmtpSize(
                        String attachmentLink) {
                boolean status = false;

                try {
                        HttpURLConnection connection = (HttpURLConnection) new URL(
                                        attachmentLink).openConnection();
                        int sizeInMB = connection.getContentLength() / (1024 * 1024);

                        if (sizeInMB &gt; MAX_SMTP_SIZE) {
                                status = false;
                        } else {
                                status = true;
                        }

                } catch (Exception ex) {
                        status = false;
                }

                return status;
        }</pre>
<p>where the actual file size can be obtained by simply obtaining the content length of the HTTP (or HTTPS) Connection object.</p>
<p>For my prototype, for HTTPS connections, I actually disabled the HTTPS certificate check by using the method described in this nifty blog: <a href="http://www.nakov.com/blog/2009/07/16/disable-certificate-validation-in-java-ssl-connections/">http://www.nakov.com/blog/2009/07/16/disable-certificate-validation-in-java-ssl-connections/</a>. In actual production use, however, HTTPS URLs are handled by using the actual certificates installed with the product.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/z0ltan.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/z0ltan.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/z0ltan.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/z0ltan.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/z0ltan.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/z0ltan.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/z0ltan.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/z0ltan.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/z0ltan.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/z0ltan.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/z0ltan.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/z0ltan.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/z0ltan.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/z0ltan.wordpress.com/88/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=z0ltan.wordpress.com&amp;blog=3901691&amp;post=88&amp;subd=z0ltan&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://z0ltan.wordpress.com/2011/12/04/how-to-read-the-file-size-of-a-document-served-at-an-https-url-using-java/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/50c8ab7cc3d29321eb4fc1f7db23d8ea?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">z0ltan</media:title>
		</media:content>
	</item>
		<item>
		<title>SICP Saga &#8211; 0</title>
		<link>http://z0ltan.wordpress.com/2009/12/30/sicp-saga-0/</link>
		<comments>http://z0ltan.wordpress.com/2009/12/30/sicp-saga-0/#comments</comments>
		<pubDate>Tue, 29 Dec 2009 20:12:49 +0000</pubDate>
		<dc:creator>z0ltan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[SICP]]></category>

		<guid isPermaLink="false">http://z0ltan.wordpress.com/2009/12/30/sicp-saga-0/</guid>
		<description><![CDATA[Downloaded video lectures. Installed the latest MIT Scheme interpreter. Bookmarked the free online copy of SICP. The agenda is to post my notes and insights as I work through the text and video lectures as well as my solutions to the exercises and assignments listed on the site. Let&#8217;s have some fun!<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=z0ltan.wordpress.com&amp;blog=3901691&amp;post=84&amp;subd=z0ltan&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Downloaded <a href="http://groups.csail.mit.edu/mac/classes/6.001/abelson-sussman-lectures/">video lectures</a>. Installed the latest MIT Scheme interpreter. Bookmarked the free online copy of <a href="http://mitpress.mit.edu/sicp/full-text/book/book.html">SICP</a>. The agenda is to post my notes and insights as I work through the text and video lectures as well as my solutions to the exercises and assignments listed on the site. Let&#8217;s have some fun! <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/z0ltan.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/z0ltan.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/z0ltan.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/z0ltan.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/z0ltan.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/z0ltan.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/z0ltan.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/z0ltan.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/z0ltan.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/z0ltan.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/z0ltan.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/z0ltan.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/z0ltan.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/z0ltan.wordpress.com/84/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=z0ltan.wordpress.com&amp;blog=3901691&amp;post=84&amp;subd=z0ltan&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://z0ltan.wordpress.com/2009/12/30/sicp-saga-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/50c8ab7cc3d29321eb4fc1f7db23d8ea?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">z0ltan</media:title>
		</media:content>
	</item>
		<item>
		<title>Took me almost too long to get this &#8216;un</title>
		<link>http://z0ltan.wordpress.com/2009/12/09/took-me-almost-too-long-to-get-this-un/</link>
		<comments>http://z0ltan.wordpress.com/2009/12/09/took-me-almost-too-long-to-get-this-un/#comments</comments>
		<pubDate>Wed, 09 Dec 2009 10:49:30 +0000</pubDate>
		<dc:creator>z0ltan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://z0ltan.wordpress.com/?p=79</guid>
		<description><![CDATA[This was a &#8216;puzzle&#8217; mailed by a friend today. It almost made me realize that I&#8217;m getting a bit rusty Fill in the lines of xxxxxxxxx so that this program will print Bingo. PS: dont Use printf("bingo") and return 0 int main() { int a,b; xxxxxxxxx xxxxxxxxx xxxxxxxxx if ( a==b) printf("equal"); else if ( [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=z0ltan.wordpress.com&amp;blog=3901691&amp;post=79&amp;subd=z0ltan&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This was a &#8216;puzzle&#8217; mailed by a friend today. It almost made me realize that I&#8217;m getting a bit rusty <img src='http://s0.wp.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<pre>
Fill in the lines of xxxxxxxxx  so that this program will print  Bingo.
PS: dont Use printf("bingo")  and return 0 

int main()
{
        int a,b;

       xxxxxxxxx          

       xxxxxxxxx  

       xxxxxxxxx  

        if ( a==b)
                printf("equal");
        else
                if ( a &gt; b )
                        printf("greater");
                else
                        if( a &lt; b)
                                printf(&quot;less&quot;);
                        else
                                printf(&quot;Bingo&quot;);

        return 0;
}
</pre>
<pre>

My solution:

int main()
{
        int a,b;

        if (a = b)
                printf("Bingo\n");
        else

        if ( a==b)
                printf("equal");
        else
                if ( a &gt; b )
                        printf("greater");
                else
                        if( a &lt; b)
                                printf(&quot;less&quot;);
                        else
                                printf(&quot;Bingo&quot;);

        return 0;
}

 <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />
</pre>
<p>Bejasus!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/z0ltan.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/z0ltan.wordpress.com/79/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/z0ltan.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/z0ltan.wordpress.com/79/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/z0ltan.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/z0ltan.wordpress.com/79/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/z0ltan.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/z0ltan.wordpress.com/79/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/z0ltan.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/z0ltan.wordpress.com/79/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/z0ltan.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/z0ltan.wordpress.com/79/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/z0ltan.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/z0ltan.wordpress.com/79/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=z0ltan.wordpress.com&amp;blog=3901691&amp;post=79&amp;subd=z0ltan&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://z0ltan.wordpress.com/2009/12/09/took-me-almost-too-long-to-get-this-un/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/50c8ab7cc3d29321eb4fc1f7db23d8ea?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">z0ltan</media:title>
		</media:content>
	</item>
		<item>
		<title>Nostalgia&#8230;..and a long awaited comeback</title>
		<link>http://z0ltan.wordpress.com/2009/11/17/nostalgia-and-a-long-awaited-comeback/</link>
		<comments>http://z0ltan.wordpress.com/2009/11/17/nostalgia-and-a-long-awaited-comeback/#comments</comments>
		<pubDate>Tue, 17 Nov 2009 06:39:30 +0000</pubDate>
		<dc:creator>z0ltan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Bored]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[data structures]]></category>

		<guid isPermaLink="false">http://z0ltan.wordpress.com/?p=73</guid>
		<description><![CDATA[Got bored, wanted to test my memory (and latent C skills): #include typedef struct node { char* data; struct node* next; }* NODE; int main() { NODE root = NULL; NODE tail = NULL; root = (NODE) malloc(sizeof(struct node)); tail = (NODE) malloc(sizeof(struct node)); root-&#62;data = "hello"; tail-&#62;data = "world"; root-&#62;next= tail; tail-&#62;next = NULL; [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=z0ltan.wordpress.com&amp;blog=3901691&amp;post=73&amp;subd=z0ltan&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Got bored, wanted to test my memory (and latent C skills):</p>
<pre>
#include 

typedef struct node {
        char* data;
        struct node* next;
}* NODE;

int main()
{

        NODE root = NULL;
        NODE tail = NULL;

        root = (NODE) malloc(sizeof(struct node));
        tail = (NODE) malloc(sizeof(struct node));

        root-&gt;data = "hello";
        tail-&gt;data = "world";

        root-&gt;next= tail;
        tail-&gt;next = NULL;

        // display the contents of the linked list
        NODE cur = root;
        for(;cur != NULL; cur= cur-&gt;next)
        {
                printf("%s ", cur-&gt;data);
        }

        free(root);
        free(tail);

        printf("\n");

        return 0;
}
</pre>
<p>And it worked. First time around. Nice! <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/z0ltan.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/z0ltan.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/z0ltan.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/z0ltan.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/z0ltan.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/z0ltan.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/z0ltan.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/z0ltan.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/z0ltan.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/z0ltan.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/z0ltan.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/z0ltan.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/z0ltan.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/z0ltan.wordpress.com/73/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=z0ltan.wordpress.com&amp;blog=3901691&amp;post=73&amp;subd=z0ltan&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://z0ltan.wordpress.com/2009/11/17/nostalgia-and-a-long-awaited-comeback/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/50c8ab7cc3d29321eb4fc1f7db23d8ea?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">z0ltan</media:title>
		</media:content>
	</item>
	</channel>
</rss>
