Tuesday, January 20, 2009

Java on Mac OS X: try Soy Latte

If you are working with Java on OS X then you probably should be trying out SoyLatte. SoyLatte is a port of BSD Java for OS X, it is also part of the OpenJDK initiative. It can help you work around the many issues you'll likely have with the 1.6 Java SDK supported by Apple (I couldn't get Woodstox working with RelaxNG schema support).

First off download it. Then you'll probably want to install it somewhere (/usr/local/soylate-xxx should work). Then make sure you have a JAVA_HOME shell var pointing to this folder. Make sure also you add the bin folder to the path.

Getting Eclipse running on SoyLatte is cake. Open the preferences, select "Java > installed JREs", click the 'add' button select the 'MacOS X VM' option and next. You'll now want to point to the SoyLatte folder and finish things off. Select the SoyLatte JRE and close the preferences.

Last thing I'd like to point out. I use CXF to do web services, and found there was an issue with SoyLatte using JAXB 2.0 when I need JAXB 2.1. To solve this I just downloaded the jaxb-api-2.1.jar and jaxws-api-xx.jar and put them into the soylatte/jre/endorsed folder.

Tuesday, January 13, 2009

Potion: Installing and Running

New to the computer language scene is Potion. This language is the work of Why (or Why the luck stiff if you like typing) a guy who created a wonderful guide to learning the Ruby programming language.

Potion is a very 'small' language in both terms of lines of code to implement and the tools and API of the language itself. Batteries are not included as they are in well established languages such as Python. NO SWEAT, this of course is why you are interested.

First things first you'll need to have Git installed. Git is source control software. I am on Ubuntu and so I just typed in the command 'sudo apt-get install git-core'. That should do it... oh not on Ubuntu well then go here and figure it out.

Second you are going to need Ragel. Ragel is a state machine compiler. Potion uses it to create the source code tokenizer. Again I used apt-get: 'sudo apt-get install ragel' and voila I had myself some Ragel. You might need to go here and download it or something.

Lastly you need the Potion source. Using Git you will download this. You should be able to type
git clone git://github.com/why/potion.git potion
and you'll now have the folder 'potion' containing the sources.

Now you'll want to change to the 'potion' folder. Type 'make' to start the process of building Potion.

Once finished copy the potion executable create in the make step into your local bin folder. For me that is '/home/rob/bin'. Make sure this folder is on the path. Now you can run potion anywhere. test it out using the command 'potion examples/fib.pn'. This will run the simple fibonacci app in the example folder.

Now you are ready to build a great program!

Saturday, January 3, 2009

MySQL and Unicode

I just wanted to point out. MySQL STILL uses ISO-Latin-1 as the default encoding. LAME!!! I ran into again the problem today of having to set up my production database to use UTF-8. Not a difficult thing, but a hassle none the less. The thing is in these days everyone is using UTF-8, I mean i18n and l13n are two big deals. Some web programming frameworks make it a huge point of how well they handle the two.

Well anyway what to do? I had already created the database and tables, in the default ISO-Latin-1 encoding, and there was a few months of data in them. Therefore I had to start by fixing the encoding on the database and tables. Here are the commands that can make this happen:
alter table xxx character set = utf8;
alter database xxx character set = utf8;
Of course insert your table and database names. Now any new tables created in the database will have utf8 encoding. You probably WANT to make sure that everything in your database is UTF-8. The best way I know of doing this is my setting the proper values in the my.cnf file in /etc. If the file is not in /etc then you probably will need to create it. If someone else admins the machine and installed mysql there is a possibility also that the file is in another castle, er sorry location.

So crack open the my.cnf and insert this line:
Thats it, restart MySQL. To test this out create a new database, then a table in the database. Issue the 'show create table xxx' where xxx is the table name, you should see some text indicating it has UTF-8 as the encoding.

URL Encoding in Tomcat

I'm working on a new feature at blueleftistconstructor (BLC) that is sorta like del.icio.us. The gist is this feature allows a member to create 'bookmarks' in their account on the site. Bookmarks can then be accessed from anywhere one can access BLC.

I created a bookmarklet that when invoked from any webpage will redirect to BLC and save the page as a bookmark. This is pretty clutch as it makes bookmarking a lot easier. I coded up this bookmarklet awhile ago but found a bug just the other day. Any site that had a title containing Unicode characters would cause the title to freak out. In the save bookmark form the characters where getting butchered.

Well it took a hour or so to troubleshoot the problem. It ends up that Tomcat (the Java webserver I host the site app in) uses ISO-Latin-1 (ISO-8859-1) when decoding URLs. Well that makes sense of why the Unicode characters where lost. As luck would have it I kinda guessed this was the issue and found this great post. If you are experiencing such issues just follow the directions in the post and you'll be fine.