Archive for the 'Solutions' Category

Sending email using gmail’s smtp with Zend Framework

To send emails using gmail’s smtp server, you must specify the tls port by providing the ’ssl’ and ‘port’ in the config array. The default port for tls is 25 but gmail is using 587. You will also need to authenticate with your account and password.

Update: There’s a daily limit of outgoing emails you can send using this smtp, I experienced a problem of maxing my limit while sending out confirmation emails to the users of my facebook app. So if you are looking to do the same, just be warned that its a bad idea.

$config = array(
’ssl’ => ‘tls’,
‘port’ => 587,
‘auth’ => ‘login’,
‘username’ => ’sender@domain.com’,
‘password’ => ‘password’);

$transport = new Zend_Mail_Transport_Smtp(’smtp.gmail.com’, $config);
//Use this if you do not want to specify $transport evertime you use Zend_Mail->send()
//Zend_Mail::setDefaultTransport($transport);

$mail = new Zend_Mail();
$mail->setBodyText(’Email body in plain text’);
$mail->setBodyHtml(’Email body in HTML’);
$mail->setFrom(’sender@domain.com’, ‘Name of sender’);
$mail->setReplyTo(’sender@domain.com’,'Name of sender’);
$mail->addTo(’recipient@targetdomain.com’, ‘Name of recipient’ );
$mail->setSubject(’Your trial at FItness First’);
$mail->send($transport);

You can use your own domain name using gmail’s coporate email service, if not, just use gmail.com for the domain.

Catch, gmail automatically replaces whatever ‘from’ or ‘reply-to’ you have specified with the account you are authenticating with (sender@domain.com). To use another account, you must allow gmail to send using that email address by following the steps here.

Bezier Curves in AS3

Was researching a while ago for a whiteboard style app and came across Andy Woodruff’s implementation for bezier curves.

http://www.cartogrammar.com/blog/actionscript-curves-update/

Fonts not working after nVidia update

After updating to the latest nVidia drivers some of my fonts stopped working. When I try to access them from the windows fonts folder I get a “the requested file ___.otf was not a valid font file” error, and the affected fonts are not loading in other apps like flash. Continue reading ‘Fonts not working after nVidia update’

Service Capture is your friend

Well, at least when you’re using flash + amf. Last week I was getting the dreaded NetConnection.Call.BadVersion error every other day. Debugging blindly, I had no way of knowing whether I was moving towards or away from the solution. On the verge of giving up until I gave Service Capture a try. The handy tool sets up itself as the proxy to your browser and monitors all kinds of traffic, SOAP, XML, Text, JSON, Flash Traces, you name it. For my case, I used it primarily to decode the AMF responses from my zend_Amf gateway. It decodes the binary responses and place it along the request and response headers in a familiar object tree view, making inspection a breeze.

And I also realized what was causing the errors: the flash player was trying to decode a redirection to facebook’s login page as Amf. Doh.

The fb:serverfbml tag is not rendering

Serious facebook developers would be familiar with this tag. It basically allows you to render fbml outside a fb canvas pages.  Now the frustrating bit.

While writing the invite page for my facebook app, I realize I could not render any fbml when the page is in an iframe. If I set the Render Method to canvas it works fine, so the problem wasn’t with the fbml itself. The xd_receiver was also referenced correctly. After a morning of testing I decided to ask Alvin for some of his old code, and it turned out to be exactly the same, which was puzzling since it definitely worked before.

Another few hours of fruitless searching finally led me to a post which provided a simple solution: set the Connect URL to the same url as your Canvas Callback URL. Appears that this requirement was put in place after an update from facebook. They automatically patched the settings in older apps that used xd_receiver so older apps would continue to run properly, but not surprisingly they missed this out in the developers’ wiki.

Since I was developing a native FB app I had skipped the fbConnect settings entirely, my bad. Now I’m posting this here (with hopefully more intuitive keywords) in case someone else is having the same problem.

ps. For general news and updates for the api remember to check http://developers.facebook.com/news.php?tab=updates often.

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 ‘Making Smarter Thumbnails’

Unzipping files using PHP

My colleage faced little problem today while transfering files to a server. The number of files were in the range of thousands, and we all know what a pain it is to ftp a large number of these small files ( Size wasn’t much of an issue compared to the overhead of commands).
Continue reading ‘Unzipping files using PHP’

Using more than 2GB of RAM in After Effects

After receiving frequent out of memory errors from my After Effects CS3, I decided to do some research and realize you actually need to edit your boot.ini to enable AE to use more than 2.0GB of ram.

Continue reading ‘Using more than 2GB of RAM in After Effects’

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();
nc.connect(null);
ns = new NetStream(nc);
addChild(vid);

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

vid.attachNetStream(ns);
ns.play(path);

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:
http://kb.adobe.com/selfservice/viewContent.do?externalId=kb403268