Posts in Category: Programming

AWS OpsWorks CookbookNotFound on Custom Repositories

Since Amazon began offering OpsWorks earlier this year, I’ve been looking forward to giving it a go and picking up some Chef know-how in the process.  I have come upon a rather painful issue where a single cookbook in my git repository’s root continuously threw Chef’s CookbookNotFound exception.  After hours of futile trial and error and a heap of Googling I finally happened upon this thread in the AWS forums.

The important takeaways are:

  1. OpsWorks doesn’t currently handle single-cookbook repositories correctly.
  2. Putting your cookbook in a subdirectory of the git repository should work.

I suppose this explains why all of Amazon’s example cookbooks are parented under the same repository! To avoid this insanity in the future, you may as well just create the cookbook in a subdirectory of a git repository to begin with.

mkdir my_app_cookbook
cd my_app_cookbook
git init
knife cookbook create my_app -o ./

Great Find for Pretty JSON in Safari

I finally got tired of going to the [really, really awesome] pro.jsonlint.com and decided to have a quick look for a Safari plugin. Sure enough, in about 6 seconds of searching, I found this safari-json-formatter on GitHub. Its advertised for Safari 5 but installs without issue and works great on Safari 6. Thanks, Rick Fletcher!

Getting NSNumberFormatter to Display Currency

When working on a little cocoa app today, I ran in to a somewhat perplexing problem where I could not get currency-formatted values to display in my NSTableView.  Using interface builder to add a number formatter to my text field and set the style to currency, I set the text value and… nothing.  Turns out that the formatter only wants double values, so use double values :)

OpenShift PostgreSQL Backups

Over the last few months I’ve been testing Red Hat’s new PaaS offering, OpenShift.  The testing insofar has gone extremely smooth, but what about preparing for when disaster strikes.  The rhc command-line client provides snapshot functionality but unfortunately carries the caveat of needing to shut down and restart the application in the process.  For a PHP or Python application this is fine as restarts are lightning fast, but redeploying a JavaEE application is… cough… not so lightning fast.

If you can live with the need to restart, this command will give you a very complete tarball:

rhc app snapshot save -a ApplicationName

The other option is to do it via a cron job that will back up the data into your OpenShift data directory on the server (the data in this directory is not deleted each time the application is redeployed).  To do this, you will need to have the cron cartridge installed in your application.

If you don’t already have the cron cartridge installed, you can easily enable it with this command:

rhc app cartridge add -a ApplicationName -c cron-1.4

With cron setup, we can setup jobs to run minutely, hourly, daily, weekly, or monthly by dropping scripts into the appropriate folder in our application’s .openshift/cron directory.
Create a file named backup_postgres.sh in the minutely, hourly, daily, weekly, or monthly folder and paste the following script in. (Also available on GitHub)

With the backup script created simply commit it and push the changes to your application.

git add backup_postgres.sh
git commit -m "Added PostgreSQL backup script"
git push

Once the changes are pushed you can retrieve your application’s database backups by using rsync

rsync -avz -e ssh loginhash@appname-you.rhcloud.com:app-root/data ./

This, admittedly, isn’t the prettiest solution to the problem but it does its job.  I may end up patching the rhc CLI app to do something similar to this and automatically download the results.

Where Have I Been?

I realize I’ve been more vacant than usual these last few months, perhaps its time to get a post down on [roughly] what I’ve been up to.  In late February I took on a pretty interesting job for a big name client (details coming soon!).  The work has afforded me the ability to become quite intimate with a number of technologies of which I’d only had “user manual” level experience.

  • Event Driven HTTP Servers in Java
  • Lots of spatial analysis using PostgreSQL’s built-in Geometry types (I didn’t even know these existed outside of PostGIS)
  • Circle Packing algorithms
  • Super Bonus:Processing found its way back into my life!  Visual prototypes that happened to be beautiful really helped me out.

There will be more information about what I’m up to in a the next week or two, but its exciting and I’m working with some awesome people.. Stay tuned!

