By now this is a pretty well known bug that if you type in file:/// (f in caps) in a lot of OSX apps, it will crash it. If you haven’t heard, see here or here or here. The worst part about this is someone could easily perform a denial of service attack on your iMessage app on any of your OSX machines by just sending you a quick message with 8 characters. You can try it right now as well……Oops, did I forget to mention? You will also send your own iMessage into a frezny crash loop…..

If you google around how to fix this, most blog posts would suggest you go and delete anything that starts with ‘chat’ in your ~/Library/Message folder (for example, Gizmodo). I would advice against it unless you don’t care about your chat history being completely erased. With a little terminal and sql you can easily fix it without having to remove your entire chat history.

The idea is pretty simple. The chat.db file that you were told to remove contains your chat history for iMessage. Instead of deleting the whole thing, you simply need to delete the culprit chat message that crashed your iMessage. We can easily do this with sqlite3 and a couple simple sql commands. Let’s get crackin.

It’s been a while since I updated my site. A lot has happened and my life has taken on a different direction! First I finished my thesis and thus completed my Ph.D degree at Berkeley! I accepted an offer from Apple Inc. and now work on the iOS Performance Team that oversees the performance of all iOS devices (iPhones, iPads etc). My team works across the whole programming stack, from app level down to kernel and device drivers, and we focus on issues related to performance, including memory, latency, framerate etc. It has been great!

This site has been down for a while because I forgot that i was hosting on the berkeley school servers, and when I graduated my account expired, but now everything should be back up and running! I will try to update the other portions of the site as well. But for now, have a great 2013!

As I mentioned in my previous post, Learning Android didn’t cover a couple topics, and one of them is Cloud to Device Messaging, or push notifications. When applications are getting data from the internet, there are two ways to keep the data fresh. First is called polling. It means that the app initiates a connection to the server at set intervals to see if there are new data. The problem is determining the polling frequency. Poll too often, you waste a lot of batteries without always getting new data. Poll too rarely, then you risk not getting new data in a timely fashion. The alternative is called pushing, or push notifications (iphone users should be familiar with the term). Instead of the client initiating a connection, the server sends a data packet to the client whenever there is new data, then the client reacts to it. Because there is some overhead to maintain a persistent connection to the server, rolling out a push notification service isn’t a trivial task, but google has done that for us! It’s called Cloud to Device Messaging (C2DM). We piggy back off of the connection that android maintains for gmail, google voice, gchat etc, and register our app to be “waken up” only when the server pings us. Note that the server doesn’t actually send the new data, it only sends an alert that new data is available. This keeps the ping packet small so there is less overhead. It’s up to the client app to receive the notification and then go to the server to retrieve the fresh data. In this post I will explain how to setup this service for your app. I will assume that you went through “Learning Android,” or at least have a basic understanding of the building blocks of Android programming. For the sake of keeping this post under a tolerable reading length, I will only go over the mechanisms. I have checked in a sample c2dm app that’s commented in my github repository, so clone the repository to see the whole picture. I also included a small ruby script to mimic a web server sending c2dm packets to the client device, this way you can debug your implementation without needing to setup a server. By the end of this post you should have an app that you can install on your phone or emulator, and then a way to send it push notifications without requiring any server side coding!

I’ve been following this online book Learning Android which I would highly recommend to anyone that wants to begin learning how to write android apps. It does a great job explaining the concepts of Android development through a non-trivial sample application – a twitter application. It also goes through the process of building the app step by step, improving the app when introducing more advanced concepts. This helps show how to use the building blocks that’s learned to improve an application. It goes through all the building blocks of android apps, and even the more advanced concepts like Android Interface Definition Language (AIDL) and using the Native Development Kit (NDK). I have followed along and built the demo apps while publishing the source code in my github repositories. If you want to learn how to write Android apps, follow along the book and I guarantee that you will not be disappointed!

However, I found that there are some concepts that are missing in this textbook, namely:

So after revisiting my blog I realized that descriptive tutorial entries with code segments are helpful, but they are…long. The front page of my blog was being dragged way too long by those entries. Thus, I needed to add an “excerpt” feature that allows me to partially display an entry and add a ‘read more…’ link for the full post. Rien Heinrichs has done exactly that with his blog created with Webby, and his github page contains the source. I took a look and turns out it was a lot easier than i thought. Here is how to do it:

