Tag Archives: Solutions

Exporting your developer and distribution certs and keys from PC to Mac

Migrating my iOS developer and distribution identities from PC to Mac turn out to be a little more involved than expected. I assumed I can import the .cer and .key into my keychain and be done with it, but my Mac does not seem to recognise .cer files at all. So if you’re figuring out how to get the .cer and .key pair to install on your Mac, here’s how.

Before you begin
Have your certificate, key, and Apple’s World Wide Developer Relations (WWDR) certificate ready (available here). Mine’s named ‘developer_identity.cer’, ‘developer_identity.key’ and ‘AppleWWDRCA.cer’, so remember to replace with your own naming when running the following commands.

Open terminal and cd into the directory where the files are residing, then run these commands:

[sourcecode language=”plain”]openssl x509 -inform der -in developer_identity.cer -out developer_identity.pem

openssl x509 -inform der -in AppleWWDRCA.cer -out AppleWWDRCA.pem

openssl pkcs12 -export -out cert.p12 -inkey developer_identity.key -in developer_identity.pem -certfile AppleWWDRCA.pem

What’s the AppleWWDRCA.cer for?
It’s Apple’s World Wide Developer Relations (WWDR) certificate required to certify your builds. Think of it as Apple’s signature on a “the internet trusts this application because Apple trusts it” agreement. You had your signature from the developer_identity obtained from Apple, and now you have Apple’s signature.

Drupal 7 – Debugging Illegal offset type in isset or empty in … and other errors

Though the title mentions Drupal 7, this article is really about the debugging technique and so is applicable to general php as well. I want to share a recent bug we had to solve at work. Though experienced developers would usually have an idea what new code is breaking, mysterious warnings and errors sometimes do slip through while working in teams (even when having a proper svn system in place!). You check with your co-developers and the one who broke it have no idea where this might be coming from, or worse: they have seen and have been ignoring this error for some time because they felt it didn’t matter. What do you do then?

Read the error
The error message “Illegal offset type in isset or empty in…” points to an illegal type used in a call to isset or empty, and it conveniently points you to the offending line – but with Drupal’s (and most of today’s frameworks’) complex page execution flows, it is hard to spot where is the real source of error, especially if the line is in one of the framework’s frequently called core routines (in my case it was in user_access). Since this is not much help in trying to deduce the real source, I resort to setting my own error handler (temporarily overriding Drupal’s) so that I can do a debug_back_trace().