Another Iteration of OpenStreetMap Visualization in 3D

I’ve made some great strides since my last update a day and a half ago.  It turns out that having someone around to re-frame your problem can make the solutions to problems more readily apparent.  I suspect this is how psychiatrists stay in business, I’m just glad it carries over into the world of mathematics :)

Rather than going through conforming Delaunay triangulations or by attempting to cut up triangles and create keystones, I’ve gotten another way to do it.  Given a center-line, quads can be created by thinking of the left and right sides as ‘tracing’ along the path of the center, but offset by some distance on either side.  In the case of turns, subtle and sharp angles can be handled in the same way.  By getting the azimuth between the prior point and the next point (we can think of them as i-1 and i+1), a constant distance from i can be maintained by simply getting the positive and negative perpendicular vectors with respect to the azimuth from i-1 to i+1.  It turned out to be a pretty good solution as you can see in the video below.

More on OpenStreetMap Data in jME

So since my deliciously glitched programmer art meets geodata post yesterday I’ve done a fair bit of work on my Thesis project.  After some frustration with Delaunay Triangulations and Conforming Delaunay Triangulations I’ve resigned myself to using GL_LINES as a temporary stopgap measure.  I’ve alotted myself a total of 1 week for the integration of any data coming out of OpenStreetMap into the project and I’m less than 48 hours in.  Hopefully I get the time to come back to this and do the triangulation properly.  Some advice from the make of Mythruna, Paul Speed, on chat tonight looks to be promising and a significantly simpler solution than I had anticipated (aren’t those the best kind?).

I’ve also added the rendering of railroad tracks this and have begun to build a color schema for the display of data.  Grey is roads and brown is railway.  Public transportation is also linked to blue lines, but New York evidently doesn’t have it annotated as such in the map.

OpenStreetMap data in jMonkeyEngine

I’m working on the integration of different GIS-related services into a single unified application for my masters thesis and have been picking up where I left off on Betaville and its OSM capabilities. (It loads the data, makes some pretty scruffy looking geometry out of it, and can then render it in real-time as well as export it to COLLADA or OBJ)

Below are a few short videos of me letting off some creative steam while playing with the data.

Triangulation is done courtesy of Java Topology Suite (JTS), which may be the coolest library ever written… with the exception of jME ;)

Berkelium Integration with jMonkeyEngine

A few other jMonkeyEngine team members and I were talking about this a week or so back and a few days ago I started thinking again how cool it would be. So here it is, a Berkelium window running within OpenGL via jME3. Mouse coordinates finally line up properly within the texture, which was my personal goal before letting people know too much about it ;)

Performance with one window is quite nice, I can get between 2600 and 3200 frames a second. Regarding the question of video, yes it will indeed play video formats natively supported by Chrome without the aid of Flash. A few YouTube videos here and there do function (I had one on Ubuntu’s website working and then starting having problems), as does a good sample Ogg-Theora video available from Wikimedia

I’m planning on keeping up development with this, including some sort of mechanism for calling delegate methods in Java from HTML widgets (effectively making it an extremely simple UI system that allows GUI’s with HTML/CSS and JavaScript.. should be pretty cool!)

Unfortunately its Windows only right now but I’m working on building Linux and Mac natives of the Berkelium-Java wrapper.

Berkellium-JME3

Berkelium JNI Binding

The screen recorder kind of killed performance :(

New OSMGenerator Branch

If you’re following me on GitHub you might have seen that I’ve been pretty busy over the last few days.  After the short discussion on the original iteration of OSMGenerator, I began work on a branch that uses separate tables linked by foreign keys to nodes/ways/relations for the storage of keys.  The idea behind this is quicker lookups based on tag searches, which is just about the only way to get data that users will find interesting out of the database.  My thanks to Frederik Ramm for bringing up the disparity in schemas between OSMGenerator and osmosis.

The branch is located here and I’m currently doing speed comparisons between it and the original 0.1 release.