I just found out that Webby is no long under active development =(. What a sad piece of news. However, with the current Webby version, it’s still good enough for me to maintain my blog. Since it’s relatively easy to extend, I decided to add tags to Webby.

I saved a link to Aarom Qian blog post about adding tags to Webby a long time ago, but unfortunately the blog is no longer online. I dug around and was able to find his github repository and the raw textile/erb entry in there. You can see it here: Adding Blog Tags using Webby.

In general his directions were pretty clear and everything worked well. It explained how to setup the tags framework and how to use rake tasks to generate the tag pages. However, I did need to make some minor hacks to get it working. I’ll try to add a tutorial blog entry if i have time. I’d also be more than happy to answer any questions if anyone is having trouble implementing tags.

In the mean time, try to follow along his post, or check out the source of this blog on my github account. Enjoy!

In my last entry I covered how to integrate facebook api with ruby on rails using fb_graph gem. There is one problem with integrating the facebook api with your website however, and that is if facebook goes down, then your site also crashes. Yesterday facebook went down, along with the graph.facebook.com api. As a result, one of the sites I was managing went down since it kept waiting to authenticate with the facebook graph api. Now there are definitely other solutions around this, but I also found that when using facebook integration on websites, the websites load a little slower because it has to connect to facebook first, fetch the data, then render the webpage, so the performance of the webpage will heavily depend on the speed of the facebook fetch. Thus, I decided to implement a caching scheme that synchronizes a local database with information fetched from facebook. This way my page only needs to access a local database every time it’s queried, but the database is synced with facebook information, so it’s pretty much like I’m accessing facebook!!

The basic idea is as follows:

Create a table that stores the information you want from facebook

Setup a ruby script that uses the fb_graph gem calls to update the database

Setup that ruby script as a cron job on the webserver and run it as frequent as you like

(09/25/10) Edit: A working version of this source code is uploaded here. Download it and follow the README to try it out!

While working on our church website, integrating with our church’s facebook fan page became a desired feature so our site maintenance team can just add an event on facebook and have it synced up to our website.

After learning about the facebook graph api, I was planning to write a library for ruby that sent out the queries and parsed the results to display on our site. However, I found the fb_graph gem written by Nov Matake and decided to try it out. The experience was extremely positive and Nov was very helpful and prompt in responding to my emails. Here’s how I integrated the facebook graph api into a ruby on rails app:

After playing around with the layout and jQuery for a while, Internet Explorer 8 was really pissing me off. Everything that worked in Firefox, Safari Chrome didn’t work properly in Internet Explorer 8. I wonder why that browser is still around… Anyhow, I later found a quick solution that can fix most of the IE problems, and that’s the zoom:1 fix! All you need to do is add the following line to your css:

And just that like, every problem that I was having disappeared. I can’t really explain why, and apparently neither can this blogger. But the point is, use it and save yourself some trouble. Microsoft, when are you going to figure it out…?

Since I’ve had such a positive experience with Webby, I’ve decided to blog a little about some stuff I’ve figured out when using webby. I know there are some amount of tutorial I’ve found only for Webby, so I’ll try to not repeat a lot of them. When I constructed this blog using webby, I wanted the dates to be in the format of “2 minutes ago” or “1 month ago,” instead of absolute dates. This cannot be achieved by using webby alone, since these dates can only be changed when the website is build. Thus, a little java script magic is needed. JQuery is a javascript library that allows plugins and has several AJAX functions. In particular, I’m using the Timeago plugin for JQuery. What this javascript does is turn any date you wish on your page into the “timeago” format. It also auto updates itself, so it’s perfect to be used with webby. First you want to follow the links above and download both the plugin and JQuery (go ahead and get the min version). In your main layout page (in the layouts folder), add the following lines between the <head> tags:

Recent Changes

Image Gallery

Sitemap

About the Site

This site was created using webby, which is a dynamic generator for static websites. The purpose of this site was for me to experiment with website generators, ruby, lightweight markup languages (textile, Haml, Markdown etc). I wanted to generate a blog like website where it was easy to update contents, it had content and layout separation, and it’s only static html pages. Then i plan to integrate more dynamic features with javascript slowly. The source code of my experiment (this website) will be kept public and up to date on github. By doing so, i can also easily deploy this website (since it’s static and the pages are all in a source control repository) to any webhost. Feel free download the source to play with it and contact me if you have any questions or comments.