Restoring Missing or Empty Environment Variables in PHP 5.3 for TextMate Commands

I am a big fan of TextMate and I am still learning to leverage its features, even after using it for over two years. I have started writing more “commands” to speed up my development process. I love that I can write commands in PHP that run locally on my Mac, and I still have access to all of the environment variables that TextMate passes such as the current line’s value or the document type and name.

The Problem

I recently upgraded to Snow Leopard, and as a result, upgraded to PHP 5.3 on my local development machine. I have been really impressed with the new features of 5.3, and I am happy it came packed with my OS X install. However, I noticed that a few of my commands had stopped functioning correctly.

I hadn’t had a chance to investigate the problem, but when I sat down to write a new command the other day, I figured it out. The $_ENV variable is an empty array on a default Snow Leopard install. When running PHP from the command line, this global variable holds all of the data about the environment PHP is running in. It’s also how TextMate injects it’s variables into the PHP script.

Continue reading

Posted in Development | Tagged , | 2 Comments

Round to the Nearest Half in Php

Sometimes, you want to round a number, but you want the nearest half instead of a full number. For example, if you have an average rating, and you want to display a star graphic representing the number of stars. In the interest of simplicity, you would like to show only full or half stars (3.5 stars instead of 3.43 stars). Here is a very simple example of how to do this in php.

$average = 3.43;
$round_to = 0.5; // you can change this to any increment you like
$rounded = round($average / $round_to) * $round_to;

The variable “$rounded” is now set to 3.5.

Posted in Development | Tagged , | Leave a comment

Compiling Pngcrush on Mac OS X Snow Leopard

Pngcrush is a command line tool that processes png files through several algorithms (read “magics”), optimizing the png without quality loss. Here is how you can install it from source on snow leopard. Continue reading

Posted in Development | Tagged , , | Leave a comment

Google Links Directly to Content Sections Inside Search Result Snippets

Google announced that they have added a new feature to search results. The brief summary in a result may contain links to specific sections of content on the page. This helps get a user directly to the most relevant content faster. For example, if I search for “jquery tabs”, one of my results looks like this:

Screenshot of Google Results with Content Links

Clicking “How To…” would take me directly to this portion of the page (http://docs.jquery.com/UI/Tabs#How_to…) instead of the top of the page (http://docs.jquery.com/UI/Tabs). I think that I will enjoy this feature quite a bit, and since most users do not scroll, this should get some dusty content a little bit of fresh attention. Continue reading

Posted in Web | Tagged , | Leave a comment

Fixing Pixelation from Scaled Images in IE

A project I worked on recently called for a carousel with five images of different sizes — somewhat like a “light” coverflow. I ended up building it with basic <img> tags that get scaled by javascript which modified the width attribute.

Cover Slider Layout Prototype

Cover Slider Layout

One of the problems that I ran in to involved the loss of quality from Internet Explorer 6 and 7 when the browser renders the image at a smaller dimension than the file.

Wired Cover scaled in IE

An image scaled in internet explorer.

This project was for a site that still has a substantial amount of visitors using IE6 (and IE7′s scaling abilities are not much better than 6). So I needed to come up with a way to correct the image scaling. A short google later, I found Ethan Marcotte‘s blog post Fluid Images [via Unstoppable Robot Ninja] and a post on flickr’s developer blog. Continue reading

Posted in Development | Tagged , , , | Leave a comment

Google’s Custom Search Engine: Unsung Hero of Search Tools

Sometimes you want to search for something, but only within a specific set of sites. For example, Smashing Magazine recently posted a list of 45+ Excellent Code Snippet Resources and Repositories. Occasionally, I find myself opening several tabs to search through a few of my favorite sites from this list in hopes that someone else has already figured out the best way to do something; so I decided to make a custom search engine.

Google provides an easy to use tool for building a “customized search engine” that only searches the sites you specify. Google Custom Search may not receive a lot of hype around the internet, but it is a very simple, yet powerful resource. Continue reading

Posted in Web | Tagged , | Leave a comment

Fever – My New Favorite RSS Reader

I was reading through my RSS feeds a few weeks ago and I came across a few posts referencing Shaun Inman‘s Fever app. I use google reader, but I often try alternatives. NetNewsWire is very powerful and Times looks clean, but neither of them worked for me as well as Google Reader. I decided to take the chance on fever and I haven’t looked back since. Continue reading

Posted in Web | Tagged , , , , , , , | Leave a comment

Using Selenium as a Development Tool

Selenium is a set of tools for web based unit testing. With a full implementation it has many advanced features, but the smaller and lighter IDE runs inside firefox. Using this arm of the suite by itself can serve as a convenient tool during actual development. Continue reading

Posted in Development | Tagged , , , , , , | Leave a comment