Jason Leveille’s Blog

Beauty’s where you find it

http_build_query arg_seperator

I have used http_build_query numerous times in the past and I’ve never had to pay attention to the third parameter before: arg_separator. I am making use of a great Curl wrapper to abstract some of the more mundane setup tasks associated with a Curl request. Initially I had constructed the setup of CURLOPT_POSTFIELDS as follows:

$url = 'http://rest-toolkit/api/users/5';
$response = $curl->post($url,
    $vars = array(
        'username' => 'baz',
        'password' => 'bar'
    )
);

...

curl_setopt($handle,
    CURLOPT_POSTFIELDS,
    http_build_query($vars)
);

Upon receiving the request, my script was showing $_POST variables as follows:

Array
(
    [username] => baz
    [amp;password] => bar
)

Thanks to a comment on the http_build_query page regarding the use of the third parameter, I quickly realized that my php.ini setting for arg_separator.output was in fact set to &. The quick fix:

curl_setopt($handle,
    CURLOPT_POSTFIELDS,
    http_build_query($vars, '', '&')
);

And the result:

Array
(
    [username] => baz
    [password] => bar
)

JavaScript Lazy Loading

I just finished a great Digital Web Magazine article about improving page load times with lazy loading techniques. The article (by Jakob Heuser) was very well written and described proximity, timeout, and event based lazy loading. If you continue to read you will see how I was able to reduce page load by 300+kb by implementing lazy loading.

What is Lazy Loading

Lazy loading, described by Martin Fowler in “Patterns of Enterprise Application Architecture”, is the process by which an object isn’t loaded with data until it is needed. Of course “needed” is subjective to the needs of your application (for example needed in proximity or based on an event). In the context of this article, Jakob Heuser was really talking about lazy loading JavaScript files when they are needed, as opposed to loading them on page load. The loading of the files happens via XHR (therefore the request is subject to the browser same origin policy). He provides examples of Gaia Online and Zimbra who both reduced their page load by 200k+ after implementing lazy loading techniques. Read the rest of this entry »

Installing Aptana on Ubuntu 8.04

Quick install guide for Aptana on Ubuntu 8.04.  Modeled after the Installing Aptana Studio on Debian guide found at the Aptana page for Installing Aptana on Linux.  The issue with the guide provided by Aptana (at least for Ubuntu) is that Ubuntu comes with FF 3 Beta 5 (as of the time of this writing) by default.  Aptana doesn’t play nicely with FF 3 Beta 5, and after what appears to be a successful install, spits back an “embedded browser not available” error.  Note: you don’t have to worry about uninstalling FF 3! Read the rest of this entry »

Rest Toolkit - User Defined Actions

This morning I got into work early (6:30am, which is early for me) and decided to add the ability to define special methods to Rest Toolkit (original blog entry). “Special” in this case means adding the ability to call specific methods which allow special processing for a resource. Read the rest of this entry »

DotNet isn’t Always Bad

I spend most of my time in PHP and JavaScript. Just the way I like it. 6 months ago I refactored a .net application from a codebase which originated in India. I’ve seen a lot of good code come from India, but this was some Ravioli code. Ultimately the client ended up happy, but I found myself cursing .net 4 days out of my 5 day workweek. Today I was asked to provide password reset functionality to a portion of the application. Because we made the decision early on to use ASP.NET 2.0’s membership service, adding the feature was as easy as dragging and dropping a PasswordRecovery login control. In a business where so much of developing an application is maintenance, this was really nice. There are a lot of things I don’t like about .net, but I thought this one deserved some accolades.

I recently finished my first CakePHP application.  Not only was the application the largest I have ever written, but I had never worked with CakePHP before.  So, needless to say, not only did I have to overcome a learning curve, but I had to deal with all that comes with writing a large application.  Today I was contacted by the project manager regarding a bug which had surfaced in the application.  In my quest to squash the bug I discovered a script which was causing a section of the administrator to act very sluggish.  In examining exactly what was going on, I realized that there were 200+ calls being made to the database.  Ok.  That’s bad.  I’d like to clarify that I was the one who wrote the original offending code.  In about 2 minutes of work I was able to bring the query count down to 2, and reduce the page response time considerably. Read the rest of this entry »

I have taken some time to refactor my original implementation of Depth First Search and Iterative Deepening in JavaScript. Namely, I removed any dependencies on the ExtJS JavaScript library, and added dependencies to the jQuery library. The advantage here is that the combined size of the files is now < 60k, whereas the original implementation was needlessly around 500k.

The Goodies

Read the rest of this entry »

Displaying The Correct Timezone Time

Yes, I know, displaying the time with JavaScript. Something that’s been written about since the dawn of time. Following is a trivial bit of code, but one that I thought others might find useful. We are working with a client whose application broadcasts meetings (and screen captures from those meetings) to client computers. A very cool project that I’d like to write about some day. With regard to time, there are 2 requirements:

  1. Time must be in Eastern Standard Time (or Eastern Daylight Time)
  2. They shouldn’t have to configure any settings to adjust for daylight savings time

Read the rest of this entry »

The Power of Virtualization

I’ve spent a considerable amount of time lately creating virtual machines on my work and home computers. In an effort to come up with a set of environments that make developing and testing applications easier I initially setup Microsoft Virtual PC 2007. In the few weeks that I’ve used it I have found that I need more than just Windows options in my virtual environments. This weekend I decided to give VMware Server a test drive … and just as quickly decided to uninstall MS Virtual PC. VMware Server is a free download, and according to the vmware website:

VMware Server installs on any existing server hardware and partitions a physical server into multiple virtual machines by abstracting processor, memory, storage and networking resources, giving you greater hardware utilization and flexibility. Streamline software development and testing and simplify server provisioning as you utilize the ability to “build once, deploy many times.”

Read the rest of this entry »

My Classes Back Online

It only took 6 months or so, but I have finally taken the time to get my old teaching site (http://my-classes.org) back online. When I was teaching I knew that a lot of people were visiting the site, specifically for the assignments that I had posted online. Believe me, teachers are always trying to find good lesson plans. After the 5th email this week regarding when the site would be back I finally broke down and found the time.

Thanks to my employer, Blue Atlas Interactive, for providing the hosting, not only for this blog, but now also for my-classes.org. Thanks to Dave for taking the time during work to get me the root shell password and my ftp information.