…one interaction is the whole experience

Posted on April 16th, 2010 in PHP by Russ

… Seth Godin (http://sethgodin.typepad.com/seths_blog/2010/04/when-a-stranger-reads-your-blog.html) said it here; Every interaction might be the whole experience that someone gets with you. The implication is that every lunch you serve should be the best. Every blog post you write should be the best. Every piece of code you codify should be the best (cough). And that you should remember that each person that sees your output (or experiences you) is forming an opinion of you from that one piece.

But what he doesn’t mention is that it goes both ways. Give other people the benefit of the doubt, because just this one lunch, this one blog post, this one piece of code may not be representative of the whole body of that person’s work. Maybe they’ve got bad allergies and need the drugs to kick in. Maybe they stayed up all night with a sick kid. I say “do your best work, but don’t expect others to do theirs.”

It’s funny, I find myself swimming upstream against Seth Godin on this topic. Is quality fractal? (he says yes, I said no). And now this.

Pipe to PHP Script from Evolution

Posted on April 4th, 2010 in PHP, system admin, system administration by Russ

Here’s a quick example of how to pipe a message to a PHP script from Evolution (the gnome-tastic email client).

First, write a script, using very clear paths. And use php://stdin to capture the input stream:


#!/usr/bin/php -q
< ?php
include_once( dirname(__FILE__).'/includeme.php' );
$input='';
$fh=fopen( 'php://stdin', 'r' );
while( ! feof( $fh ) ) {
$input .= fread( $fh, 4096);
}
fclose( $fh );

Do whatever you need to with the $input variable. I had subscribed to a newsletter, and was using PHP to parse out the interesting bits of the newsletter (everything between the h1, h2 and h3 tags, so I knew if I needed to read it), and remail that to a more-frequently checked email address.

You can test your file with a shell command of "cat (testfile) | $somescript.php "

When it's perfect, then go to your evolution program and use the "message filters" to "pipe a message to a program." And pipe it to this one (including of course the explicit paths).

The things to take away here are the php://stdin slurp, and the fact that you have to use explicit paths (and you'll have a dickens of a time tracking down any errors).

Hope that helps ya!