Awesome PHP debugging function

I still haven’t found a good free setup for debugging PHP but this is the next best thing. Jacob Rosenberg posted a copy of his yo() debugging function. We used it extensively when building http://video.yahoo.com and I can vouch for its awesomeness.

The Greatest PHP Debugging Function of All Time.

I did have one issue with it though, for whatever reason the install of PHP on my DreamHost account wasn’t ever able to pick up any vars if I used the yo() shortcut. I had to modify the shortcut so that it passed func_get_args() to the static function. Weird, and annoying that everything was now wrapped in a superfluous Array() but not the end of the world.

I’m happy to have yo() available to me again for what little PHP work I do these days. It makes me feel warm and safe.

YUI 2.8 Uploader

I know this is old but I finally tried upgrading my uploader implementation at http://tivac.com/upload/ to YUI 2.8. Ran into some nasty problems where the SWF would never fire its contentReady event.

Turns out, it’s a known issue with the Uploader component in YUI 2.8 and it’ll be fixed in the next patch release.

Important Issue: Due to a current bug, the current version of uploader.swf hosted on yui.yahooapis.com in the YUI 2.8 branch is NOT compatible with the uploader.js hosted on yui.yahooapis.com. Until the next bugfix release, you can work around this issue by either locally hosting the older version of uploader.swf (available here), or locally hosting the uploader.js and making the following changes to it:

  • On line 509, in swfObj.addVariable(“elementID”, swfID);, replace “elementID” with “YUISwfId”.
  • On line 512, in swfObj.addVariable(“eventHandler”, “YAHOO.widget.FlashAdapter.eventHandler”);, replace “eventHandler” with “YUIBridgeCallback”.

That only had me frustrated for 5 minutes, thank god I read the documentation.

Arena.net

While I don’t work on the team responsible for the Arena.net site I help out all over the company wherever I can. When it was decided that the old site needed to be updated I got the call. After some discussions around what exactly the site should encompass it came down to wanting to have the site be an aggregator of updates by arena.net on various different services.

Here’s the rundown:

I certainly wasn’t looking forward to building parsers for the multiple different feed types that entails, but YQL came along and saved the day again. I only had to do simple things manually like make sure that Twitter links & @username replies were properly wrappped in <a> tags. To keep from bashing on YQL every time the page is loaded it stores the transformed results of the updates for an hour in a local APC cache. This provided the best of both worlds and made caching super-easy.

The site itself was built using YUI grids, YUI 3b1, and DD_belatedPNG to solve transparent PNG issues in IE6. It’s also using my favorite new PHP framework, Nice Dog. It’s a nano framework (about 100 lines) that is more of a VC than MVC. For a site like Arena.net it’s perfect as there’s no need for models. I could’ve plugged in an ORM to make it the full stack but when getting all your data is as simple as

apc_fetch($key);

the need to build a “proper” MVC site kinda isn’t there any longer.

PatCavit.com

Sunday morning I had a few too many skittles after waking up and decided I wanted to build an actual landing page on patcavit.com

So then I started on it, I had grand plans. There were even icons that I was going to grab from… somewhere. That part of it was rather poorly planned. After doing the basic layout I spent about an hour trying to find the right icons. Eventually I threw up my hands and just dropped the whole idea.

Here’s what I’d planned for it to look like:
052520091392.jpg

