Carpe diem (Felix's blog)

I am a happy developer

C/ObjC Block Syntax Explained

Block is heavily used in objective-c APIs. If you want to write concurrent and responsive interface, you will need blocks and grand central dispatch. Blocks also bring many goods form functional programming to cocoa. It is just awesome.

However, when I first learn blocks I found the syntax confuses me a lot. This is why I wrote this article. Hope this article can help people who have the same problem as I did.

Taiwan Typhoon App (2)

I start from a single view application with MKMapView. Remeber to link MapKit.framework in project setting.

This is just a prototyping app, so everything will be handled in FCViewController, including

  • NSURLConnection delegate: handle request and incoming data stream.
  • Read data as string, and process it with regular expression and JSON parsing.
  • MKMapView delegate: create and draw annotations and overlays.

Taiwan Typhoon App (1)

Taiwan is an island next to Pacific ocean, and one kind of serious disaster in Taiwan is typhoon. Fortunately, We have best typhoon researches in the world, and I want to make a step further to let people read typhoon predictions on iOS.

Earthquake Early Warning Prototype

I made a prototype of earthquake early warning system in one week. The scenario goes as follows: We use a Friendly ARM SBC (Single-Board Computer) as an earthquake signal collector and processor. If the signal was identified as serious earthquake, it would send a message to our server. Then our server will authenticate the message and use Apple Push Notification Service (APNS) to notify some iPhone registered for the notifications.

The demo video:

Grand Central Dispatch vs OpenMP

In 2009 Apple released a new task parallelism technology called Grand Central Dispatch (GCD). Apple worked hard on tuning GCD; stated that only 15 instructions are required to queue up a work unit in GCD, while creating a traditional thread could easily require several hundred instructions.
The main advantage of GCD is that programmer/user does not required to choose how many thread for application that optimize the most. It can save a lot of time for programmers because getting the most power out of CPUs requires a lot of measurement. With GCD, let the operating system decide it for you, it just works.

Handle Touch Events in UIWebView

This is an annoying problem that related to my recent project. The goal is simple:

handle single touch event in UIWebView and let it handle other touch events as defaults.

However this is really hard to achive…

Edit: 6/20

I found this post:DETECTING TAPS AND EVENTS ON UIWEBVIEW – THE RIGHT WAY. He handles touch event via - (void) sendEvent:(UIEvent*) event instead of UIGesutreRecognizer. His approach is more general and less hacky than mine. Have a look at it also!

Debug UIWebView in Your iOS App

It is often to embed a UIWebView in an iOS app. However it doesn’t provide the powerful webkit inspector by default. Nathan de Vries has written a post to solve the problem, but the solution didn’t work on my XCode 4 with Clang front end.

Recursion Best Practices

There are many programming languages that support recursion. However, recursion is hard to write, and even harder to write it well.

To iterate is human, to recurse, divine.

If you also surveyed deeply in FP area, you will find a lot of patterns, such as tail recursion, continuous passing style, combination of higher order functions, fixed point y-combinator, memoization, and many more. You can see that a simple factorial can be written in 23 different forms. How do we pick a better one?

In short, the only pattern you should use heavily is tail recursion. Use other patterns only when necessary.

Jekyll/Octopress Hacker News Plugin

Inspiration

I found out that some cool blogs have a cute hacker news like button on each of its posts.

The service is HN Like Button, created by shashyal. To use it you can use the generator like so:

However, we don’t want to do that every time, right? So I decided to write a small Jekyll plugin to generate the button automatically. Hope you can enjoy it!