Sunday, August 15, 2010

The D language

I'm reading The D Programming Language by Andrei Alexandrescu.

It's very easy to setup the environment in Ubuntu:

1. From the downloads page, get version 2 of the deb package and install.
2. Install Geany editor. It already supports D out of the box. You can compile and build from within the editor.
3. Happy compiling.

Thursday, July 1, 2010

inotify + StringTemplate

I was looking for the equivalent of Dreamweaver templates on Ubuntu. I couldn't find anything that met my needs so I decided to create a workflow that came close.

I have potentially many files that contain xhtml fragments which need to be inserted into one or more templates. That is, I edit a file which when saved results in the creation of a completed html document in some other directory.

I used inotify and inotify-tools to notify when files in my source directory are modified, and StringTemplate for the template engine.

inotify should already exist on Linux. But, you'll need to install inotify-tools:

sudo apt-get install inotify-tools

This script runs in a terminal waiting for edits to happen in the source directory, then calling the groovy script when it does:

#!/bin/bash
inotifywait -m -e modify /path/to/src/directory | while read line;
do
echo "updating file: $line"
groovy /path/to/monitor.groovy
done

The groovy script finds the file with the latest modified timestamp and uses StringTemplate to insert the contents into the template. It ends with writing the new file to the target directory.

def srcDir = new File("/path/to/src")
def targetDir = "/path/to/target/"
def lastModifiedFile = srcDir.listFiles().max{ it.lastModified() }

StringTemplateGroup group = new StringTemplateGroup("myGroup", "/path/to/templates")
StringTemplate query = group.getInstanceOf("template-1")

query.setAttribute "content", lastModifiedFile.text

outFile = new File(targetDir + lastModifiedFile.name)
outFile.write query.toString()

So with two small script files, I end up with a neat workflow that maintains the separation of content and template.

Sunday, June 27, 2010

XHMTL to PDF: wkhtmltopdf

I was looking for a way to create a resume in PDF format without having to use a word processor.

I looked at Latex but I didn't want to learn a new language.

XHTML as the primary document would be ideal; a simple markup language that can be styled with CSS.

I played around with Prince, but it's not free or cheap. Also, with the non-commercial license, Prince will put a logo on the first page of the document.

While trying to find an alternative, I stumbled upon wkhtmltopdf. Wkhtmltopdf uses the QT WebKit widget as the rendering engine to generate PDFs. So, the PDF will look very much like what appears in Chrome or Safari.

I'm using Ubuntu 10.04 and was pleasantly surprised to see wkhtmltopdf in the repositories. However, that version is not the patched version. That is, you won't be able to set header and footer options.

The good news is they provide static binaries of the latest versions. Download, extract and copy the binary into /usr/local/bin/ and you're good to go.

Wednesday, March 17, 2010

Android

So I got an android dev environment setup on Ubuntu 9.10 x64. Very straightforward and no missing packages to install.

The emulator takes awhile to startup. But once it's up, you can deploy/redeploy your apps quickly.

The developer's guide is a good reference. Also reading Hello, Android.

The plan is to eventually get to using Android NDK.

Wednesday, December 30, 2009

GWT MVP article

Here's a good article explaining MVP in GWT applications:

Large scale application development and MVP

Saturday, December 26, 2009

Netbeans 6.8 missing beans.xml

If you want to create a JSF 2 web app using Netbeans 6.8, you'll have to manually create a beans.xml under WEB-INF.

A file with empty tags will do:
<beans></beans>

Sunday, November 29, 2009

Installing Flex Builder 3 with Flex 4 beta in Eclipse 3.5 on Linux

I was curious to see what Flex 4 has to offer so I decided to try installing a development environment on Ubuntu 9.10.

  1. Install Eclipse 3.5 Galileo and Flex Builder for Linux alpha 5.

  2. There's an issue with Eclipse Galileo. Just prepend "path=" to [ECLIPSE_HOME]/links/com.adobe.flexbuilder.feature.core.link.

  3. Apply James Ward's patch (steps 2,3,4,5).

  4. Apply another patch (Stage 2: steps 5,6,7).

At this stage you will have a working Flex 3.x environment and of course without the design view.

To use Flex 4 SDK:

  1. Install Flash Player 10.x.

  2. Download the Flex 4 SDK.

  3. Extract contents to [Linux Flex Builder install directory]/sdks/4.0.0 folder.

  4. In Eclipse, [Window > Preferences > Flex > Installed Flex SDKs] and add 4.0.0 to the list.

  5. In Eclipse, right-click your project, then Properties. Under Flex Compilers, select the Flex 4 SDK and also enter "10.0.0" for "Require Flash Player version".

Almost there. Things will compile but the template file will not be generated under "html-template".

  1. From [Linux Flex Builder install directory]/sdks/4.0.0/templates/swfobject folder, copy /history, index.template.html and swfobject.js files to your project's "html-template" folder.

When running, Flex Builder complains about Flash player 9. Just click through the alerts and the browser will run displaying your app.

Phew!