Notice my awesome hand-drawn icons… :(

Today I was feeling more up for a challenge though. I did some reading and decided to use YQL thanks to Chris Heilmann’s screencast illustrating how he used it to pull multiple sources of data together. After deciding to just ditch the icons I picked a few colors for the top-level sections instead, and here’s what I came up with.

patcavit.com.png

I like it well enough. Still wish I could’ve found icons I was happy with.

YUI Uploader Updated

The uploader I wrote and talked about in YUI Upload Implementation has been updated to work with YUI 2.6.0 and also with the new Flash security rules for browsing files. The changes were relatively minor, but here’s a quick explanation.

A new element had to be added that could overlay the button that lets you select files. Once the JS fires it makes that element the exact same size/position of the button you can see and then the YUI Upload fills that overlay with a flash object. While the button still exists when you click the event is actually captured by the flash object. This gets around the tighter flash security rules while not changing the upload experience at all. It’s not a perfect solution but at least the uploader works again.

Changed code looks like this in upload.js

var button = YUD.getRegion('browse');
var overlay = YUD.get('btn_overlay');
YUD.setStyle(overlay, 'width', button.right - button.left + "px");
YUD.setStyle(overlay, 'height', button.bottom - button.top + "px");
YUD.setStyle(overlay, 'top', button.top + "px");
YUD.setStyle(overlay, 'left', button.left + "px");
this.uploader = new YAHOO.widget.Uploader('btn_overlay');

Updated uploader still lives at http://tivac.com/upload/

Xbox Live Friends 1.3

In a fit of inspiration I’ve updated the xbox live friends gadget with offline friends and hopefully taken care of the phantom friend problem in a more thorough way. Also went ahead and added a refresh button because two minutes is apparently too much time for some people to wait.

Pictures!

You know what time it is!

Download the gadget

Quick Vista Gadget Development Note

This is more of a reminder for me than anything else, but since I kept searching for this tonight with little luck maybe somebody else will get some use out of it.

When developing a Vista gadget it can be realy useful to set up a gadget folder somewhere other than “%userprofile%\appdata\local\microsoft\windows sidebar\gadgets”. Unfortunately to have the sidebar notice it you’ll need to symlink it. That’s a pretty easy process, and note that just making a shortcut to the folder WON’T WORK.

  1. Open an explorer window to %userprofile%\appdata\local\microsoft\windows sidebar\gadgets
  2. Open a cmd prompt with elevated privileges (start, “cmd”, shift right-click, run as admin)
  3. cd in cmd to %userprofile%\appdata\local\microsoft\windows sidebar\gadgets
  4. mklink /D "Gadget Name.gadget" "c:\path\to\development gadget"

That’ll set up a symlink so you can edit your gadget wherever you want and still have Vista add it to the gadget browser. Handy for those of us that like having all our programming projects in one spot.

Tweaking the Image Uploader

For fun I went trolling through the images people have uploaded via the YUI Uploader implementation I wrote a while ago. When it took my browser a solid 30 seconds to even be remotely responsive and start rendering images it struck me that perhaps it was time to paginate the images instead of just dumping them all out onto one page.

So I added pagination. It’s currently super simple which makes for easy explanation. The PHP still collects and sorts every single image in the directory by date. I don’t think there’s any other way to do that. Afterwards it checks to see if the “o” query param was set and is an integer (thanks for adding filter_input to PHP5, PHP devs!). Once there’s an offset to start from, it slices the array at that point and takes the next 50 images.

After that there’s just some simple logic around drawing the pagination numbers and figuring out which one is the current page. The numbers are centered and boxed using a variation on Hedger’s inline-block work (Item List Grid : Practice with display:inline block across browsers) that I worked on for the next VYC release. It solves the problem with a minimum amount of code in a really semantic way that just makes my web developer brain as happy as can be. Granted the CSS is not what I would call “pretty” but it works everywhere and is not impossible to understand, so I’m not too bothered by it.

So here’s how it turned out. Be forewarned that I don’t control what is uploaded here, and as such there might be NSFW content on this page!

http://tivac.com/upload/images/

Xbox Live Friends Sidebar Gadget 1.2

I’ve had this sitting on my hard drive for quite some time. I think there was something else I wanted to do with it, but I’m not really sure.  It’s been running pretty well for me for months though, so I think it’s about time I released it!

Version 1.2 has a bunch of small fixes in it and some cleaned up graphics. There’s some issues with the API I’m hitting causing ghost friends to show up, not much I can do about that. I’m also noticing some weirdness with the scroll bar in the config panel. It’s not worth fixing right now.

You know what time it is!

Download the gadget

Xbox Live Friends Sidebar Gadget

What’s the problem?

Knowing when my friends are online on Xbox Live has been a problem I’ve struggled with for years. When Microsoft announced the Xbox Community Developers program I thought I had found the answer. Then the recipients of the 50 API keys they gave out promptly made a bunch of websites I couldn’t care less about…

Except for 360voice.com (<3 their RSS feeds, I’m right here). I really like the daily summaries that pop up into Bloglines, it’s cool knowing what games I should get so we can play more.

But even 360voice doesn’t handle the status info I was interested in. There’s no good way to have a list of my friends updating in the background so I can tell with a glance who is online and whether or not I should join them. Plus there’s the hassle of actually getting someone else to sign up for it, so far I think all of 3 or so friends of mine are on there.

The other issue is one that isn’t anyone’s fault, per se. I don’t want to have to open a webpage to know who is online. The Xbox.com friends page is certainly easy to read, and it sticks all your friends at the top so you can scan it quickly. It still suffers from the fact that I have to actively go to it if I want to see who is online. I could hook up one of the Firefox extensions that checks a page for updates, but that still isn’t what I’m looking for.

That sounds like it should work…

So how do I get an unobtrusive, automatically updating list of my friends to sit on my desktop so I know at a glance who is online? Well I’m rocking Vista and dual-monitors, so I fired up the Sidebar and added the Xbox Friends WatchXbox Friends Watch gadget. It’s doubly neat because it not only does what I want but it uses Silverlight so there’s lots of fancy animations and the like.

I was pretty happy with this solution for a while, but it’s still not quite right. Despite me having more than 5 friends on Xbox Live, I can’t get updates for them. The gadget will happily add them and even appears to render them on its list, but it doesn’t support scrolling of any sort. You can kinda mouseover the very bottom and see the highlight travel to the other people on your list, but you’ll never know if they are online or not. Adding gamertags to it wasn’t the easiest thing in the world either, as the settings dialog expects tags to be commas-separated , which I always found to be pretty clunky.

Like I mentioned, the hard limit of 5 gamertags wasn’t a huge issue for me and I was happily using the Xbox Friends Watch gadget for several months. Eventually though I was having to swap people in and out of the list on a pretty regular basis, depending on which group of friendXbox Friends Watch Configs I was going to try and play with next. It didn’t make sense to me that I would have to do that, so I went looking to see if there were any other options out there.

Not quite, next!

The closest I found was Duncan MacKenzie’s Xbox to Twitter application. It’s very cool, and something I contemplated running for a while before deciding that I spammed Twitter (and Facebook, thanks to the Twitter App) and people probably wouldn’t care that much. Besides, I’m not looking for ways to broadcast to other people that I’m online, I want a way to keep tabs on my friends and know when they’re online.

So Xbox to Twitter wasn’t what I needed, but it did get me the hook I needed to be able to solve my problem. As part of his twitter app Duncan also put up a Webservice API you can hit to get Xbox status info for a gamertag. Even better, he put up a REST version of it that you can hit using plain old HTTP. It’s super simple, check this out:

http://duncanmackenzie.net/services/GetXboxInfo.aspx?GamerTag=Tivac

<?xml version="1.0"?>
<XboxInfo xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <AccountStatus>Gold</AccountStatus>
  <PresenceInfo>
    <Valid>true</Valid>
    <Info>Last seen 58 minutes ago</Info>
    <Info2 />
    <LastSeen>2008-04-14T15:42:05-05:00</LastSeen>
    <Online>false</Online>
    <StatusText>Offline</StatusText>
    <Title>www.xbox.com</Title>
  </PresenceInfo>
  <State>Valid</State>
  <Gamertag>tivac</Gamertag>
  <ProfileUrl>http://live.xbox.com/member/tivac</ProfileUrl>
  <TileUrl>http://tiles.xbox.com/ti...8M6cr.jpg</TileUrl>
  <Country>United States</Country>
  <Reputation>99.98135</Reputation>
  <ReputationImageUrl>http://live.xbox.com/xweb/...gif</ReputationImageUrl>
  <GamerScore>12860</GamerScore>
  <Zone>Recreation</Zone>
  <RecentGames>
    <XboxUserGameInfo>
      <Game>
        <Name>Halo 3</Name>
        <TotalAchievements>49</TotalAchievements>
        <TotalGamerScore>1000</TotalGamerScore>
        <Image32Url>http://tiles.xbox.com/tiles/oo/P5/0...</Image32Url>
        <Image64Url>http://tiles.xbox.com/tiles/zS/3N/1W....jpg</Image64Url>
      </Game>
      <LastPlayed>2008-04-10T00:25:48-05:00</LastPlayed>
      <Achievements>25</Achievements>
      <GamerScore>770</GamerScore>
      <DetailsURL>http://live.xbox.com/en-...o=tivac</DetailsURL>
    </XboxUserGameInfo>
    ...
  </RecentGames>
</XboxInfo>

A little hard to parse in this format, I know. Hitting that URL in your browser will make it easier to understand though. I also shortened all the URLs and removed a the previous 9 games I had played because honestly, it’s not that interesting and it makes the XML way longer.

This is it though, the data that I needed to solve the problem of “I want to know what friends are on Xbox Live” (at least for me!). All I needed to do was to figure out how to use that info. Reaching back into the depths of my memory I recalled my previous attempt at building sidebar gadgets (http://patcavit.com/2007/05/04/vista-gadget-headaches/) and how I in fact had tried to build this very gadget once before. Except it failed horribly because I couldn’t automate a Windows Live login. Well wonder of wonders, with this API I don’t have to!

Finally, some progress!

So after a few days of hacking in JavaScript and PHP I’ve got a sidebar gadget that takes a list of Xbox gamertags and will update to let you know when any of them are online. It even uses the cool Gadget Persistent Storage library to store your list of gamertags when you remove and re-add the gadget. A lot of this is powered by a small subset of YUI because programming JS without it is too painful. Specifically I’m using Reset, DOM, Event, JSON & Connection.

There are of course some caveats to this, but there always are.

Getting a list of gamertags isn’t automated. I’m not even sure the people who have direct access to the Xbox Community Developers Program ever got this capability. I doubt it. It means that for now you’ll still need to input a bunch of gamertags by hand. Fortunately this list is newline separated, so it’s very quick to add a bunch of them. I’ve got some stub code in there to parse it from a copy/paste of your Xbox.com friends management page, but it isn’t ready for anyone to actually use yet.

  1. It violates Microsoft’s Gadget UI Guidelines, in that gadgets shouldn’t change size on anything other than a click. Mine does automatically depending on the number of people online. It could even conceivably become taller than your monitor. Microsoft is definitely right about this and I think it sucks, but I didn’t figure out a clean way of paginating the data that could stand. This is something I’m going to work on in the future, but for now it’s crappy.
  2. There’s no undocked state. More accurately, it’s the exact same docked to the sidebar and undocked. Ideally it would expand a bit to shower bigger icons, larger text, and gamerscore (at a minimum) when you undocked the gadget. That’s on the list of things I’d like to do someday, but since I never use the gadget undocked is pretty low priority.
  3. There’s still some weird behaviors. Here’s the ones I know about.
    1. Sometimes the requests to the server for user info just take forever and return empty.
    2. Opening a new flyout when there’s already one open causes the flyout to lose focus until you click on it. This appears to be a Sidebar/Gadgets limitation so it’s unlikely to be fixed.

Still, it works like I need it to which is really the only important thing! I’d love to have some other people use it and give me feedback though. I’m always down for hearing about bugs as well, though no promises that they will be something easily fixable.

It’s not the prettiest thing in the world, I’ve modelled it after xbox.com and the flyout details are powered by the Embeddable Gamercards offered on xbox.com. Here’s an example of the what those look like

Put your gamertag here too.

It’s lazy but it gets the data I want in there without a lot of hassle on my part. In the future I would like to have a nicer flyout more akin to what Xbox Friends Watch has. Unfortunately, that’ll be a a good chunk of work to get the interactions right so that’s a challenge I’m putting off for another day. I don’t even really use the flyouts in my day to day gadget usage, but it’s nice to be able to interact and get a bit more information.

As usual I’ve written way too much and not posted enough links to just get the damn thing, so here you go!

Xbox Live Friends Gadget 1.0