Today I Learned...

Fixing Textmate's PHP Commands with MacPorts PHP

Ethan's picture

For anyone else who's having trouble with include path errors when trying to run PHP-based bundle commands in Textmate like this one:

PHP Warning: require(/lib/beautify.php): failed to open stream: No such file or directory in /private/tmp/temp_textmate.4tD2ED on line 19

It looks like the problem has to do with php.ini configuration settings that ship with MacPorts (may be the production sample ini file, in particular). In order to environment variables to populate the $_ENV global that Textmate uses for settings, etc, be sure you've got the letter "E" at the front of the "variables_order" setting value, like this:

variables_order = "EGPCS"

Reluctant hat-tip to an article on Experts Exchange for this one.

Free Zip Code Database Import

Dan's picture

When you need a zip code database for the US you should get it from here
http://www.free-zipcodes.com/
But you shouldn't spend time trying to install all the required perl (sigh) libs needed to import it into MySQL.
Simply create the table structure

CREATE TABLE zipcodes (
       zipcode INT NOT NULL PRIMARY KEY,
       latitude FLOAT(10,8),
       longitude FLOAT(10,8),
       state VARCHAR(2),
       city VARCHAR(128),
       county VARCHAR(128)
);

Then fire up Sequel Pro. File-> Import. Set "Fields terminated by" to || and uncheck "First line contains fields names."

As a bonus Sequel Pro supports ssh tunneling out of the box so you can do it directly to firewalled DBs.

As always make sure you back up your DB first incase of failure.

How to make a Views "exposed filter" dropdown appear as checkboxes

Ben Buckman's picture

I'm using Views' "expose filters as a block" functionality in a custom search page. One of the filters is for content type, and users need to be able to select multiple options. Views can only generate multi-select lists as dropdowns, however, and the designs require checkboxes. Using a hook_form_alter to flip the #type from 'select' to 'checkboxes' fails because the form API structures those so differently. The views_filter_pack module claims to be able to convert from one to the other, but is extremely over-engineered for this purpose. Some searching around showed that other people had the same problem but no solutions seemed to work.

Then it dawned on me that I didn't need Drupal or Views to use checkboxes, I just needed the browser output to be rendered as checkboxes.

Safari Flash Cache

Dan's picture

If you are having trouble getting rid of a stale .swf with Safari
open ~/Library/Caches/Metadata/Safari/History/
Delete files at will then clear the Safari cache and reload.

UPDATE:
I found iPurge Safari Cache

Which does the trick!

Today I learned: about max() array magic

Ethan's picture

Today I learned:

  1. That there's always more tricks in the PHP bag
  2. That the max() command will return the element with the highest-value key when returned an associative array. So, given $a = array(1 => "red", 5 => "green", 10 => "blue");, max($a) will return "blue".

Using SVN Merge for Dev-Prod Web Deployments

Ben Buckman's picture

We use Subversion (SVN) to manage our code, and typically branch the code from 'dev' to 'prod' at launch time, with each project's tech lead determining the best way to manage the two repositories in parallel for subsequent development. SVN, like any decent versioning system, has branching and merging functionality, but until recently I had little success (and some disaster) trying to use it. So I used the cruder but tried-and-true method of locally rsync'ing dev to prod (with -rC for recursive and ignoring SVN metadata) and committing the changes to each separately. That mostly works fine, except it can be a very tedious process (using FileMerge to check every file and figure out which branch's version is correct); it makes SVN's logs very difficult to understand (with no clear history to a file and duplicate commits of everything); it's easy to make a mistake and mess up a branch; and it seemed unnecessary given SVN's built-in functionality. In some cases, the dev and prod branches got so out of whack that the developers had given up on merging them, and all development was done on local copies of the production branch, an inefficient (and dangerous) method that made branches pointless.

So on my latest post-launch project, I decided to figure out SVN merging. The first deployment process took 2+ hours with a splitting headache at the end; then 1 more lucid hour; now it's 5 minutes, so I do this even for extremely urgent fixes. svn help merge describes multiple ways to use the command; this is how I've gotten it to work.