Thursday, January 19

Q&A For The Week 15 Jan 2012

Some recent research:

How do I import a script file into a Play Framework application?

Documentation 1.2.4

#{script 'jquery-1.4.2.min.js' /}

What's the best way to sort an internal JPA collection?

Sort them in Java, Comparator

List getRegions(){
  sorted = new List(regions);
  Collections.sort(sorted, new RegionComparator(getUserLanguage()));
  return sorted;
}

How to use Java enums in a Play Framework's YAML datafile?

enum value from yaml fixtures

// try just the enum value
// snake YAML can infer the rest...
category: Third

How do I tie into Play's style and script import system?

morestyles and morescripts

#{set 'moreStyles'}
    #{get 'moreStyles' /}
    #{stylesheet 'main.css' /}
#{/set}

Thursday, December 1

Mercurial Case Collisions

I tried to clone an HG repo today and saw this error:
luther$ hg clone Project
updating working directory
abort: case-folding collision between pdf.png and PDF.png
While this could have been caused by a Windows machine I very much doubt it as it is part of an iPhone project. Instead, I'm sure I renamed a file with lowercase 'pdf' and checked it in as this post alludes to. It wasn't too hard to fix - Mercurial walked me through the process here:
On Windows, it is currently (before Mercurial 1.1) possible to introduce case collisions in the repo that prevent you from checking out a repository. One way to repair such a repository is to check it out on a case-sensitive Unix system, remove the problematic file, and commit it again. If that's not possible, you can do the following:
  • hg clone -U repo repair
  • cd repair
  • hg debugsetparents <bad revision>
  • hg debugrebuildstate
At this point, Mercurial will think you have the bad revision checked out and all the files are missing (status '!'). To fix the repo, we simply have to do:
  • hg rm -A <file causing the collision>
Now hg st should show the troublesome file in state 'R' and all other files in state '!'. Now we can check in our fix:
  • hg ci -m "fix case collision"
To get all our files back, we just check out again:
  • hg co tip
Or you can install the CaseFoldExtension and use this:
  • hg up --fold

Wednesday, November 9

The Development Square

Different developers take different approaches to development but here recently, I've create a few new ideas for products and I've settled on something I call the development square.

The first thing I do is generally mock up the interface. This might be in HTML, a graphic design tool or within Interface Builder (Xcode). Whatever the technology, I need to walk through the screens and get a sense for the workflow of the application. I am less concerned about how pretty the app is as much as I'm getting a feel for the function and flow.

The second thing I do is populate that interface dynamically with data from a datastore. This gives me a chance to tweak the database schema to make the UI easy to develop against.

Next, I implement add, edit and delete functionality. This gets tricky since, at times, I don't even have such named buttons or methods in the interface but it really pulls the whole thing together as at this point, the interface becomes a working application.

The final step is to sweeten up the graphics and polish the app as a whole. This leaves me at the final node of my square - which leaves me at the beginning &hellip;

Repeat.

Thursday, September 29

Finding Value in a Formal Directory Structure

While a language like Java generally requires a very formal directory structure (packages map directly to directories) other languages are not so lucky. If you're writing C, C++ or Objective-C, directory structure is not really forced upon you. For the most part, it is something you impose on yourself, the compiler simply needs to be able to find the files in its include paths.

To that end, I don't espouse that everyone adhere to Java's directory structure, but on the other hand, I don't suggest you drop all of your XIB, plist, .h, .m, .png, .project and *.xyz files into the root directory of your project either. Instead, find a middle ground and organize your files in a simple but consistent directory structure. I prefer to separate files by their type and not generally by their function. For example, I wouldn't consolidate files associated with the login function into one directory. Instead, I save images to an 'images' directory, view controllers get a separate directory as does the datamodel implementation. I generally keep resources separated from class files and I further separate resources by their type (resources/images, resources/xibs, resources/strings, …).

Whatever structure you use, think it through, set it up early, adhere to it throughout, and fix it as you go along. You'll thank yourself later when you can find files intuitively instead of having to search for files that sound like "<your controller name here>".

Distributed Sync Is Hard

How do you get the goat, the lettuce and the lion across the bridge?

Too easy? Ok, you've got an iPad, an iPhone and a web application. Design a system that allows you to sync any device with any other device.

Yet Another Algorithm Blog

I created an algorithms blog to help study these bad boys.

Check it out and fix my errors :)