Counting to 1000 in PHP without loops or conditionals

Posted March 14th, 2011 in PHP by Andrew Curioso

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.

Continue Reading »

FreePriceAlerts.com

Posted March 10th, 2011 in Portfolio by Andrew Curioso

FreePriceAlerts.com is a set of tools that help people save money while they shop.

It was originally built on technologies developed for myVBO but has grown to something much more. Some of its features are:

  • An advanced pricing engine that quickly finds the best prices from all over the Internet.
  • Toolbars for Firefox, Safari, Chrome, and Internet Explorer.
  • A mobile website.
  • Wishlists that users can create and share.

My own contributions to the project include:

  • Collaborated on the user experience and architecture design from the project start.
  • Developed a product processing infrastructure capable of handling tens of millions of products a day using Gearman as a job manager along with XSLT, AWK, Lex, and Yacc.
  • Designed a RESTful API for use by all client applications.
  • Partner integration.
  • Designed a scalable cloud based multi-tier infrastructure.

AccessiblePlaces.in

Posted March 10th, 2011 in Portfolio by Andrew Curioso

I had the pleasure of attending the Boston Hack Day challenge in 2011. I came without any ideas of my own. Instead, I was looking to help a team that was working on something cool and genuinely good for society. I was not disappointed.

AccessiblePlaces.in is a crowd sourced website that helps people with disabilities discover places that are accessible to them and anonymously share their experiences with other people. It is optimized to be quick and easy to use on both a mobile phone and on a computer.

AccessiblePlaces.in was conceived and launched during a 48-hour hack-day in Boston sponsored by the Boston Globe and Boston.com. The team consisted of Anthony Deaver, Sam Bisbee, and myself. In total, 32 teams competed. At the end of the weekend the project was fully working and it was awarded “Best Geo-Location Hack.” It only came extremely close to being the audience choice award (only a couple votes off).

The site was built using jQuery Mobile for the interface. On the back-end, PHP and CouchDB were used. It was built from the ground up to have an easy to use RESTful API and stores data that is compatible with the Open Civic Data standard.

I was able to flex my creative muscles a bit. My personal contributions included designing the logo, writing the copy on the Boston Hack Day wiki… and of course a little PHP and Javascript.

The project later went on to be a finalist for a 2011 MITX Innovation Award in the “Doing Good” category. Although my direct involvement with the project was limited to the Hack Day, I am happy to have helped with such a worthy project.

RIA: Desktop Notifications in Google Chrome

Posted January 27th, 2011 in Javascript by Andrew Curioso

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.
Continue Reading »

My 2011 New Year’s resolutions

Posted January 17th, 2011 in Personal by Andrew Curioso

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:
Continue Reading »

Error handling stack in PHP 5.3+

Posted October 13th, 2010 in PHP by Andrew Curioso

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.
Continue Reading »

Welcome CakeFest 2010 Attendees

Posted September 4th, 2010 in PHP by Andrew Curioso

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!

Authentication vs. Authorization

Posted July 14th, 2010 in Security by Andrew Curioso

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.

Continue Reading »

CakeFest 2010 – Chicago, IL

Posted June 24th, 2010 in Portfolio by Andrew Curioso

CakeFest is an annual gathering of CakePHP developers. The 2010 conference was held in Chicago, IL on September 2nd and 5th.

I presented a talk on API Development.

Continue Reading »

Detecting file size overflow in PHP

Posted June 9th, 2010 in PHP by Andrew Curioso

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.
Continue Reading »