Author Archive

Using Google-API-PHP-Client with Google Analytics Core Reporting

Thursday, December 22nd, 2011
No Gravatar

Google’s PHP client library for their GData API hasn’t received as much love as their client libraries for other languages. Despite the lack of high level service classes for Google Analytics’ Core Reporting API it is possible to work with it using google-api-php-client.

The below is a quick and dirty self contained example based on a Google+ example to get a report. Before you get started go to the API Console and enable access to the Analytics API and generate a client id, client secret, and to register your redirect uri.

Third Party On-Site Search Tools

Wednesday, December 21st, 2011
No Gravatar

Here at the Web Shop, we like to take advantage of existing tools, whether they’re free or reasonably priced. One tool that we opted to not roll on our own is a site search. From time to time clients require them and the first third party search tool so used was Google Custom Search. It’s pretty expensive considering how much traffic site searches tend to get and it behaves oddly, especially with sites that aren’t well indexed.

Keep the Currency Out of Your Templates

Thursday, November 24th, 2011
No Gravatar

I was recently tasked with creating e-commerce sites for countries where dollar signs don’t apply. Symfony’s I18N support was great for translating strings but proved to be inadequate for formatting currency. Having only used our e-commerce software to display currency in either American or Canadian dollars I had to first remove all hard coded dollar signs from our templates and invent a generic way to display currency for different regions.

Symfony’s format_currency() almost gets the job done, so I created a helper which augments its output. There’s nothing fancy here. You can add a currency indicator on either the left or the right of the currency, and if neither a left or right currency indicator are configured, we default to showing a dollar sign.

A class to take PHP shell scripting to the next level.

Thursday, November 3rd, 2011
No Gravatar
Are you familiar with PHP? Do you find Bash shell scripting to be a special form of torture? If you answered yes to the previous questions then you are in for a treat. I’ve written a class to help make shell scripting in PHP much nicer. Here’s the list of features that were important enough to me to bother including in the class:
  • Return Code Checking
  • Parameter Escaping
  • Streamed Output
  • Exceptions
  • Object Oriented
  • Fluent Interface
Let’s get right into some examples. Here’s basic command:
Cmd::create()
  ->setCmd('ls -l')
  ->exec();
Want to allow for a variety of return values?

95fe20cccbfccbb1a2fe43f70eceb232003

jQuery 1.7′s New Simplified Event API

Friday, October 14th, 2011
No Gravatar

This is just a quick heads up if you haven’t been following the jQuery blog. jQuery has added two new functions: .on() and .off(). We’ve seen this syntax before in other libraries like YUI and it’s clear and concise. These new functions infer whether to use .delegate(), .live() or .bind() based on the parameters passed to it.

From the jQuery blog:

Old API New API
$(elems).bind(events, fn) $(elems).on(events, fn)
$(elems).bind(events, { mydata: 42 }, fn) $(elems).on(events, { mydata: 42 }, fn)
$(elems).unbind(events, fn) $(elems).off(events, fn)
$(elems).delegate(events, selector, fn) $(elems).on(events, selector, fn)

Compressing Transparent PNGs for the Web

Thursday, August 11th, 2011
No Gravatar

Today is a very exciting day: HTML5 Boilterplate v2 came out and I discovered that transparent PNGs don’t have to be massive.

There was one change from h5bp from v1 to v2 that would be easy to overlook: “We feel tools like imagealpha and pngquant, and techniques like using 8-bit PNGs are more useful than using stopgap fixes like belatedpng.”

What’s this? pngquant? Huh? It turns out pngquant is an OS X only GUI for pngnq. What is pngnq? From the pngnq website: “Pngnq is a tool for quantizing PNG images in RGBA format.” I don’t know what that means but it sure can make a difference in your transparent PNG’s file size.

Browser Image Scaling

Thursday, May 5th, 2011
No Gravatar

We’ve recently had a request to have an image on a webpage that would scale to the full width of the browser window. Generally we avoid this sort of thing citing poor browser  image scaling as the reason. However it’s a trend on the web and so we must investigate! I set out to see how various browsers cope with both scaling images up and scaling images down.

In each of the tests below you can compare how an image scaled by the browser compares to an image scaled by Photoshop by dragging the vertical line left or right.

Simplifying the drawing of forms in Symfony

Friday, February 18th, 2011
No Gravatar

Implementing forms in 2011 is still a challenge, even with a framework like Symfony helping you along. sfForm is great for defining widgets and validators but it sucks at outputting practical markup.

Practical Markup

For me, the ideal markup for a form field looks like:

This gives me a lot of flexiblity for styling. Unfortunately I was never able to find a way to acheive this using formatters, and so I continued on writing very verbose forms. Luckily I grew weary of this and decided to see if I could create a helper to ease the output of forms. The following is what I cam up with:

A JavaScript Implementation of Symfony’s url_for()

Friday, October 15th, 2010
No Gravatar

While developing a UI that makes heavy use of use of JavaScript I found myself sending and receiving Doctrine_Record‘s as JSON. It became tedious making URL’s available for various Symfony actions in JavaScript so I sought to find a way to create a helper like Symfony’s url_for() in JavaScript. This post describes how I made Symfony’s routing available in JavaScript.

Is NoSQL the future of databases?

Friday, August 13th, 2010
No Gravatar

Unfortunately the title of this post is nonsensical. NoSQL isn’t any one thing, it’s a broad spectrum of emerging technologies. NoSQL could be used to describe just about any data store that isn’t a traditional database, and it turns out there are many flavours of databases.

I haven’t used any NoSQL product personally but I have the answers to some important questions:

Are these database systems proven and used in large scale productions?

They sure are.

Do they provide advantages over traditional RDBMS’s?

In some cases they are very interesting, in others there is debate as to whether they’re the right tool for the job.