Cool little Objective-C Method for grouping Facebook likes

Firstly, I just want to say I’m pretty proud of myself for writing compilable code at 4:30am. Go me.

I am making an iOS app as part of my 4th year design project, and we are leveraging Facebook for it. Basically, our app allows you to take a picture of someone’s face and we use facial recognition to pull up their Facebook profile.

Anyway, I was fooling around with the Facebook iOS SDK and one of the things I’ve been wanting to do is to group one’s likes by category. Facebook seems to just return a large array of likes, with no grouping. This little method below groups them so I can have a table view with headings like “Favorite Books”, “Favorite Movies”, etc. Check it out.

An Update on TopForty.it

Figured I would give a quick update as to how TopForty.it been doing. We’re about 2 weeks in, and the response has been great. People seem to love the idea, the execution and the UI/UX, which is heartwarming although I still think it’s rough around the edges (won’t tell you where because then you will notice it =D ).

Some stats: In 2 weeks, people have listened to over 5000 songs (5194 as of last night), totalling in a little under 25,000 minutes. Our visitor return rate is over 60% and the average time spent on site is around 30 minutes. These numbers seem to be increasing, which is good considering the fact that we haven’t really promoted it much (blogs, reddit, HN, etc.).The growth seems to be organic with 50% traffic from Facebook. As we add features, we plan to hit Hacker News and some blogs.

Update: Techvibes did cover us from the demo we gave at Velocity’s end-of-term Demo Day. Since them, we’ve also been featured on GigaOm and The Next Web

Update: Here are the photos from Velocity’s Demo Day.

It’s been really fun to work on this project. I think where we are at now is interesting as we are trying get it out of the “hack” stage and into the “software” stage. Up until a certain point, you don’t give much importance to architecture, focussing on getting features out as quickly as possible. This is changing as the LOC grows. Since all the application logic is in JS, I have to spend a few days really cleaning that out. The good news is that YUI does a lot of the work for you, so I won’t have to refactor too much. I will take that time to pull in some of the new Y.App stuff that’s in 3.5.0.

I really do wish to write a blog post at some stage detailing how the UI works – as much as for my own records as for other people’s understanding. I have exams going on now, so it’ll probably have to wait till mid-December. I have started, but don’t want to publish something that’s half-baked.

OpenCV on Mac OSX: A step-by-step guide

I’m using OpenCV for my 4th year design project and setting it up was a huge pain. I had to look through a whole bunch of different sites to figure out what to do. There are various ways to install it – through package managers such as Homebrew or Macports, or through the tarball + cmake. Now that I’ve got it set up, I decided to write this little post to explain to others how to go about setting it up.

Note: This method does not set up the Python bindings for OpenCV (still working on that). It only sets up the C++ framework. Also, I tested this on OSX Lion, but it should apply to Snow Leopard or Leopard. Also you will need XCode installed for any of this to work (but you knew that, right?)

On that note, let’s get started.

Download a Package Manager

It’s between Macports, Fink or Homebrew. I used Macports, so I’d recommend that. Download the .dmg file, then install it. You can check to see if it installed successfully by opening your terminal and typing port.

Download the OpenCV Tarball

You can get that from here. Look for the Linux or Mac version. Unzip it after you download it into a folder.

Get cmake

In your terminal, type in the following:
sudo port install cmake
This will go fetch cmake and its dependencies and install them onto your system. You can check to see that cmake is installed by typing cmake in a new terminal window.

Build OpenCV

We are going to build OpenCV using cmake. In terminal, navigate to the folder where OpenCV was extracted to. Type in the following:

# make a separate directory for building
mkdir build
cd build
cmake -G "Unix Makefiles" ..

Now, we can make OpenCV. Type the following in:

make -j8
sudo make install

This should now build OpenCV into your /usr/local/ directory.

Make A Sample OpenCV Project

So we now have OpenCV built but we still have to link to the framework in our project.

  1. Start a new XCode Command Line Tool project.
  2. We have to link the .dylib files provided by OpenCV into our project. To do this, right click on the project, and click “Add files to..”
  3. When Finder pops up, hit “/” to bring up the navigation panel.
  4. Type in /usr/local/lib
  5. Add in all the .dylib files that you need. To prevent linker errors, I recommend you initially add ALL the files ending in “…2.3.1.dylib”. There should be a dozen or so. If you know what you need, you can obviously pick and choose.
  6. Now, you should have a bunch of .dylib files in your project. Feel free to move them to a separate group within your project.
  7. Click on the project file and go to “Build Settings”.
  8. Search for “Header Search Paths”
  9. Change the path to  /usr/local/include. This is where the header files for OpenCV were built.
  10. Open main.cpp
  11. Copy the following code snippet. This snippet should load a .jpg image and save it as a .png image.
// Example showing how to read and write images
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv/cvaux.hpp>

int main(int argc, char** argv)
{
  IplImage * pInpImg = 0;

  // Load an image from file - change this based on your image name
  pInpImg = cvLoadImage("my_image.jpg", CV_LOAD_IMAGE_UNCHANGED);
  if(!pInpImg)
  {
    fprintf(stderr, "failed to load input image\n");
    return -1;
  }

  // Write the image to a file with a different name,
  // using a different image format -- .png instead of .jpg
  if( !cvSaveImage("my_image_copy.png", pInpImg) )
  {
    fprintf(stderr, "failed to write image file\n");
  }

  // Remember to free image memory after using it!
  cvReleaseImage(&pInpImg);

  return 0;
}

And there you go. That should be working for you. If it’s not, leave a comment below with the error you get and I’ll try looking into it for you. Hopefully, this helps save you some time.

On that note, here is a good OpenCV Tutorial.

Some Interview Help

Here are some good interview resources that I’ve found over time. Felt it would be useful to friends who are going in for their first full-time technical interview.

Hope this is useful for you guys. If you have more, add it to the comments below and I will update the list.