Main menu

21 Nov

Titanium Studio, Android, and Homebrew

Published by paul

I'm a big fan of the Homebrew package manager for OSX and use it to manage all of the third-party, UNIXy tools that I use for development. The last time I ran brew update, I noticed that there is a formula for the Android SDK. My previous install of the Android SDK was out of date, so I decided to try the brew version and see if I could get it to work with Titanium Studio. The install and config process was pretty straightforward:

  1. Install Homebrew according to the instructions on the web site (http://mxcl.github.com/homebrew/)
  2. Open Terminal and run brew install android
  3. Run android to start the Android SDK Manager
  4. Follow the instructions on the Appcelerator wiki for installing the required SDK components (http://wiki.appcelerator.org/display/guides/Installing+and+Updating+Andr...)
  5. Launch Titanium Studio and open the Preferences. Select Titanium Studio > Titanium, and set the Android SDK Directory to /usr/local/Cellar/android-sdk/r15/. The trailing slash is significant; I found that the SDKs won't be found without it.

Enjoy!

25 May

Lookup tables in CouchDb

Published by paul

These days, I'm busy working on a reimplementation of KnitMinder that uses Mobile Couchbase for data storage. One of the issues that I've been thinking about recently is how to set up an elegant system for shared references that incorporate both built-in values and user-entered data. Examples of these types of sets include colors, counter names, and needle/hook sizes. If I were using an RDBMS, I would create a reference table with synthetic IDs for each value, then use those IDs in the entity table. I could do something similar in CouchDb, but it would be a pain to do all the lookups and maintain referential integrity by hand. Eventually, I realized that CouchDb already does efficient lookups: they're called "views". Duh.

Let's say that I need to present a sorted list of all standard and user-entered colors as part of editing a yarn entity. I define a color as a JSON object containing hue, saturation, value, and name:


{ name: "periwinkle", h:0.097, s:0.225, v:0.925 }

All entities that use color will conform to this object definition, so I might have an existing yarn entry with the following property:


colors: [
{ name: "cinnabar", h:0.014, s:0.760, v:0.550, pct:0.25 },
{ name: "olive", h:0.167, s:1.0, v:0.25, pct:0.75 }
]

Now I can write a view that emits one row for each value in the "colors" property of the yarn object with a key of [ h, s, v ] and a value of "name". With a little bit of property name standardization, I can extract colors from any entity type, not just yarn. I can also provide standard colors by simply creating a document with a field named "colors". Note that each color object in the yarn has an additional field that shows its relative percentage in the color makeup of the yarn. For the purposes of generating the color list, any extra fields are ignored.

The main downside to this design is that the name and color values are copied in each document that uses them, so storage costs are higher than a referential system. For a few hundred to a few thousand documents, though, this shouldn't be an issue, and the advantages far outweigh the additional storage costs for the color data and indexes.

The same system can be used for any other combination of user-entered and provided data.

source for colors: http://en.wikipedia.org/wiki/List_of_colors