Monday, December 22, 2008

Publishing to Blogger with Google Docs

When I first started publishing to Blogger, I was extremely disappointed with the WYSIWG editor. Simple tasks such as inserting tables or images take a lot of time and you have to usually wind up writing HTML code to do it right. I have been looking for a better solution to do my blogging.

Google Docs
I recently took Google Docs out for a test drive and was impressed with how easy it was to write rich text documents through a web page. You can easily make format changes, build tables, and insert images. Google Docs also allows you to create presentations and spreadsheets.

Posting to Blogger with Google Docs
While working on a test document, I noticed there is a share button on the top right hand corner of the page. When you click the Share button, there are a couple of options available. If you select Publish as Web Page, you will presented with an option to Post to Blog. There will also be a link there so that you can setup your blog account settings.  Once your Blogger account settings are saved in Google Docs, you can now easily post documents from Google Docs to your Blogger blog. Give it a try, I have been using this setup for a few weeks now and I have to say that it is the best way I have found to create Blogger posts.

Meld: Open Source diff and merge tool for Linux

When I chose to move over to Linux from Windows on my development computer, I had to find an alternative diff and merge tool as I had been using TortoiseSVN for this functionality. That's when I found about Meld and I have been pleasantly surprised by this simple yet powerful diff tool.

Easy Installation

Since Meld is in the Ubuntu package archives, you can easily install it by opening Applications > Add/Remove. When Add/Remove opens, search for Meld and select to install Meld Diff Viewer. From the command line, you can also install Meld through apt with the following command: sudo apt-get install meld



In Place Editing

The main feature that has blown me away with Meld is the capability to edit files while you are comparing them. Not only can you do normal merge operations with files you are comparing, but you can actually edit the files as though they are in a text editor and Meld does realtime comparisons as you do this. This really comes in handy in all sorts of situations.

You can see in the image that while comparing the two files, I decided to throw in some extra text into file2 and it immediately updated the comparison. Of course if I want to move the change over to file1 all I have to do is click the black arrow and it will update file1. This is a very powerful feature and really saves time when you need to be able to make changes in a hurry to multiple files.

Easy Integration with RapidSVN

If you miss the file comparison feature found in TortoiseSVN under Windows, you can setup Meld to be your file comparison tool under RapidSVN in Linux. In RapidSVN, click on View from the menu bar and select Preferences. Once the Preferences Menu opens, click on the Diff Tool tab, type meld in the command text box and click OK. Now when you choose to diff files from within RapidSVN, it will use Meld to compare files.

Integration with Nautilus

For more siplicity, you can setup Nautilus so that Meld shows up in the right-click menu when you select two or more files. In order to do this, you'll need to install the Nautilus Actions Configuration application. Open up Applications > Add/Remove. When Add/Remove opens search for Nautilus Actions Configuration and install it. Once installed, go to System > Preferences > Nautilus Actions Configuration. Once it loads, click the Add button.
  1. Set the Label to Meld. This is the text that will show up when you right click.

  2. Set the Icon to wherever your Meld icon image file is. Mine is located at /usr/share/pixmaps/meld.png.

  3. Set the path to meld

  4. Set the parameters to %M. If you look at the legend, this will pass in a space-separated list of the selected files/folders with their full paths.

  5. Click the Conditions tab.

  6. Set Filenames to * and check the Match Case check box.

  7. Set Mimetypes to */*

  8. Select the Both radio button and check the Appears if selection has multiple files or folders check box under "Appears if selection contains."

  9. Click OK
Now when you select two files in Nautilus and right click, you will have a menu item called Meld that will allow you to compare the files. Nice...

Thursday, December 18, 2008

Pandora for the iPhone

I have been using another awesome app for the iPhone which is Pandora.  It is just like the Pandora Internet Radio in that you type in a band or song name and it builds a radio station around your entry.  You can add radio stations to the app by adding band names and once you have more than one band name, you can do a quick mix which is essentially a mesh of all of the radio stations you have built.  This is a really nice app that makes owning the iPhone even better.  I listen to this while I'm at work, at the gym, or even while I'm just cleaning the house.  It also includes the capability to rate songs that are played so that it can fine tune the types of music you will enjoy.  As the iPhone is the first Apple product I have ever owned, I am definitely not a fanboy, but I may be soon.

How to search for a percent (%) sign in a like query

The percent (%) sign in a SQL LIKE query is used as a wildcard. If you need to look for text containing a percent (%) sign, then you'll have to use an escape character to specify that the SQL database should look for an actual percent sign. The query below is an example of how to do this:
SELECT * FROM my_table WHERE some_column LIKE '%\%%' ESCAPE '\';
The query above defines the backslash as an escape character so that it will search for any row that has a percent sign in some_column.

Wednesday, December 17, 2008

Generate Charts and Graphs in Java Using JFreeChart

I was recently looking for an open source charting and graphing API for Java when I came across JFreeChart. They describe JFreeChart as a free 100% Java chart library that makes it easy for developers to display professional quality charts in their applications.

One of the first things I noticed was that there is very little to no documentation on how to use JFreeChart and I am assuming that is because they sell their Developer's Guide to support the project. While that is definitely a good way to support their project, it makes it hard for people to test out the API. So, hopefully, I can help you get started with using JFreeChart. I strongly encourage purchasing the Developer's Guide if you plan on using JFreeChart in your projects.

A Simple Line Chart
We'll take a look at a simple dataset that would be used in a basic line graph using JFreeChart. Our datasets will represent the number of visitors counted at local parks over a 7 day period.


Park 1
DayNumber of Visitors
110
24
36
412
511
639
733
Park 2
DayNumber of Visitors
123
215
318
45
552
666
783

We are going to create a graph using the dataset above with the JFreeChart API. The sample class below will show how to generate a line graph using the data above.


package org.javaconfessions.sample;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.chart.ChartUtilities;

import java.io.File;
import java.io.FileOutputStream;

class XYChartSample {

public void buildChart() throws Exception {

XYSeriesCollection dataset = new XYSeriesCollection();
XYSeries xySeries = new XYSeries( "Park 1" );
xySeries.add( 1, 10 );
xySeries.add( 2, 4 );
xySeries.add( 3, 6 );
xySeries.add( 4, 12 );
xySeries.add( 5, 11 );
xySeries.add( 6, 29 );
xySeries.add( 7, 33 );

XYSeries xySeries2 = new XYSeries( "Park 2" );
xySeries2.add( 1, 23 );
xySeries2.add( 2, 15 );
xySeries2.add( 3, 18 );
xySeries2.add( 4, 5 );
xySeries2.add( 5, 52 );
xySeries2.add( 6, 66 );
xySeries2.add( 7, 83 );

dataset.addSeries( xySeries );
dataset.addSeries( xySeries2 );

JFreeChart chart = ChartFactory.createXYLineChart( "Park Chart",
"Day",
"# of Visitors",
dataset,
PlotOrientation.VERTICAL,
true,
false,
false );

FileOutputStream out = new FileOutputStream( new File( "parkchart.png" ) );
ChartUtilities.writeChartAsPNG( out, chart, 400, 200 );

}

}
This is just a basic example of how you can generate charts using JFreeChart. You can see at the end I also show an example of another useful feature found in JFreeChart, the capability to write out charts as images. In this example, I wrote out the chart as a PNG file. Here is an example of how that chart would look if you ran the code above.

© 2010 Confessions of a Java Programmer, All Rights Reserved