By Matt Butcher
mac
OS X: Installing MongoDB and the PHP Mongo Driver
Submitted by matt on Sat, 2010-01-30 12:09MongoDB is a full-featured object database. Since it is fast, versatile, and schema-less, you can develop a very complex data storage layer without an ORM, and without any tedious coding. For this reason, I have been investigating MongoDB as a storage layer for PHP. Here's how to set up an environment on OS X Snow Leopard.
In this blog we'll do the following:
- Install MongoDB
- Add some initial data to MongoDB
- Install the PHP PECL driver for MongoDB
- Write a short PHP Script that uses MongoDB
- Shut down the MongoDB server
OS X: Using curl instead of wget
Submitted by matt on Fri, 2010-01-15 11:21OS X does not come with wget, a command-line tool for retrieving websites. For a while, I grumbled about this. I knew that curl was installed, but I hadn't ever used curl from the command line. But once I tried it out, I realized that for my needs, curl is just as good as wget... and I don't have to install anything extra to get it.
Here's how to use curl to fetch a remote URL:
$ curl -OL h ttp://spine-health.com/index.php
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 34646 0 34646 0 0 15314 0 --:--:-- 0:00:02 --:--:-- 17767This will download the remote file and store it locally in index.php. If you leave off the -O, it will write the file to standard output (your terminal, usually).
curl: Remote file name has no length!
Fetching from a URL's root can behave differently. If you perform the same command as above, but pointing to the base URL, you will get an error:
$ curl -OL h ttp://spine-health.com/ curl: Remote file name has no length! curl: try 'curl --help' or 'curl --manual' for more information
What's going on here? The error is not terribly informative on this point. The problem is that curl doesn't know where to write the output file. A better command here is something like this:
$ curl -L h ttp://spine-health.com/ > out.html
This time, the retrieved data will be written to the out.html file.
Like wget, curl has many options. You can read the man page for details, or you can get a quick summary with the usual curl --help command.
Phing: Fixing Output on OS X
Submitted by matt on Sat, 2009-12-26 18:18Using Phing on a Mac OS X console sometimes has a strange result: While the Phing script runs correctly, the console displays nothing. The reason for this is that the ANSI color codes used by some versions of Phing are not supported by OS X.
The solution is simple. Change the output logger.
$ phing -logger phing.listener.DefaultLogger ftest
This will use a non-colorized logger.
OS X Security Warning on Email Attachments: Getting rid of them
Submitted by matt on Mon, 2009-11-02 18:10A colleague of mine recently pointed out that when you unzip an archive of scripts received as an email attachment, every time you open a file, you get a warning like this:
“csvimport.inc.php” is a script application which was attached to a mail message. Are you sure you want to open it?
When you have dozens of scripts to look at, clicking through this warning each time is irritating, to say the least. A little examination of the xattr flags on these files, though, revealed the problem:
$ python Python 2.5.1 (r251:54863, Feb 6 2009, 19:02:12) [GCC 4.0.1 (Apple Inc. build 5465)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import xattr >>> xattr.listxattr('config.inc.php') (u'com.apple.quarantine',) >>>
There is a flag on such files called 'com.apple.quarantine'. This flag needs to be cleared.
Originally, I was going to write a script to do this, but a quick google obviated that need. Mark Liyanage has done this already. He shows two different ways to clear the flag.
TechStartups: The Demise of Web 2.0
Submitted by matt on Thu, 2009-10-29 10:08I spent last weekend out in Santa Clara at the Google SOC Mentor Summit. The conference itself was fantastic, but at one point a lightbulb went on in my head, and I sat down and wrote an article. Head on over to Tech Startups and read about The Demise of Web 2.0.
TechStartups: The Demise of Web 2.0
Using the UNIX find Command
Submitted by matt on Mon, 2009-08-03 20:48Today I needed to run a simple script against thousands of identically named files nested in a huge directory structure. What I needed was a quick way to recurse through all of the directories, ignore all of the files I didn't care about, but run a specified command on any files with a particular name.
While this sounds like the sort of thing that will require a couple dozen lines of shell scripting, it can actually be accomplished on a single line with the command find. find has been around for decades, and can be found on almost any UNIX-like file system. It is a simple to used for searching for files within the UNIX directory hierarchy. Honestly, there's not much more to it. Like all good UNIX tools, it does one thing well.
Vim Colorschemes
Submitted by matt on Sat, 2009-07-04 20:46Here's a small tip for burgeoning Vim (VI Improved) users. Vim supports various colorschemes in its colorized editing mode. If you don't like the default syntax highlighting colorscheme that Vim uses, you can change it easily by running a command like this (within Vim):
:colorscheme koehler
The :colorscheme command takes one argument: the name of the colorscheme. Above, I am setting the syntax highlighting colorscheme to the koehler scheme. At any point, I can change it back to the default by running:
:colorscheme default
Mac: Using the Visor terminal utility
Submitted by matt on Fri, 2009-06-26 09:46A week ago, I was introduced to Visor, a utility for turning the Mac OS X console into a "Quake-style" console. What does that mean? In a nutshell, it means that the terminal runs not as a normal window, but as a boderless window attached to the top of the screen. Hit a button and the console slides down. Hit the button again (or unfocus from the window) and up it slides. It's a convenient way of keeping a terminal accessible at all times. (And, yes, it supports multiple tabs.)
Visor: "Official" screenshot
Visor is written in Ruby, and is easy to install (though the installation process is a little more, ahem, manual than your typical Mac OS application.
Tip: By default, Visor slides away when the window loses focus. Sometimes, though, it is desirable to keep the visor down for short (or perhaps long) periods while working in another window. To do this, expand visor and then click on the visor terminal icon on the right side of your menu bar. Select "pin" and the visor will stay open. To set it back to its regular behavior, select "unpin".
Thanks to sdboyer for turning me on to Visor.
Mac: Tabbing through all form fields
Submitted by matt on Wed, 2009-06-17 15:07By default, the Mac OS X behavior for tabbing through form fields is different than that of Windows and Linux. Instead of tabbing through all fields in a form, the default Mac behavior is to skip only between lists, text fields and text areas. Buttons and checkboxes are skipped. However, this behavior is configurable.
To configure OS X to tab through all fields, go to System Settings and navigate to Keyboard and Mouse. From there, click on the Keyboard Shortcuts at the top.
PHP 5 Runkit for MAMP 1.7.2
Submitted by matt on Sun, 2009-03-15 20:31Ever tried to get PHP's Runkit PECL extension running on the popular MAMP stack for Mac OS X? If you have tried, you will understand why it is difficult. There are two roadblocks that must be overcome before Runkit can be installed.
The first has to do with MAMP itself. While MAMP provides most of the tools that a web developer needs, it is generally incapable of dealing with PECL builds. The reason for this is simple: MAMP does not ship with header files for PHP. That means that extensions built from C source files cannot successfully compile. That is a problem.
The second difficulty has to do with Runkit, which (being basically feature complete) hasn't undergone a major revision in a couple of years. The official released version, in fact, will not run on PHP 5.2. Yes, that is the version that ships with MAMP. To get the fixed version, you will need to check out the latest source code from PHP.net's CVS repository and build it yourself.
Recently, I found a situation that demanded Runkit. (Okay, it might have been a contrived situation.) To accomplish the goal of my project, I built Runkit from source. If you want it, the runkit.so file is attached at the end of this post.








Recent comments
2 days 14 hours ago
4 days 23 min ago
4 days 55 min ago
4 days 1 hour ago
4 days 13 hours ago
4 days 13 hours ago
2 weeks 1 hour ago
2 weeks 21 hours ago
2 weeks 1 day ago
2 weeks 2 days ago