PHP double equals vs. triple equals on a number and string

During development of a new, yet to be named, client site we're passing JSON to PHP and converting the JSON to XML for passing off to a final API endpoint. My initial PHP didn't have support for attributes, so I figured I would just go on and add it. Simple enough. So I made a special case that says: If you see a key that is equal to the string "@attributes" don't create a node, it should be processed as an attribute list. However, I ran into an issue that stumped me for a bit. It was skipping the entire JSON.

Can you see the bug in this code:

It turns out that if $key is a number it will pass the condition.

Run this code:

Expected:

NO
NO

Result:

YES
NO

Strangely enough this only seems to work with zero. I tried "0" (with quotes) and other numbers, but the result is always the expected one "NO NO". There's a reason why developers always recommend using triple equals.

If you're doing cross domain pixel tracking, don't forget to set your P3P header for IE support.

Recently we launched a financial focused media network. For auditing purposes we need to cookie users to see how well our publishers are converting and to prevent fraud. Unfortunately, for the past few days there's been a bug where our analytics dashboard wasn't reconciling the data between impressions and clicks.

During troubleshooting we found that the session cookie wasn't being sent back in nearly 50% of the time when someone clicked. Now it's always possible for some people to go directly to a click without an impression, but not half our clicks!

After a few days of debugging we've finally isolated it to a problem with Internet Explorers default privacy settings. By default IE blocks cookies from being accepted unless they specify a privacy policy. Regardless of the fact that P3P is a dead standard, it's the simplest way around the cross domain issue. This is an issue for anything cross domain (i.e., third party), such as iframes.

Rookie mistake!

Screen

Get the number of words in a Wordpress post (in your code!) - And help increase your unique content!

Google doesn't like short posts. If we have a post less than 300 words we want to either no-index or remove some of our duplicate content, so google's algorithm will show a higher percentage of unique content. Our template "single.php" is duplicated across all our posts, so it's technically duplicate content in google's eyes.

And then in our single.php and sidebar.php use $short_post to exclude certain parts of your content.

ReferenceError: java is not defined - Mac OS X - Firefox 4, 5, 6, 7+

For grabbing screenshots we often use iOpus' wonderful Firefox plugin iMacros. Today I opened an old macro and it failed to run. It turns out that it uses the global java object (via LiveConnect) to read and write files, and the global java object was no longer available.

Other error message you may see include, "ReferenceError: java is not defined (Error code: 991)" from iMacros, or simply "ReferenceError: java is not defined" from Firebug or the browser itself.

The simple solution is to check "Enable applet plug-in and Web Start applications" in the Java Preferences app. Use spotlight to find it.

Screen_shot_2011-10-25_at_2
Then restart Firefox and try to run the macro again and it should work. If you're using Firebug, you can easily test to see if it's installed correctly by typing "java" into the console. If installed you should see "[Java Package "java"]" as output.

Screen_shot_2011-10-25_at_2

Theories why this happened? Most likely it's because Java for browsers is disabled by default in Mac OS X Lion, so I only noticed this after I upgrade from Snow Leopard.

Another source that confirms my suspicion:

http://sniptools.com/mac-osx/making-java-work-in-browsers-on-mac-osx-lion

Turn Off New Facebook Chat

Update: The old method won't work. Here's the new method to kill Facebook chat. The solution is to...

First, Click on "Try It Now" in the chat area.

Screen-shot-2011-07-10-at-9

Second, In the options drop down unselect "Available to Chat".

Screen_shot_2011-07-10_at_9

 

Original post:

I logged in to my Facebook account tonight and found that I was also logged into chat. I really hate chat, so I searched how to turn off the new Facebook chat. It's really simple, so I hope that Facebook doesn't kill this link. Also, all your chat messages are stored in your inbox.


First, click on this link:
http://www.facebook.com/presence/popout.php

Second, click on the options drop down and go offline!

Screen_shot_2011-07-10_at_9

Bye Bye FB Chat!

Whatever you do...

Do not click on the chat area at the bottom of the screen or you'll be logged in again!

Screen_shot_2011-07-10_at_9

3 Options for Upgrading to the Asynchronous Google Analytics Tracker Code from the old pageTracker

I ran into an issue last night when I went to upgrade to the new Google Analytics asynchronous tracking code. It turns out that the pageTracker object no longer exists as a global variable.

Instead of using pageTracker._trackEvent(...) to track events, you must instead use _gaq.push(['_trackEvent', ...]).

There are three different options I could have chosen. I ended up choosing the last option.

1. Rewrite all my old pageTracker code to use the new syntax. I.e., change pageTracker._trackEvent(...) calls to _gaq.push(['_trackEvent', ...]);

2. Recreate the pageTracker (which I never verified if this code actually worked)

3. Create a wrapper.

This is the option I went with for one simple reason. I already use a variation of this code for logging tracking events when I debug on my localhost. Here is my full version.

Job Posting on Craigslist is a Waste of Time

Craigslist is no longer an essential stop in my hiring process. I've been using it over the last few years with a few different companies, and have seen it get progressively worse. Just recently, I posted a job on Craigslist to fill a need for a web engineer position at AD:60. Over a week later and we have 19+ companies (on and off shore) and 1 woefully under-qualified applicant.

Hiring managers, does this look familiar?

Junkmail

What part of "Please do not contact job poster about other services, products or commercial interests." don't these spammers understand? Ok, so I've accepted the fact that I'll get spam from job posts on Craigslist. And, yes, hiring is hard. I accept that also. But all spam, and no one qualified?!

The worst part is that craigslist implies that it's much better than Monster and Career Builder for the price. I'd have more faith in that assertion if the studies they cite weren't from 2000 and 2006.

Are there solutions? Does Craigslist care enough?

I will admit one little secret though, I've got the best candidates from an impromptu post on Hacker News.