To set your own error handler, define a function and feed the name to php’s set_error_handler():
// Your custom handler
function my_error_handler($errno, $errstr, $errfile, $errline
, array $errcontext)
// error was suppressed with the @-operator, ignore
if (0 === error_reporting()) {
return false;

// print the backtrace
echo ‘<pre>’.print_r(debug_backtrace(),true).'</pre>’;

// throw an error exception if you want to catch it at the caller
throw new ErrorException($errstr, 0, $errno, $errfile, $errline);

// Back at the offending line:

try {
// original code
catch (ErrorException $e) {
// print your own debug log or what not

// Restore Drupal’s own error handler. You don’t want a backtrace
// on every other E_USER_NOTICE’s do you?


While you may find it useful to convert every error into an exception, note that even E_USER_NOTICE would then halt your page execution, so please use with care (refer to php manual on the ErrorException class for a handler that ignores non-fatal errors).

Now, what’s left is to carefully read through the debug backtrace and spot the problem. For my case, it was a line of code someone embedded in a view context. Hope this helped, share your own debugging methods and opinions in the comments.

End note
Some people may feel that my style of debugging isn’t very ‘elegant’ but my experience is that the fastest way to find the problem isn’t necessarily the most elegant way. Rather than going through hours of deducing which functions might or might not be involved, and later realising the problem was in one of those functions that “logically shouldn’t have mattered in this case”, I find that getting a solid backtrace – after a quick deduction fails – is usually my best bet in the long run.

Making Smarter Thumbnails

I was recently tasked to improve the look and functionality of a site that lets users upload images. One of the area I looked into was how it handled automatic thumbnail generation, because I found the thumbnails that were being generated to be, well, plain ugly.

The method they used was a standard resize to max width and height. The uploaded photo is scaled down proportionately to fit into a box of specified width and height. This resulted in irregularly sized thumbnails and even more so when users upload photos with strange dimensions. Not only does it make the page look messy and disorganized, Continue reading

Getting video length in AS3

To get the length of a loaded FLV, you need to have an object listening to the meta data stream. Here’s how:

var vidClient:Object = new Object();
vidClient.onMetaData = onMetaData;
ns.client = vidClient; //ns is the netstream object

function onMetaData(metadata:Object):void {
lengthOfVideo = int(metadata.duration * 1000)+1;
trace("Length of flv from metadata = " + lengthOfVideo);


vidClient.onMetaData = null;
vidClient = null;

If you’re wondering how to actually load and play the flv file:

var nc : NetConnection;
var ns : NetStream;
var vid : Video;
var path : String = "test.flv";

nc = new NetConnection();
ns = new NetStream(nc);

//optional events to handle status and error
ns.addEventListener(NetStatusEvent.NET_STATUS, statusHandler);
ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);


Photoshop’s Save As dialog box appears and disappears

More like a flicker I should say, and then Photoshop seems to have hung. Well apparently the window is still there, its just off screen. Press ‘esc’ to close it and try File->save again. If it still doesn’t show up, use the following combination:

Alt key, Space bar, ‘M’

and use the arrow keys to guide the lost dialog back to your screen. If pressing left doesn’t work, try pressing right. Have fun.


For more details:

ZBrush to Maya and back again

It is common to want to bring your model out of zbrush to do up the uv’s (although it is always a better idea to deal with them BEFORE getting into zbrush), but importing the edited .obj back into zbrush can be a hassle, esp when your model ‘explodes’ inexplicably when you move up the subdiv level.

Example of a exploded model:

Exploded model

Exploded model

To save a few souls, below is what worked for me and you can try to take note of the following when nothing seems to work:
(Tested with ZBrush 3.1 and Maya 2008)

In ZBrush

When exporting from zbrush, make sure you are at the lowest subdiv level.

Under Tool->Texture, make sure you have UV enabled:

Enable UV

Enable UV

Under Tool->Export, turn off the ‘Grp’ option and on the ‘Mrg’ option as such:

Export from ZBrush

Export from ZBrush

In Maya

Go to File->Import Options, and set the settings as below:

(Note: When editing DO NOT move the vertices in maya, only edit the UV’s)

When exporting, go to File->Export Selection Options. Select OBJ and off all the File Type Specific Options in the last section:

Back in ZBrush

Import the .obj while still at subdiv level 1.

After import, move up a level to check if it explodes.

Feel free to leave any comments whether this worked for you and also for others to benefit from your experience =)

IIS Service failing, cannot start Com+ System Application

Recently my IIS service have been failing with COM+ errors in my event log:

A condition has occurred that indicates this COM+ application is
in an unstable state or is not functioning correctly.
Assertion Failure: SUCCEEDED(hr)

Server Application ID: {02D4B3F1-FD88-11D1-960D-00805FC79235}
Server Application Instance ID:
Server Application Name: System Application
The serious nature of this error has caused the process to terminate.
Error Code = 0x8000ffff : Catastrophic failure
COM+ Services Internals Information:
File: d:qxp_slpcomcom1xsrccomsvcstrackertrksvrtrksvrimpl.cpp, Line: 3000
Comsvcs.dll file version: ENU 2001.12.4414.308 shp

Microsoft’s Malicious Software Removal Tool reports that it removed CutWail from my system but on furthur inspection CutWail was still present and I manually removed the 2 files (ip6fw.sys and secdrv.sys) in %systemroot%/system32/drivers/ along with some reg entries.

Next I suspected a corrupted IIS installation, so I reinstalled IIS but the problem persists. It turns out the COM+ System Application Service could not be start. (And IIS depends on COM+)

The symptons are as follows (i’ve ranked them in order of discovery):

  1. Visual Studio refused to load web application projects. (giving me the “visual studio cannot create or open the application because the web server on this computer is not running” error)
  2. Browser unable to connect to localhost
  3. World Wide Web Publishing service stops by itself after it starts. (Or when i try to load projects in VS)
  4. IIS Admin service stops in the same fashion as the above.
  5. COM+ errors in event log (see event details above)
  6. COM+ System Application could not be start (Error when you try to start it).

After looking around and tested many solutions I finally found one that fixed the problem (without reformating and reinstalling everything, as a few people suggested).


  1. Refer to How to clean up a damaged COM+ catalog (http://support.microsoft.com/default.aspx?scid=kb;en-us;315296) to repair COM+
  2. Reinitialising IIS by running rundll32 %windir%system32inetsrvwamreg.dll, CreateIISPackage (also detailed in the KB article)

Did the above work for you too?