I am currently working on a small personal project, an iPhone app written in Objective-C. I needed a simple data structure to hold a 2-element tuple of integers. I originally implemented this as a C-struct:

struct Index {
    NSInteger row;
    NSInteger column;
typedef struct Index Index;

This worked fine, but I often found myself doing a multiline declare-then-set-members pattern every time I wanted to use the data structure. To simplify, I added a small C function to generate structs, similar to CGRectMake:

Read on

I have been working in LaTeX for a paper I’m writing, and have found that if you want to include Matlab graphs in a LaTeX document, EPS files are by far the best way to go. EPS files are converted to PDF graphics and then included in the resulting PDF, which looks way better than plugging a JPEG or a PNG file in directly.

However, I came across a weird issue when trying to save one of my graphs. I used the confusionmat function in Matlab to create a confusion matrix from a set of ground truth and observation data pairs. I then wrote a simple script to create a nice graphical representation of the confusion matrix (adapted from here).

Read on

Today I came across a small issue when trying to adjust a UIView based on rotation of the device. The UINavigationController has two main delegate methods that pertain to rotation of the device: willRotateToInterfaceOrientation:duration: and didRotateFromInterfaceOrientation:. They are pretty self-explanatory. The former is called when the view is about to rotate, and provides the destination rotation. The latter is called when the view rotation animation is over.

The problem I have is that I want to wait until the rotation is over so that I can query the UIViewController’s view for its size and then update subviews accordingly. But if we wait until the didRotateFromInterfaceOrientation: method is called, the entire rotation animation is over and then all my views update – it’s pretty jerky. But if I perform my view manipulation in the willRotate... method, the view controller’s view has not been assigned its new view container yet, so I don’t know what the new size of the view is.

Read on

I’m currently building a web app using Knockout.js as a frontend framework, with Bootstrap as my CSS framework. I wanted to create a button group in which only a single button at a time could be selected (a set of radio buttons). I then wanted to detect when those buttons change value, and which value is subsequently selected.

There are a variety of ways to go about this. You could solve this using jQuery events, Bootstrap-specific events, or within the Knockout framework. I decided to do it using a Knockout click binding so that once the event does fire, I’m right where I need to be to update my ViewModel, and possibly my backend.

Read on

As far as I can tell, this is the best and most correct way to create a custom UITableViewCell that has a backing Objective-C class (so custom subviews) and is layed out using a Nib. If anyone knows of a better way to do it, let me know. There’s a bunch of conflicting information on the web.

Read on

I am using RestKit to map objects in my iPhone application to RESTful requests to my Flask server. I have to use RKRequestMapping to specify the format of the data a POST request expects. This works fine when the data is flat, but I had trouble when there was an array of nested mappings that needed to be accounted for. For example, here is the object that will be passed as data to the POST request:

Read on
Copyright © 2013 Chris Greenwood
Powered by Octopress. Design credit: Shashank Mehta