The high tech scene in New Hampshire

As many of you know, I moved to New Hampshire a couple years ago from Boston.

It’s not as big a move as it sounds. I can still get to Boston in 45 minutes if traffic permits me. Plus I have all the fresh air, hiking, biking, and great restaurants I want.

But it is a huge move in terms of developer community. I find myself routinely driving to Boston for the always great Boston PHP meetup but most other meetups I dropped entirely because I can’t justify the commute. Read more ›

Tagged with: , , ,
Posted in World

Counting to 1000 in PHP without loops or conditionals

Update: added a benchmark for performance comparison and updated the code to no longer rely on a fatal error to exit.

It started with one question:

Print numbers from 1 to 1000 without using any loop or conditional statements. Don’t just write the printf() or cout statement 1000 times.

How would you do that using C or C++?
Source: Stack Overflow

My favorite answer was an amazing example of obscure C. Using math to iterate between two function pointers (printf and exit). And while it brought back memories of my C days, I kind of left it at that.

Later in the day, one of my co-workers messaged me with his version of a 1-1000 iterator in PHP. So naturally, I had to write my own version.

Read more ›

Tagged with: ,
Posted in Code

RIA: Desktop Notifications in Google Chrome

I’ve seen a number of blog posts floating around today about GMail Desktop Notifications (here, here, here, here and here — did I miss anyone?). I tried them out myself and they are very useful. Being a rich web applications developer I, of course, wanted to figure out how it works and how I could use it for my own apps. Here’s a quick overview of what I found.
Read more ›

Tagged with: , ,
Posted in Code

My 2011 New Year’s resolutions

I haven’t written a blog posts in a while so it figured a good start might be to make some resolutions for myself in the new year (yes, I know that January is almost over).

Here are few things I want to improve:
Read more ›

Posted in World

Error handling stack in PHP 5.3+

Update: this article is mentioned in a few places as a practical example of using closures.
Some languages pass variables into a closure automatically. In PHP it needs to be done explicitly using the use keyword. See line #6 of the code example.

I was inspired by a question that I was asked on Twitter to write a quick code snippet.

As you may know, set_error_handler can be used to set a custom error handler in PHP. It will catch any errors that happen in the script (with a few notable exceptions). If the function returns false then error handling resumes as normal; otherwise it is assumed that the custom handler took care of things. The problem is that you can only have one error handler active at one time. The purpose of this code is to provide a error handeling stack for PHP.

Using this code you can have more than one error handler while taking advantage of the set_error_handler function.
Read more ›

Tagged with:
Posted in Code

Welcome CakeFest 2010 Attendees

I noticed a spike in my traffic which can only mean one thing: welcome, CakeFest attendees, to my home on the web!

When conference day two roles around you’ll be able to find all my presentation notes here and I will be uploading the slides as well.

As you may know, I will be talking on API Development with CakePHP. It is a complex topic so my presentation won’t be the end of it, I will be adding additional information over time. So I hope that you subscribe to me via RSS.

Happy coding!

Posted in Uncategorized

Authentication vs. Authorization

This seems like a no-brain-er but I have seen it more times than I can count and I have seen it happen to some very experienced developers. Put simply: authentication is not enough; you need to make sure that the authenticated user is actually authorized to perform an action. It is one thing to know who a user is and an entirely different — though equally important — thing to know what a user is allowed to do.

This article covers the concepts of authentication and authorization.

Read more ›

Tagged with: , , ,
Posted in Code

Detecting file size overflow in PHP

One of the things that separates a good web application from a great one is how gracefully they handle failures. One of the often overlooked cases is when a user attempts to upload a file that exceeds the set PHP upload file size. This article shows how to detect when the user tries to upload a file that is too large and display an appropriate message.
Read more ›

Tagged with: ,
Posted in Code

A method called ‘delete’ in Flex and AS3

You are in for a headache if you have try to call a method or create a member variable with the name of a reserved word in Actionscript. It can lead to such fun situations as having variables called: insert; update; deleteSomething. Because calling the third variable “delete” may be logical but it is a reserved word so that is out of the question. It gets hairier when you don’t necessarily have control over the object format (such is often the case with remote calls). I ran into this today when trying to call the “node_delete” (or “node.delete”) method in Drupal via Services and AMFPHP. This is frustrating so I’m going to show two situations where you could run into this problem and how I fixed them.
Read more ›

Tagged with: , ,
Posted in Code

5 things about PHP 5.3 that make me smile

Rest assured. Soon I will be writing “Things about PHP 5.3 that make me cringe” but for now I sing the praises of the latest release of PHP that that came out today. I’ve been playing with the new release for months and there are indeed many good things about it and many of them have been a long time coming.

The other day I was reading the release notes and I couldn’t help but smile.
Read more ›

Tagged with: ,
Posted in Code