Author Archives: Ryan Tan

Fixing Drupal’s Canonical link meta tag

Fblint complained that one of my page’s canonical link mismatches the og:url meta tag. Turns out Drupal 7 outputs relative canonical links by default and although there’s nothing strictly forbidden about relative links, both facebook and google seems to prefer absolute links. Rather than altering the offending tag through hook_html_head_alter() or even worse, mess with the core files, I decided to install the Metagtag module (http://drupal.org/project/metatag).

The default configuration looked fine (the module even supports og meta tags!) so I ran the page through fblint again, hoping it to be another fine install-set-go Drupal 7 module. 58827 sites were using this module at last count, that’s pretty reliable. I was dismayed when I got the same results and a quick check revealed that apparently the module modified none of my head tags. I also noticed that its only the front page that was having this issue. The module works fine on all other pages. A few drupal.org threads later I arrived at the solution: calling render($page['content']); is all it needs to get it to work on overidding page–*.tpl.php’s. Yup just calling render() will do, no need to print.

Solution thread: http://drupal.org/node/1293214

Tips while profiling your app to solve low memory warnings and crashes

Just a quick post to share what I learnt while investigating crashes in my iPad app. The crash reports consistently showed low memory warnings before the crash so I started using instruments to profile the app. Here’s some tips that may help you out when you are stuck using the instruments tool:

Turn off Zombies. Zombies are great for debugging messages sent to de-allocated objects, but they come at a cost of memory – NSZombies are never deallocated. Turning this off immediately showed great reductions in terms of live bytes in the allocations instrument. Apple’s documentation advises zombies to be used only on the simulator while debugging and testing.

Mark your heap before and after performing actions on your app to inspect the memory changes introduced by the action. A simple evaluation to keep in mind is that if any set of actions returns the app to the same state as before the actions, the changes in heap before and after the set of actions should be close to 0. Any significant amounts detected here would signal a leak, which need not necessarily reflect in the leaks instrument profile. Many conditions, like circular references, may cause actual leaks to be ignored in the leaks instrument, but that’s the focus of another article.

The Allocations and Activity Monitor operates differently, and gives very different results. I made the mistake of assuming the ‘live bytes’ column in the allocations report to be what my app was consuming. While allocations reported that my app is using a consistant amount of memory, I was still receiving low memory warnings, so I finally decided to run activity monitor. Surprise – the low 6.3mb consumption in allocations actually translated to 180mb in activity monitor. Why is that so? Turns our when you deallocate memory in your app, or even if you are using ARC, the memory is only released at undetermined intervals when iOS feels like it. While allocations track every memory your app allocates and deallocates, the activity monitor gives a true reflection of your app’s memory footprint.

But of course, those latent released memory wouldn’t chalk up to 100 over mb’s. The real culprit turns out to be CoreGraphics, while it handles all on screen drawings and image operations behind the scenes. The real memory consumed by these operations are not reflected in allocations at all. ARC also does not track CG objects so do remember to release them properly.

Now knowing the real issue, I proceed to refactor and restructure my drawing code to improve reuse of bitmap contexts and reduce repainting areas by keeping track of dirty rectangles. Hope these tips would help give some ideas to those of you debugging your crashes at 3 in the morning. Do also share some of your own tips or experiences in the comments!

Calling all Singaporean smartphone users

Spent the weekend working on an interactive survey of Singapore’s mobile landscape focusing on the 3 mobile operators Singtel, Starhub, and M1. I figured none of the telcos will ever commission this sort of open data so I decided to put it out there and see what sort of response it can get. Everyone can leave their feedback on the map to help build a comprehensive and unbiased overview of our tiny nation’s network coverage.

Landing page of the Singapore's mobile landscape website

As you can see it’s still at a very rough stage so please excuse the bugs and usability issues. If you have a cool idea, do leave them here in the comments or drop me a mail, welcoming all feedback and suggestions. Please share to fellow Singaporeans!

http://singaporemobilelandscape.com

Storing images on file system vs database

While researching efficient methods of storing large numbers of images on my server, I came across this post detailing the process of returning an image from a mysql server. The process described is common, except that it is inspected at a much lower level, complete with mode switching between kernel and user on a linux server:

Your systems network buffer fills with a new packet containing a new request from the network card. The system delivers the packet to your Apache, switching from kernel mode into user mode.

Apache processes the packet, handing it internally to its mod_php for processing. The mod_php parses the request, constructing a SQL query for the image blob, and pushes the SQL query into a kernel buffer, switching from user mode into kernel mode.

Check out the full post at http://mysqldump.azundris.com/archives/36-Serving-Images-From-A-Database.html

Making Lobster Thermidor

See Alvin the chef turn lobsters fresh from the jurong fishery port into delicious lobster thermidor, complete with tiger prawn spaghetti, pan-seared striploin steak and a side of rockets salad and cheese. We spent a day at Alvin’s place helping out and I took the chance to capture the process to the tune of Waipod Phetsuphan’s Ding Ding Dong.

Check out the photos too.

Clear’s FaceBook Racing Game

clearfinish

Did a flash racing game for Clear’s worldwide campaign in time to coincide with the F1 racing event in Singapore. Turn on your speakers for the full experience! Features a per-country leaderboard and some clever optimisations to allow the average consumer machine to run these beautiful full resolution 3000×4000 maps for each difficulty level. Play the game on FaceBook.

Galaxy Note 10.1 to include Photoshop Touch

The new Galaxy Note 10.1 will be released to the public on 16th August and Samsung has preloaded it with Photoshop Touch. This will be the first time that a feature of this kind has been included on a mobile device, so it marks a significant milestone in the technology world. This was made possible, after Samsung teamed up with Adobe Systems in order to load Photoshop Touch onto the new version of the Nexus. With this feature, users will be able to sync files to the Adobe Creative Cloud, as well as having access to 2GB of free storage space.

One of the advantages of the Galaxy Note 10.1 is its affordability when compared with computer systems. With its Stylus Pen, users can still use great apps, without having to spend a lot of money in order to obtain them. So while desktop computers may be useful for some things, like typing out documents and playing party poker, the new Galaxy Note 10.1 is a good choice for app lovers. Users can edit photos while they are on the move, with their fingers or the Stylus Pen, as there are many features within Photoshop Touch that make this easy.

The preloaded version of Photoshop Touch includes some great features, such as selection tools, layers, filters and adjustments. Users can edit images to create wonderful works of art, or simply to tweak the photograph and make it appear how they want it to. The unique camera fill feature uses the tablet’s camera to fill in an area on a layer, which is a very useful tool. There is also an integrated Google Image Search, with which users can look for images, as well as the ability to share images to Facebook. This new release signals the start of something great for app lovers and should go a long way to making many image editor’s lives easier.