Mar 29

In developing Easy Export, I created a cron script that updates the user’s fbml on their profile page periodically. It worked great, but after some time I started getting the following execption thrown:

 'Invalid parameter', on line 1520 in facebookapi_php5_restlib.php

After looking into it, I realized it’s because I was trying to set the fbml on a user who previously had the application installed, but had since removed it. So to fix it, you can either ignore the error (empty try/catch block around setFBML) or check whether the user has the application added before trying to make this call - via users_getInfo( $user_id, ‘has_added_app’ )

Mar 26

I created a facebook application several weeks ago, but never got to write about it. It was actually pretty painless.

I wanted copies of all the pics I had been tagged in on my own computer. It was taking me forever to click through all of them individually. So I made this app - which will save you lots of time if you ever want to do the same. It also makes a spreadsheet of all your friends and packages everything up in a single zip file.

I made it public so others can use it to.

For more info:
http://www.shanelabs.com/easyexport/

Or to install it:
http://www.facebook.com/apps/application.php?id=21759489312

Mar 26

I couldn’t find a function already created for PHP that calculates someone’s age based on their birthdate and the current date (in unix timestamp format - seconds since 1970). First I tried this:

$age = date("Y",$endtime) - date("Y",$starttime);

But then I realized that this might not be completely accurate, base on the calendar, leap year, etc. So here’s what I ended up with:

function computeAge($starttime,$endtime)
{
     $age = date("Y",$endtime) - date("Y",$starttime);
    //if birthday didn't occur that last year, then decrement
    if(date("z",$endtime) < date("z",$starttime)) $age--;
    return $age;
}

Let me know if you have any improvements!

Mar 07

I’ve got a google maps application on an ASP.NET ajax enabled page through an update panel. I had used setInterval to run a javscript function periodically and update the markers on the map. Over time, I noticed that when the map was updated through ajax while the javascript code was executing, i got the one of the following two errors:

'__e_' is null or not an object
'undefined' is null or not an object

These errors didn’t seem to have any effect, other than a javascript error being noted.

Through debugging, I determined that it was because of GEvent.addListener(), GEvent.clearListeners(), and marker.setImage(). Because I was getting real time updates, it was ok if every once in a while these things didn’t get updated - I could just ignore it and it probably will be updated next round. So, if you simply put these calls in a try/catch block, the errors don’t get generated.

try
{
    marker.setImage(newImagePath);
}
catch(err){} //it's ok to fail here - ignore it.

Good luck!

Mar 07

I’ve got a project where I’m using google maps within an ASP.NET web part in an update panel. The google maps code requires you to run some javascript as soon as the page loads. Usually people put this in <body onload=x> or use javascript: window.onload=x, but when I did those either the method wouldn’t run, or web parts would get messed up. I’m guessing because there’s some web parts javascript that needs to run at page load, and since you can only assign one method, they were interfering with eachother.

 I tried just running the google maps initialization script after I write all the needed elements to the page, but then I was randomly getting the dreaded IE error “Internet Explorer cannot open the internet site. Operation Aborted.” The common fixes to this error suggest calling your initialization script with an onload trigger (not possible for me as described above) or moving your script to the bottom of the page, outside of the body tag.

Sounds like an easy fix, but since I was using web parts within update panels I had to use ScriptManager.RegisterStartupScript in order to inject the code, which didn’t allow me to place exactly where the script was being placed. After long hours of trying many many workarounds, I finally found about the PageRequestManager pageLoaded event. It’s a javascript class that is available when you use asp.net’s ajax, and it can be used to register functions that should be triggered once the page is loaded. Here’s the javascript you need:

var prm = Sys.WebForms.PageRequestManager.getInstance(); prm.add_pageLoaded(myFunctionToRunOnLoad);

It took me forever to find this, I wish it was documented more. Hopefully it solves your problems!

Mar 05

I was having trouble getting Dundas Gauge for ASP.NET to reflect the value that I was assigning it. For some reason, the needle always pointed to the default 0. I was using this code:

//create circular gauge
GaugeContainer gauge = new GaugeContainer();
CircularGauge circleGauge = new CircularGauge();
gauge.CircularGauges.Add(circleGauge);

//scale
CircularScale scale = new CircularScale();
scale.Minimum = -100;
scale.Maximum = 100;
circleGauge.Scales.Add(scale);

//pointer
CircularPointer pointer = new CircularPointer();
pointer.Type = CircularPointerType.Needle;
pointer.Value = 10;
circleGauge.Pointers.Add(pointer);

//display
gauge.ImageType = ImageType.Png;
gauge.Width = new Unit(200);
gauge.Height = new Unit(200);
gauge.Page = Page;
gauge.RenderType = Dundas.Gauges.WebControl.RenderType.BinaryStreaming;
gauge.RenderControl(writer);

So “pointer.Value = 10;” was not working. After looking at some examples, I figured out that this worked:

gauge.CircularGauges[0].Pointers[0].Value = 10;

I’m not sure what the difference is, but give it a try if you’re having a similar problem.

Mar 02

I was at a relative’s funeral yesterday, and someone eulogized her as “taking delight in other people’s happiness.” What a great mantra to live by. I’m gonna try to adopt it.

Mar 02

Well, here’s my first blog and my first blog entry. I’m gonna use this blog to help me document some of the lessons I learn, through life or software, so that other people can learn from them.  Enjoy!