<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title type="text">Blog entries tagged perl :: mwop.net</title>
  <updated>2012-06-24T21:50:00-05:00</updated>
  <generator uri="https://getlaminas.org" version="2">Laminas_Feed_Writer</generator>
  <link rel="alternate" type="text/html" href="https://mwop.net/blog/tag/perl"/>
  <link rel="self" type="application/atom+xml" href="https://mwop.net/blog/tag/perl/atom.xml"/>
  <id>https://mwop.net/blog/tag/perl</id>
  <entry xmlns:xhtml="http://www.w3.org/1999/xhtml">
    <title type="html"><![CDATA[Automatic deployment with git and gitolite]]></title>
    <published>2012-06-24T21:50:00-05:00</published>
    <updated>2012-06-24T21:50:00-05:00</updated>
    <link rel="alternate" type="text/html" href="https://mwop.net/blog/2012-06-24-git-deploy.html"/>
    <id>https://mwop.net/blog/2012-06-24-git-deploy.html</id>
    <author>
      <name>Matthew Weier O'Phinney</name>
      <email>contact@mwop.net</email>
      <uri>https://mwop.net</uri>
    </author>
    <content xmlns:xhtml="http://www.w3.org/1999/xhtml" type="xhtml">
      <xhtml:div xmlns:xhtml="http://www.w3.org/1999/xhtml"><xhtml:p>I read a <xhtml:a href="http://seancoates.com/blogs/deploy-on-push-from-github">post
recently by Sean Coates about deploy on push</xhtml:a>. The concept is
nothing new: you set up a hook that listens for commits on specific
branches or tags, and it then deploys your site from that
revision.</xhtml:p>
<xhtml:p>Except I'd not done it myself. This is how I got there.</xhtml:p>
<xhtml:p>Sean's approach uses <xhtml:a href="https://help.github.com/articles/post-receive-hooks">Github
webhooks</xhtml:a>, which are a fantastic concept. Basically, once your
commit completes, Github will send a JSON-encoded payload to a
specific URI. Sean uses this to trigger an API call to a specific
page in his website, which will then trigger a deployment
activity.</xhtml:p>
<xhtml:p>Awesome, this should be easy; I already have a deploy script
written that I trigger manually.</xhtml:p>
<xhtml:p>One small problem: my site, while in Git, is not on Github. I
maintain it on my own <xhtml:a href="https://github.com/sitaramc/gitolite">Gitolite</xhtml:a> repository.
Which means I needed to write my own hooks.</xhtml:p>
<xhtml:p>I originally went down the route of using a post-receive hook.
However, I had problems determining what branch the given commit
was on, despite a variety of advice I found on the subject on
<xhtml:a href="http://stackoverflow.com/">StackOverflow</xhtml:a> and git
mailing lists. I ended up finding a great example using
<xhtml:code>post-update</xhtml:code>, which was actually perfect for my
needs.</xhtml:p>
<xhtml:p>In order to keep the <xhtml:code>post-update</xhtml:code> script
non-blocking when I commit, I made it do very little: It simply
determines what branch the commit was on, and if it was the master
branch, it touches a specific file on the filesystem and finishes.
The entire hook looks like this:</xhtml:p>
<xhtml:pre><xhtml:code class="language-bash hljs bash" data-lang="bash"><xhtml:span class="hljs-meta">#!/bin/bash</xhtml:span>
branch=$(git rev-parse --symbolic --abbrev-ref <xhtml:span class="hljs-variable">$1</xhtml:span>)
<xhtml:span class="hljs-built_in">echo</xhtml:span> <xhtml:span class="hljs-string">"Commit was for branch <xhtml:span class="hljs-variable">$branch</xhtml:span>"</xhtml:span>
<xhtml:span class="hljs-keyword">if</xhtml:span> [[ <xhtml:span class="hljs-string">"<xhtml:span class="hljs-variable">$branch</xhtml:span>"</xhtml:span> == <xhtml:span class="hljs-string">"master"</xhtml:span> ]];<xhtml:span class="hljs-keyword">then</xhtml:span>
    <xhtml:span class="hljs-built_in">echo</xhtml:span> <xhtml:span class="hljs-string">"Preparing to deploy"</xhtml:span>
    <xhtml:span class="hljs-built_in">echo</xhtml:span> <xhtml:span class="hljs-string">"1"</xhtml:span> &gt; /var/<xhtml:span class="hljs-built_in">local</xhtml:span>/mwop.net.update
<xhtml:span class="hljs-keyword">fi</xhtml:span>
</xhtml:code></xhtml:pre>
<xhtml:p>Now I needed something to detect such a push, and act on it.</xhtml:p>
<xhtml:p>I considered using cron for this; it'd be relatively easy to
have it fire up once a minute, and simply act on it. But I decided
instead to write a simple little daemon using perl. Perl daemons
are trivially easy to write, and if you use module such as
<xhtml:code>Proc::Daemon</xhtml:code> and follow a few trivial defensive coding
practices, you can keep memory leaks contained (or at least
minimal). Besides, it gave me a chance to dust off my perl
chops.</xhtml:p>
<xhtml:p>I decided I'd have it check for the file in 30 second intervals,
simply sleeping if no changes were detected. If the file was found,
however, it should attempt to deploy. Additionally, I wanted it to
quit if it was unable to remove the file (as this could lead to
multiple deploy attempts), and log success and failure status of
the deploy. The full script looks like this:</xhtml:p>
<xhtml:pre><xhtml:code class="language-perl hljs perl" data-lang="perl"><xhtml:span class="hljs-comment">#!/usr/bin/perl</xhtml:span>
<xhtml:span class="hljs-keyword">use</xhtml:span> strict;
<xhtml:span class="hljs-keyword">use</xhtml:span> warnings;
<xhtml:span class="hljs-keyword">use</xhtml:span> Proc::Daemon;

Proc::Daemon::Init;

<xhtml:span class="hljs-keyword">my</xhtml:span> $continue = <xhtml:span class="hljs-number">1</xhtml:span>;
$SIG<xhtml:span class="hljs-string">{TERM}</xhtml:span> = <xhtml:span class="hljs-function"><xhtml:span class="hljs-keyword">sub</xhtml:span> </xhtml:span>{ $continue = <xhtml:span class="hljs-number">0</xhtml:span> };

<xhtml:span class="hljs-keyword">my</xhtml:span> $updateFile   = <xhtml:span class="hljs-string">"/var/local/mwop.net.update"</xhtml:span>;
<xhtml:span class="hljs-keyword">my</xhtml:span> $updateScript = <xhtml:span class="hljs-string">"/home/matthew/bin/deploy-mwop"</xhtml:span>;
<xhtml:span class="hljs-keyword">my</xhtml:span> $logFile      = <xhtml:span class="hljs-string">"/var/local/mwop.net-deploy.log"</xhtml:span>;
<xhtml:span class="hljs-keyword">while</xhtml:span> ($continue) {
    <xhtml:span class="hljs-comment"># 30s intervals between iterations</xhtml:span>
    <xhtml:span class="hljs-keyword">sleep</xhtml:span> <xhtml:span class="hljs-number">30</xhtml:span>;

    <xhtml:span class="hljs-comment"># Check for update file, and restart loop if not found</xhtml:span>
    <xhtml:span class="hljs-keyword">unless</xhtml:span> (-e $updateFile) {
        <xhtml:span class="hljs-keyword">next</xhtml:span>;
    }

    <xhtml:span class="hljs-comment"># Remove update file</xhtml:span>
    <xhtml:span class="hljs-keyword">if</xhtml:span> (!<xhtml:span class="hljs-keyword">unlink</xhtml:span>($updateFile)) {
        <xhtml:span class="hljs-comment"># If unable to unlink, we need to quit</xhtml:span>
        <xhtml:span class="hljs-keyword">system</xhtml:span>(<xhtml:span class="hljs-string">'echo "'</xhtml:span> . <xhtml:span class="hljs-keyword">time</xhtml:span>() . <xhtml:span class="hljs-string">': Failed to REMOVE '</xhtml:span> . $updateFile . <xhtml:span class="hljs-string">'" &gt;&gt; '</xhtml:span> . $logFile);
        $continue = <xhtml:span class="hljs-number">0</xhtml:span>;
        <xhtml:span class="hljs-keyword">next</xhtml:span>;
    }

    <xhtml:span class="hljs-comment"># Deploy</xhtml:span>
    <xhtml:span class="hljs-keyword">system</xhtml:span>($updateScript);
    <xhtml:span class="hljs-keyword">if</xhtml:span> ( $? == -<xhtml:span class="hljs-number">1</xhtml:span> ) {
        <xhtml:span class="hljs-keyword">system</xhtml:span>(<xhtml:span class="hljs-string">'echo "'</xhtml:span> . <xhtml:span class="hljs-keyword">time</xhtml:span>() . <xhtml:span class="hljs-string">': FAILED to deploy: '</xhtml:span> . $! . <xhtml:span class="hljs-string">'" &gt;&gt; '</xhtml:span> .  $logFile);
    } <xhtml:span class="hljs-keyword">else</xhtml:span> {
        <xhtml:span class="hljs-keyword">system</xhtml:span>(<xhtml:span class="hljs-string">'echo "'</xhtml:span> . <xhtml:span class="hljs-keyword">time</xhtml:span>() . <xhtml:span class="hljs-string">': Successfully DEPLOYED" &gt;&gt; '</xhtml:span> . $logFile);
    }
}
</xhtml:code></xhtml:pre>
<xhtml:p>The <xhtml:code>system()</xhtml:code> calls for logging could have been done
using Perl, but I didn't want to deal with additional error
handling and file pointers; simply proxying to the system seemed
reasonable and expedient.</xhtml:p>
<xhtml:p>When all was ready, I started the above listener, which
automatically daemonizes itself. I then installed the
<xhtml:code>post-update</xhtml:code> hook into my bare repository, and tested
it out. And it runs! When I push to master, my site is
automatically deployed, typically within 15-20 seconds from
completion.</xhtml:p>
<xhtml:h4>Caveats</xhtml:h4>
<xhtml:p>This solution, of course, relies on a daemonized process. If
that process were to terminate, I'd have no idea until I discovered
my site didn't refresh after the most recent push. Clearly, some
sort of monitor checking for the status of the daemon should be in
place.</xhtml:p>
<xhtml:p>Also, note that I'm having this update on changes to the master
branch; you may need to adapt it for your own needs, depending on
your branching strategy.</xhtml:p>
<xhtml:p>Finally, this approach does not address issues that might
require a roll-back. Ideally, the script should probably log what
revision was current prior to the deployment, allowing roll-back to
the previous state. Alternately, the deployment script should
create a new clone of the site and swap symlinks to allow quick
roll-back when required.</xhtml:p>
<xhtml:div class="h-entry"><xhtml:img class="u-photo photo" width="50" src="https://avatars0.githubusercontent.com/u/25943?v=3&amp;u=79dd2ea1d4d8855944715d09ee4c86215027fa80&amp;s=140" alt="matthew"/> <xhtml:a class="u-url u-uid p-name" href="https://mwop.net/blog/2012-06-24-git-deploy.html">Automatic
deployment with git and gitolite</xhtml:a> was originally published
<xhtml:time class="dt-published" datetime="2012-06-24T21:50:00-05:00">24
June 2012</xhtml:time> on <xhtml:a href="https://mwop.net">https://mwop.net</xhtml:a>
by <xhtml:a rel="author" class="p-author" href="https://mwop.net">Matthew
Weier O'Phinney</xhtml:a>.</xhtml:div>
</xhtml:div>
    </content>
  </entry>
  <entry xmlns:xhtml="http://www.w3.org/1999/xhtml">
    <title type="html"><![CDATA[Why Conventions Matter]]></title>
    <published>2012-01-11T22:58:28-06:00</published>
    <updated>2012-01-11T22:58:28-06:00</updated>
    <link rel="alternate" type="text/html" href="https://mwop.net/blog/why-conventions-matter.html"/>
    <id>https://mwop.net/blog/why-conventions-matter.html</id>
    <author>
      <name>Matthew Weier O'Phinney</name>
      <email>contact@mwop.net</email>
      <uri>https://mwop.net</uri>
    </author>
    <content xmlns:xhtml="http://www.w3.org/1999/xhtml" type="xhtml">
      <xhtml:div xmlns:xhtml="http://www.w3.org/1999/xhtml"><xhtml:p>When I started teaching myself scripting languages, I started
with Perl. One Perl motto is <xhtml:a href="http://en.wikipedia.org/wiki/TMTOWTDI">"TMTOWTDI"</xhtml:a> — "There's
More Than One Way To Do It," and pronounced "tim-toady." The idea
is that there's likely multiple ways to accomplish the very same
thing, and the culture of the language encourages finding novel
ways to do things.</xhtml:p>
<xhtml:p>I've seen this principle used everywhere and in just about every
programming situation possible, applied to logical operations,
naming conventions, formatting, and even project structure.
Everyone has an opinion on these topics, and given free rein to
implement as they see fit, it's rare that two developers will come
up with the same conventions.</xhtml:p>
<xhtml:p>TMTOWTDI is an incredibly freeing and egalitarian principle.</xhtml:p>
<xhtml:p>Over the years, however, my love for TMTOWTDI has diminished
some. Freeing as it is, is also a driving force behind having
coding standards and conventions — because when everyone does it
their own way, projects become quickly hard to maintain. Each
person finds themselves reformatting code to their own standards,
simply so they can read it and follow its flow.</xhtml:p>
<xhtml:p>Additionally, TMTOWTDI can actually be a foe of simple, elegant
solutions.</xhtml:p>
<xhtml:p>Why do I claim this?</xhtml:p>
<xhtml:p>Recently, discussing module structure in Zend Framework 2, some
folks were arguing that our recommended directory structure invokes
the <xhtml:a href="http://en.wikipedia.org/wiki/YAGNI">YAGNI</xhtml:a>
principle: You Ain't Gonna Need It. Our recommendation is this:</xhtml:p>
<xhtml:pre><xhtml:code class="language-arduino hljs arduino" data-lang="arduino">ModuleName/
    autoload_classmap.php
    Module.php
    <xhtml:span class="hljs-built_in">config</xhtml:span>/
        <xhtml:span class="hljs-keyword">module</xhtml:span>.<xhtml:span class="hljs-built_in">config</xhtml:span>.php
        (other <xhtml:span class="hljs-built_in">config</xhtml:span> files)
    <xhtml:span class="hljs-keyword">public</xhtml:span>/
        css/
        images/
        js/
    src/
        ModuleName/
            (source files)
    test/
    view/
</xhtml:code></xhtml:pre>
<xhtml:p>The argument is that since most modules implement a single
namespace, and because we recommend following <xhtml:a href="https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md">
PSR-0</xhtml:a> for autoloaders, it makes sense to simply have the source
files directly under the module directory.</xhtml:p>
<xhtml:pre><xhtml:code class="language-arduino hljs arduino" data-lang="arduino">ModuleName/
    autoload_classmap.php
    Module.php
    (other source files)
    <xhtml:span class="hljs-built_in">config</xhtml:span>/
        <xhtml:span class="hljs-keyword">module</xhtml:span>.<xhtml:span class="hljs-built_in">config</xhtml:span>.php
        (other <xhtml:span class="hljs-built_in">config</xhtml:span> files)
    <xhtml:span class="hljs-keyword">public</xhtml:span>/
    test/
    view/
</xhtml:code></xhtml:pre>
<xhtml:p>The argument myself and others made was that it makes sense to
group the files by responsibility. However, the module system
ultimately <xhtml:em>doesn't care</xhtml:em> how you organize the module —
we've embraced TMTOWTDI, and our only requirement is that for your
module to be consumed, you must define a
<xhtml:code>ModuleName\Module</xhtml:code> class, and notify the module manager
how to find it. Anything goes.</xhtml:p>
<xhtml:p>How does that bolster my argument about the importance of
conventions? It doesn't. What does is what following the
recommended structure enabled me to do.</xhtml:p>
<xhtml:p>One common concern identified with having a re-usable module
system is that you should be able to expose public assets easily:
things like module-specific CSS or JavaScript, or even images. The
first question that arises when you consider this is: where do I
put them in my module? That's why the recommendation includes a
<xhtml:code>public</xhtml:code> directory. In fact, the recommendation goes a
step further, and suggests <xhtml:code>css</xhtml:code>, <xhtml:code>images</xhtml:code>,
and <xhtml:code>js</xhtml:code> directories as well.</xhtml:p>
<xhtml:p>Now, your modules are typically <xhtml:em>outside</xhtml:em> the document
root. This is a rudimentary and fundamental security measure, and
also simplifies deployment to a degree — you don't need to worry
about telling the web server about what it <xhtml:em>shouldn't</xhtml:em>
serve. But if the modules are outside the document root, how can I
expose their public assets?</xhtml:p>
<xhtml:p>There are a two possibilities that immediately jump to mind:</xhtml:p>
<xhtml:ul>
<xhtml:li>Install scripts for modules, which copy the files into the
document root.</xhtml:li>
<xhtml:li>Symlink the files into the document root.</xhtml:li>
</xhtml:ul>
<xhtml:p>Both are valid, and easy to accomplish. Both raise the same
question: where, exactly? What if multiple modules have public
assets named the same? how do I refer to my assets withing things
like view scripts?</xhtml:p>
<xhtml:p>This is where having a convention starts to make sense: having a
convention should answer these questions unambiguously.</xhtml:p>
<xhtml:p>My answer: public access should be at
<xhtml:code>/css/ModuleName/stylesheetname</xhtml:code>, or
<xhtml:code>/js/ModuleName/scriptname</xhtml:code> or
<xhtml:code>/images/Modulename/imagename</xhtml:code>. It's a dirt-simple rule
that fulfills the use cases.</xhtml:p>
<xhtml:p>However, I'm now stuck with having to develop either install
scripts or remembering to create symlinks — ugh. And that's where
having conventions led me to a simple, elegant solution.</xhtml:p>
<xhtml:p>I added one line to my Apache vhost definition:</xhtml:p>
<xhtml:pre><xhtml:code class="language-apacheconf hljs apache" data-lang="apacheconf"><xhtml:span class="hljs-attribute">AliasMatch</xhtml:span> /(css|js|images)/([^/]+)/(.*) /path/to/module/<xhtml:span class="hljs-number">$2</xhtml:span>/public/<xhtml:span class="hljs-number">$1</xhtml:span>/<xhtml:span class="hljs-number">$3</xhtml:span>
</xhtml:code></xhtml:pre>
<xhtml:p>The translation:</xhtml:p>
<xhtml:blockquote>
<xhtml:p>When I come across a path to CSS, JS, or image files that are in
a subdirectory, alias it to the corresponding public asset of the
matched module directory.</xhtml:p>
</xhtml:blockquote>
<xhtml:p>I dropped this into my vhost, restarted Apache, and now not only
were the assets I'd created already served, but any new ones I
create are immediately available as well. Having a convention
actually simplified my choices and my solutions.</xhtml:p>
<xhtml:p>Rapid application development at its finest.</xhtml:p>
<xhtml:p>My point is this: there will always be more than one way to do
things when you're programming, and you may not always agree with
the decisions your team has made, or the component library or
framework you're using has made. However, if you poke around a
little and play within those confines, you may find that those
decisions make other decisions easier, or disappear altogether.</xhtml:p>
<xhtml:div class="h-entry"><xhtml:img class="u-photo photo" width="50" src="https://avatars0.githubusercontent.com/u/25943?v=3&amp;u=79dd2ea1d4d8855944715d09ee4c86215027fa80&amp;s=140" alt="matthew"/> <xhtml:a class="u-url u-uid p-name" href="https://mwop.net/blog/why-conventions-matter.html">Why Conventions
Matter</xhtml:a> was originally published <xhtml:time class="dt-published" datetime="2012-01-11T22:58:28-06:00">11 January 2012</xhtml:time> on
<xhtml:a href="https://mwop.net">https://mwop.net</xhtml:a> by <xhtml:a rel="author" class="p-author" href="https://mwop.net">Matthew Weier
O'Phinney</xhtml:a>.</xhtml:div>
</xhtml:div>
    </content>
  </entry>
  <entry xmlns:xhtml="http://www.w3.org/1999/xhtml">
    <title type="html"><![CDATA[Seven Things - Tagged by Keith Casey]]></title>
    <published>2009-01-02T10:44:54-06:00</published>
    <updated>2009-01-04T16:31:52-06:00</updated>
    <link rel="alternate" type="text/html" href="https://mwop.net/blog/204-Seven-Things-Tagged-by-Keith-Casey.html"/>
    <id>https://mwop.net/blog/204-Seven-Things-Tagged-by-Keith-Casey.html</id>
    <author>
      <name>Matthew Weier O'Phinney</name>
      <email>contact@mwop.net</email>
      <uri>https://mwop.net</uri>
    </author>
    <content xmlns:xhtml="http://www.w3.org/1999/xhtml" type="xhtml">
      <xhtml:div xmlns:xhtml="http://www.w3.org/1999/xhtml"><xhtml:p>I'm really not sure I understand these "seven things" or
"tagged" memes, but I'm going to give it a shot, after <xhtml:a href="http://caseysoftware.com/blog/seven-things-tagged-by-tony-bibbs">Keith
Casey</xhtml:a> did a drive-by tagging of me on New Year's Eve.</xhtml:p>
<xhtml:p>So, without further ado, seven things you may not know about
me…</xhtml:p>
<xhtml:ul>
<xhtml:li>
<xhtml:p><xhtml:em>My actual college degree is in comparative religion.</xhtml:em> I
ended up in the Religion department at the <xhtml:a href="http://www.ups.edu/">University of Puget Sound</xhtml:a> (yes, the
initials are UPS, which can easily cause confusion with brown,
parcel-bearing trucks), due to a line of questioning that occurred
during an Artificial Intelligence course I was taking. The
instructor was asking if there would be any ethical barrier to
unplugging an AI — i.e., since it would be capable of thought,
would this be equivalent to "killing" it? My initial response was,
"No," because humans consist of more than thought… and then I
started wondering a bit about that. My emphasis in religion was in
Eastern religions. I have a minor in Mathematics (CS at UPS was
actually CS/Mathematics).</xhtml:p>
</xhtml:li>
<xhtml:li>
<xhtml:p><xhtml:em>I have an FCC Commercial Radio Operator's License.</xhtml:em> My
parents were volunteer DJs at <xhtml:a href="http://www.kglt.net/">KGLT</xhtml:a> while I was growing up, and I did
my first radio announcing at… get this… the ripe age of 11. I
finally got my license before starting college so that I could be a
DJ at the university station… and ended up as the General Manager
of <xhtml:a href="http://en.wikipedia.org/wiki/KUPS">KUPS</xhtml:a> my last two
years.</xhtml:p>
</xhtml:li>
<xhtml:li>
<xhtml:p><xhtml:em>I had long hair — down to my butt at times — for around ten
years.</xhtml:em> Which likely comes as a huge shock to those of you who
have met me at conferences. Ironically, I cut it off just prior to
moving to Vermont as part of an effort to increase the success of
my job hunt.</xhtml:p>
</xhtml:li>
<xhtml:li>
<xhtml:p><xhtml:em>Before I started my programming career, I was a graphics
technician.</xhtml:em> The job immediately prior to my first programming
position was with a small book publisher that specialized in bird
hunting and flyfishing guidebooks, for which I created maps,
scanned and processed images for books, and did book and catalog
layout.</xhtml:p>
</xhtml:li>
<xhtml:li>
<xhtml:p><xhtml:em>My first Object Oriented Programming was in Perl.</xhtml:em> If
you've ever done OOP in Perl, you'll likely agree with the
following statement: OOP in any other language is easy by
comparison. I mean, come on, a syntax where the very definition of
an object requires that you "bless" a "thingy"? Truly; this is from
the "bless" documentation:</xhtml:p>
<xhtml:blockquote>
<xhtml:p>bless REF: This function tells the thingy referenced by REF that
it is now an object in the CLASSNAME package. If CLASSNAME is
omitted, the current package is used. Because a bless is often the
last thing in a constructor, it returns the reference for
convenience. Always use the two-argument version if a derived class
might inherit the function doing the blessing. See perltoot and
perlobj for more about the blessing (and blessings) of objects.</xhtml:p>
</xhtml:blockquote>
<xhtml:p>This made OOP in PHP look easy.</xhtml:p>
</xhtml:li>
<xhtml:li>
<xhtml:p><xhtml:em>I hold the degree of shodan in Aikido,</xhtml:em> though I haven't
trained in several years, due to time and travel constraints. I
love the movement and flow of Aikido, and always found it very
meditative. I also liked working with weapons, especially the
bokken (wooden sword). This is why when I say, "don't make me get
my clue bat out," you should take heed; I know from experience that
white oak leaves a mark.</xhtml:p>
</xhtml:li>
<xhtml:li>
<xhtml:p><xhtml:em>I could have been <xhtml:a href="http://calevans.com/">Cal</xhtml:a>.</xhtml:em> When <xhtml:a href="http://www.zend.com/">Zend</xhtml:a> first interviewed me, it was for
the position of Editor-in-Chief of <xhtml:a href="http://devzone.zend.com/">DevZone</xhtml:a>. After my in-house
interview, I had reservations — I didn't feel experienced or
connected enough, and was worried I'd botch it. Fortunately for me,
and probably the PHP community in general, they decided to hire me
as a PHP developer instead.</xhtml:p>
</xhtml:li>
</xhtml:ul>
<xhtml:p>So, that's seven things (and quite a bit more, really) about me.
And now it's time to tag some others:</xhtml:p>
<xhtml:ul>
<xhtml:li><xhtml:a href="http://calevans.com/">Cal Evans</xhtml:a> is an obvious
choice for me. Besides having worked together for some years, he's
a great friend.</xhtml:li>
<xhtml:li><xhtml:a href="http://www.leftontheweb.com/">Stefan Koopmanschap</xhtml:a>,
who took a train to Amsterdam just to have dinner and a beer with
me.</xhtml:li>
<xhtml:li><xhtml:a href="http://seancoates.com/">Sean Coates</xhtml:a>, whom I met in
an airport on the way back from ZendCon two years ago, who lives
less than two hours away, and whom I haven't seen since that
ZendCon.</xhtml:li>
<xhtml:li><xhtml:a href="http://www.lornajane.net/">Lorna Jane Mitchell</xhtml:a>,
with whom I'll be doing a tutorial session on Subversion at
php|tek, and who will be clearly flustered by being tagged.</xhtml:li>
<xhtml:li><xhtml:a href="http://jansch.nl/">Ivo Jansch</xhtml:a>, whom I met almost
two years ago, and somebody I admire and respect greatly.</xhtml:li>
<xhtml:li><xhtml:a href="http://www.khankennnels.com/blog/">Ligaya
Turmelle</xhtml:a>, one of my co-authors for "The PHP Anthology," the
woman who got me to volunteer as a phpwomen Booth Babe, and now
MySQL guru.</xhtml:li>
<xhtml:li><xhtml:a href="http://akrabat.com/">Rob Allen</xhtml:a>, who has made my
job easier by publishing tutorials and now a book on Zend
Framework, and who in real-life is a mild-mannered Clark Kent I'd
gladly raise a pint with any day.</xhtml:li>
</xhtml:ul>
<xhtml:p>And here are the rules I'm supposed to pass on to the above
bloggers:</xhtml:p>
<xhtml:ul>
<xhtml:li>Link your original tagger(s), and list these rules on your
blog.</xhtml:li>
<xhtml:li>Share seven facts about yourself in the post - some random,
some wierd.</xhtml:li>
<xhtml:li>Tag seven people at the end of your post by leaving their names
and the links to their blogs.</xhtml:li>
<xhtml:li>Let them know they've been tagged by leaving a comment on their
blogs and/or Twitter.</xhtml:li>
</xhtml:ul>
<xhtml:div class="h-entry"><xhtml:img class="u-photo photo" width="50" src="https://avatars0.githubusercontent.com/u/25943?v=3&amp;u=79dd2ea1d4d8855944715d09ee4c86215027fa80&amp;s=140" alt="matthew"/> <xhtml:a class="u-url u-uid p-name" href="https://mwop.net/blog/204-Seven-Things-Tagged-by-Keith-Casey.html">
Seven Things - Tagged by Keith Casey</xhtml:a> was originally published
<xhtml:time class="dt-published" datetime="2009-01-02T10:44:54-06:00">2
January 2009</xhtml:time> on <xhtml:a href="https://mwop.net">https://mwop.net</xhtml:a> by <xhtml:a rel="author" class="p-author" href="https://mwop.net">Matthew Weier
O'Phinney</xhtml:a>.</xhtml:div>
</xhtml:div>
    </content>
  </entry>
  <entry xmlns:xhtml="http://www.w3.org/1999/xhtml">
    <title type="html"><![CDATA[Mumbles irssi integration]]></title>
    <published>2008-12-10T15:01:50-06:00</published>
    <updated>2008-12-12T15:19:50-06:00</updated>
    <link rel="alternate" type="text/html" href="https://mwop.net/blog/197-Mumbles-irssi-integration.html"/>
    <id>https://mwop.net/blog/197-Mumbles-irssi-integration.html</id>
    <author>
      <name>Matthew Weier O'Phinney</name>
      <email>contact@mwop.net</email>
      <uri>https://mwop.net</uri>
    </author>
    <content xmlns:xhtml="http://www.w3.org/1999/xhtml" type="xhtml">
      <xhtml:div xmlns:xhtml="http://www.w3.org/1999/xhtml"><xhtml:p>I've been using IRC regularly for the past six to nine months,
in large part due to the growing ZF community on the <xhtml:a href="http://freenode.net/">Freenode</xhtml:a> <xhtml:code>#zftalk</xhtml:code> channel
(unfortunately, I simply don't have time to be in that particular
channel any more, but you can generally find me in
<xhtml:code>#zftalk.dev</xhtml:code>), but also to keep in contact with other
peers, friends, and colleagues.</xhtml:p>
<xhtml:p>One difficulty, however, is keeping productivity high while
staying on IRC. To me, the ultimate client would provide me
notifications when somebody mentions my name or a watch word —
allowing me to read the channel at my leisure, yet still respond to
people in a timely fashion.</xhtml:p>
<xhtml:p>I've tried a variety of IRC clients over the months, starting
with Pidgin (poor interface for IRC), mirc (huge difficulties
figuring out the UI), xchat (not bad, but seemed a bit heavy),
Chatzilla (I liked the interface, but once you got many tabs going,
it was unwieldy switching around between them; I also hated that
Firefox dying or restarting caused Chatzilla to do likewise), and
now <xhtml:a href="http://irssi.org/">irssi</xhtml:a>.</xhtml:p>
<xhtml:p>So far, irssi is the best I've tried — I can run it in screen,
allowing me to keep it open as long as my machine is running. The
interface is reasonable, and cleanly keeps channels separate from
private messages. Opening, closing, and manipulating windows is
easy. And it's highly scriptable… including in a language I
actually use! The perl bindings are top notch, though sometimes
cryptic. What's important, however, is that there are plenty of
examples out there if you want to try doing something. So, I
figured I'd write up a quick plugin to trigger notifications.</xhtml:p>
<xhtml:p>I've been using a number of different notification servers for
linux, and personally like both <xhtml:a href="http://gnotify.sourceforge.net">gnotify</xhtml:a> and <xhtml:a href="http://www.mumbles-project.org/">mumbles</xhtml:a>. Both are very
lightweight and offer network protocols for triggering
notifications.</xhtml:p>
<xhtml:p>I first tried using gnotify. It has a very, very simple TCP
protocol, and I've had success creating messages from the shell,
PHP, and perl. Unfortunately, for some reason, using it in irssi
displayed some odd behavior: I'd lose the cursor and the ability to
enter input from the time a notification triggered until it
completed (i.e., the notification disappeared). Forking the process
did not appear to help.</xhtml:p>
<xhtml:p>So, I decided to try out mumbles. Mumbles is written in python,
and has themeable notifications — already a plus. It runs via dbus
by default, but can also optionally spawn a server that implements
the <xhtml:a href="http://growl.info/">Growl protocol</xhtml:a> — making it
accessible for any process to send notifications. Additionally, it
has a command-line utility for triggering notifications — by
default over dbus, but optionally by contacting the growl server,
if running.</xhtml:p>
<xhtml:p>Growl's protocol is a bit involved, and I didn't want to spend
too much time on this. So, I did a quick, dirty hack: I used
backticks to trigger the CLI utility. And it works
<xhtml:em>fantastically</xhtml:em> — no delays whatsoever. Here's the code:</xhtml:p>
<xhtml:pre><xhtml:code class="language-perl hljs perl" data-lang="perl"><xhtml:span class="hljs-comment"># $HOME/.irssi/scripts/mumbles.pl</xhtml:span>
<xhtml:span class="hljs-keyword">use</xhtml:span> strict;
<xhtml:span class="hljs-keyword">use</xhtml:span> Irssi;
<xhtml:span class="hljs-keyword">use</xhtml:span> Irssi::Irc;
<xhtml:span class="hljs-keyword">use</xhtml:span> vars <xhtml:span class="hljs-string">qw($VERSION %IRSSI)</xhtml:span>;

$VERSION = <xhtml:span class="hljs-string">'0.1.0'</xhtml:span>;
%IRSSI = (
    <xhtml:span class="hljs-string">authors     =&gt;</xhtml:span> <xhtml:span class="hljs-string">"Matthew Weier O'Phinney"</xhtml:span>,
    <xhtml:span class="hljs-string">contact     =&gt;</xhtml:span> <xhtml:span class="hljs-string">'matthew@weierophinney.net'</xhtml:span>,
    <xhtml:span class="hljs-string">name        =&gt;</xhtml:span> <xhtml:span class="hljs-string">'Mumbles notifications for irssi'</xhtml:span>,
    <xhtml:span class="hljs-string">description =&gt;</xhtml:span> <xhtml:span class="hljs-string">'This script enables mumbles notifications for irssi'</xhtml:span>,
    <xhtml:span class="hljs-string">license     =&gt;</xhtml:span> <xhtml:span class="hljs-string">'New BSD'</xhtml:span>,
    <xhtml:span class="hljs-string">changed     =&gt;</xhtml:span> <xhtml:span class="hljs-string">"2008-12-10"</xhtml:span>
);


<xhtml:span class="hljs-function"><xhtml:span class="hljs-keyword">sub</xhtml:span> <xhtml:span class="hljs-title">mumbles_sig_printtext</xhtml:span> </xhtml:span>{
  <xhtml:span class="hljs-keyword">my</xhtml:span> ($dest, $text, $stripped) = @_;

  <xhtml:span class="hljs-keyword">if</xhtml:span> (($dest-&gt;{level} &amp; (MSGLEVEL_HILIGHT|MSGLEVEL_MSGS)) &amp;&amp; ($dest-&gt;{level} &amp; MSGLEVEL_NOHILIGHT) == <xhtml:span class="hljs-number">0</xhtml:span>)
  {
    <xhtml:span class="hljs-keyword">if</xhtml:span> ($dest-&gt;{level} &amp; MSGLEVEL_PUBLIC)
    {
      mumbles($dest-&gt;{target} . <xhtml:span class="hljs-string">" : "</xhtml:span> . $text);
    }
  }
}

<xhtml:span class="hljs-function"><xhtml:span class="hljs-keyword">sub</xhtml:span> <xhtml:span class="hljs-title">mumbles</xhtml:span> </xhtml:span>{
    <xhtml:span class="hljs-keyword">my</xhtml:span> $message = <xhtml:span class="hljs-keyword">shift</xhtml:span>;
    <xhtml:span class="hljs-keyword">my</xhtml:span> $response;

    $message =~ <xhtml:span class="hljs-regexp">s/[^!-~\s]//g</xhtml:span>;

    <xhtml:span class="hljs-string">`/usr/bin/mumbles-send -g 127.0.0.1 -s "IRC" "$message"`</xhtml:span>;
}

Irssi::command_bind <xhtml:span class="hljs-string">'mumbles'</xhtml:span> =&gt; <xhtml:span class="hljs-function"><xhtml:span class="hljs-keyword">sub</xhtml:span> </xhtml:span>{
    <xhtml:span class="hljs-keyword">my</xhtml:span> ($message) = @_;
    mumbles($message);
};

Irssi::signal_add({
  <xhtml:span class="hljs-string">'print text'</xhtml:span>    =&gt; \&amp;mumbles_sig_printtext
});
</xhtml:code></xhtml:pre>
<xhtml:p>This triggers a notification for any "highlight" event —
basically, anytime anybody "says" my name in a channel, or mentions
a keyword I've marked for highlighting. Additionally, I created a
<xhtml:code>mumbles</xhtml:code> command so that I can send test messages
(usage: <xhtml:code>/mumbles "this is the message..."</xhtml:code>). You could
certainly bind to other events, such as topic changes, joins,
parts, etc — I'm only interested in highlight events.</xhtml:p>
<xhtml:p>You may note the regexp in there. One thing I discovered was
that most messages contained control and non-ascii characters that
often resulted in unreadable notifications, as well as some nasty
messages reported by irssi. The regexp removes anything not in the
ascii character set or the set of whitespace definitions prior to
emitting the notification.</xhtml:p>
<xhtml:p>Something else I needed to do was configure compiz to ensure
that the notifications actually popped <xhtml:em>above</xhtml:em> my windows. I
did this by going into the compiz configuration manager, selecting
"General Options", selecting the "Focus &amp; Raise Behaviour" tab,
and modifying the "Focus Prevention Windows" to read as
follows:</xhtml:p>
<xhtml:pre><xhtml:code class="language-text">(any) &amp; !(class=Mumbles)
</xhtml:code></xhtml:pre>
<xhtml:p>To test it, I placed the script in
<xhtml:code>$HOME/.irssi/scripts/mumbles.pl</xhtml:code>, and then, in irssi,
executed <xhtml:code>/load mumbles.pl</xhtml:code>.</xhtml:p>
<xhtml:p>Once I had it to my liking, I symlinked it into my
<xhtml:code>$HOME/.irssi/scripts/autorun/</xhtml:code> directory, allowing it
to run as soon as irssi loads. I can now have irssi running in a
screen session, or minimize the terminal, and get notifications —
keeping me productive and informed at the same time.</xhtml:p>
<xhtml:p><xhtml:strong>UPDATED 2008-12-12:</xhtml:strong> Added information on how to
load the script, as well as fixed the location to the autorun
directory. Thanks, @sidhighwind!</xhtml:p>
<xhtml:div class="h-entry"><xhtml:img class="u-photo photo" width="50" src="https://avatars0.githubusercontent.com/u/25943?v=3&amp;u=79dd2ea1d4d8855944715d09ee4c86215027fa80&amp;s=140" alt="matthew"/> <xhtml:a class="u-url u-uid p-name" href="https://mwop.net/blog/197-Mumbles-irssi-integration.html">Mumbles
irssi integration</xhtml:a> was originally published <xhtml:time class="dt-published" datetime="2008-12-10T15:01:50-06:00">10 December
2008</xhtml:time> on <xhtml:a href="https://mwop.net">https://mwop.net</xhtml:a> by
<xhtml:a rel="author" class="p-author" href="https://mwop.net">Matthew
Weier O'Phinney</xhtml:a>.</xhtml:div>
</xhtml:div>
    </content>
  </entry>
  <entry xmlns:xhtml="http://www.w3.org/1999/xhtml">
    <title type="html"><![CDATA[Vimgrep and Vim Project]]></title>
    <published>2008-10-21T07:36:49-05:00</published>
    <updated>2008-10-22T21:55:03-05:00</updated>
    <link rel="alternate" type="text/html" href="https://mwop.net/blog/194-Vimgrep-and-Vim-Project.html"/>
    <id>https://mwop.net/blog/194-Vimgrep-and-Vim-Project.html</id>
    <author>
      <name>Matthew Weier O'Phinney</name>
      <email>contact@mwop.net</email>
      <uri>https://mwop.net</uri>
    </author>
    <content xmlns:xhtml="http://www.w3.org/1999/xhtml" type="xhtml">
      <xhtml:div xmlns:xhtml="http://www.w3.org/1999/xhtml"><xhtml:p>Chris Hartjes today was <xhtml:a href="http://www.littlehart.net/atthekeyboard/2008/10/20/vim-programming-bounty-fuzzyfind-inside-files/">
on a quest for a "find in project" feature for Vim</xhtml:a>. "Find in
Project" was a feature of Textmate that he'd grown accustomed to
and was having trouble finding an equivalent for.</xhtml:p>
<xhtml:p>The funny thing is that Textmate is a newcomer, and, of course,
vim has had such a feature for years. The thing to remember with
vim, of course, is its unix roots; typically if you know the unix
command for doing something, you can find what you need in vim. In
this case, the key is the vimgrep plugin, which ships in the
standard vim distribution.</xhtml:p>
<xhtml:p>There are a variety of resources on vimgrep. The vim
documentation includes a chapter on it, and a quick <xhtml:a href="http://www.google.com/search?q=vimgrep">google search</xhtml:a> on the
subject turns up some nice tutorials immediately. If you've ever
used grep, the syntax is very straightforward:</xhtml:p>
<xhtml:pre><xhtml:code class="language-markdown hljs markdown" data-lang="markdown">vimgrep /{pattern}/[<xhtml:span class="hljs-string">g</xhtml:span>][<xhtml:span class="hljs-symbol">j</xhtml:span>] {file} ...
</xhtml:code></xhtml:pre>
<xhtml:p>The "g" option indicates that all matches for a search will be
returned instead of just one per line, and the "j" option tells vim
<xhtml:em>not</xhtml:em> to jump to the first match automatically. What does
the "g" flag really mean, though, and how are searches
returned?</xhtml:p>
<xhtml:p>Vimgrep returns search results in what's known as a "quickfix"
window, and this is where the vimgrep documentation falls apart… it
doesn't explain what this is, or link to it (which would be a nice
indication that it actually has a separate topic for this).</xhtml:p>
<xhtml:p>The Quickfix window is a pane that shows a search result per
line. Each line shows the file that matches, the line number, and
the contents of that line:</xhtml:p>
<xhtml:pre><xhtml:code class="language-awk hljs awk" data-lang="awk"><xhtml:span class="hljs-regexp">/home/m</xhtml:span>atthew<xhtml:span class="hljs-regexp">/git/</xhtml:span>bugapp<xhtml:span class="hljs-regexp">/application/</xhtml:span>controllers<xhtml:span class="hljs-regexp">/helpers/</xhtml:span>GetForm.php|<xhtml:span class="hljs-number">10</xhtml:span>| * @var Zend_Loader_PluginLoader
</xhtml:code></xhtml:pre>
<xhtml:p>You can't do much from this window; it simply serves as a visual
indicator of what file you're currently looking at from the list.
However, in the main window, you can start iterating through the
results one at a time, using a subset of the Quickfix commands. As
a quick summary:</xhtml:p>
<xhtml:ul>
<xhtml:li><xhtml:strong>:cc</xhtml:strong> will move to the next match in the
list</xhtml:li>
<xhtml:li><xhtml:strong>:cn</xhtml:strong> will move to the next match in the
list</xhtml:li>
<xhtml:li><xhtml:strong>:cp</xhtml:strong> will move to the previous match in the
list</xhtml:li>
<xhtml:li><xhtml:strong>:cr</xhtml:strong> will rewind to the first match in the
list</xhtml:li>
<xhtml:li><xhtml:strong>:cla</xhtml:strong> will fast forward to the last match in
the list</xhtml:li>
</xhtml:ul>
<xhtml:p>When done, you can simply close the Quickfix window/pane, and
continue working.</xhtml:p>
<xhtml:p>I should note that vimgrep <xhtml:em>is</xhtml:em> cross-platform. On
*nix-based systems, it defaults to using the native grep command,
but it also contains an internal (slower) implementation for use on
operating systems that do not provide grep by default. You may also
map the command to alternate implementations if desired.</xhtml:p>
<xhtml:p>I personally use this feature most with the <xhtml:a href="http://www.vim.org/scripts/script.php?script_id=69">project
plugin</xhtml:a>. Project maps vimgrep to two different commands:
<xhtml:code>&lt;Leader&gt;g</xhtml:code> and <xhtml:code>&lt;Leader&gt;G</xhtml:code>. The
first will grep all files in the current project at the current
level; the second does the same, but also recurses into
subprojects. This is an incredibly easy way to refactor code,
particularly for name changes.</xhtml:p>
<xhtml:div class="h-entry"><xhtml:img class="u-photo photo" width="50" src="https://avatars0.githubusercontent.com/u/25943?v=3&amp;u=79dd2ea1d4d8855944715d09ee4c86215027fa80&amp;s=140" alt="matthew"/> <xhtml:a class="u-url u-uid p-name" href="https://mwop.net/blog/194-Vimgrep-and-Vim-Project.html">Vimgrep
and Vim Project</xhtml:a> was originally published <xhtml:time class="dt-published" datetime="2008-10-21T07:36:49-05:00">21 October
2008</xhtml:time> on <xhtml:a href="https://mwop.net">https://mwop.net</xhtml:a> by
<xhtml:a rel="author" class="p-author" href="https://mwop.net">Matthew
Weier O'Phinney</xhtml:a>.</xhtml:div>
</xhtml:div>
    </content>
  </entry>
  <entry xmlns:xhtml="http://www.w3.org/1999/xhtml">
    <title type="html"><![CDATA[Vim 7 code completion]]></title>
    <published>2006-09-19T17:45:00-05:00</published>
    <updated>2006-09-22T09:21:27-05:00</updated>
    <link rel="alternate" type="text/html" href="https://mwop.net/blog/123-Vim-7-code-completion.html"/>
    <id>https://mwop.net/blog/123-Vim-7-code-completion.html</id>
    <author>
      <name>Matthew Weier O'Phinney</name>
      <email>contact@mwop.net</email>
      <uri>https://mwop.net</uri>
    </author>
    <content xmlns:xhtml="http://www.w3.org/1999/xhtml" type="xhtml">
      <xhtml:div xmlns:xhtml="http://www.w3.org/1999/xhtml"><xhtml:p>I may work at <xhtml:a href="http://www.zend.com/">Zend</xhtml:a>, but I've
never been a fan of IDEs. They simply don't suit my programming
style. I can usually keep track of file locations in my head pretty
easily, and what I really need is a blank slate on which I can
write, and one that doesn't consume resource that can better be
used running web servers and other programs. Syntax highlighting,
good indentation — these are important, but you can get these from
good, minimal text editors very easily. <xhtml:a href="http://www.vim.org">Vim is my editor of choice</xhtml:a>.</xhtml:p>
<xhtml:p>I will admit, though, that one area where I have had IDE-envy is
the area of code completion. I often find myself doing quick
lookups to php.net or perldoc to determine the order of arguments
to a function or method call, or checking for the expected return
value. Most of the time, this doesn't take much time, however, so I
just live with it.</xhtml:p>
<xhtml:p>Today, however, cruising through the blogosphere, I came across
<xhtml:a href="http://linuxhelp.blogspot.com/2006/09/visual-walk-through-of-couple-of-new.html">
an article showcasing some new features of Vim 7.0</xhtml:a>, and
discovered Vim 7's code completion.</xhtml:p>
<xhtml:p>Basically, while in insert mode, you can type <xhtml:code>&lt;C-x&gt;
&lt;C-o&gt;</xhtml:code> to have vim attempt to autocomplete the current
keyword. If more than one possibility exists, it shows a dropdown,
and you can use your arrow keys to highlight the keyword that you
wish to use.</xhtml:p>
<xhtml:p>But it gets better! Not only does it do this kind of
autocompletion, but it also opens a small 'scratch preview' pane
showing the function/method signature — i.e., the expected
arguments and return value!</xhtml:p>
<xhtml:p>I thought I had little need for IDEs before… now I have even
less! Bram and the rest of the Vim team, my hat's off to you for
more fine work!</xhtml:p>
<xhtml:div class="h-entry"><xhtml:img class="u-photo photo" width="50" src="https://avatars0.githubusercontent.com/u/25943?v=3&amp;u=79dd2ea1d4d8855944715d09ee4c86215027fa80&amp;s=140" alt="matthew"/> <xhtml:a class="u-url u-uid p-name" href="https://mwop.net/blog/123-Vim-7-code-completion.html">Vim 7 code
completion</xhtml:a> was originally published <xhtml:time class="dt-published" datetime="2006-09-19T17:45:00-05:00">19 September 2006</xhtml:time> on
<xhtml:a href="https://mwop.net">https://mwop.net</xhtml:a> by <xhtml:a rel="author" class="p-author" href="https://mwop.net">Matthew Weier
O'Phinney</xhtml:a>.</xhtml:div>
</xhtml:div>
    </content>
  </entry>
  <entry xmlns:xhtml="http://www.w3.org/1999/xhtml">
    <title type="html"><![CDATA[Telcos are Attacking the Internet]]></title>
    <published>2006-04-28T11:31:00-05:00</published>
    <updated>2006-04-28T13:47:28-05:00</updated>
    <link rel="alternate" type="text/html" href="https://mwop.net/blog/107-Telcos-are-Attacking-the-Internet.html"/>
    <id>https://mwop.net/blog/107-Telcos-are-Attacking-the-Internet.html</id>
    <author>
      <name>Matthew Weier O'Phinney</name>
      <email>contact@mwop.net</email>
      <uri>https://mwop.net</uri>
    </author>
    <content xmlns:xhtml="http://www.w3.org/1999/xhtml" type="xhtml">
      <xhtml:div xmlns:xhtml="http://www.w3.org/1999/xhtml"><xhtml:p>I generally try to stay out of politics on this blog, but this
time something has to be said, as it affects anyone who uses the
internet, at least in the US.</xhtml:p>
<xhtml:p>Basically, a number of telcos and cable providers are talking
about charging internet content providers — the places you browse
to on the internet, places like Google, Yahoo!, Amazon, etc. — fees
to ensure bandwidth to their sites. Their argument is that these
content providers are getting a 'free ride' on their lines, and
generating a lot of traffic themselves, and should thus be paying
for the cost of bandwidth.</xhtml:p>
<xhtml:p>This is patently ridiculous. Content providers already have to
pay for their bandwidth — they, too, have ISPs or agreements with
telcos in place, either explicitly or via their hosting providers.
Sure, some of them, particularly search engines, send out robots in
order to index or find content, but, again, they're paying for the
bandwidth those robots generate. Additionally, people using the
internet are typically paying for bandwidth as well, through their
relationship with their ISP. What this amounts to is the telcos
getting paid not just by each person to whom they provide internet
access, but every end point on the internet, at least those within
the US.</xhtml:p>
<xhtml:p>What this is really about is telcos wanting more money, and
wanting to push their own content. As an example, let's say your
ISP is AOL. AOL is part of Time Warner, and thus has ties to those
media sources. Now, those media sources may put pressure on AOL to
reduce bandwidth to sites operated by ABC, CBS, NBC, FOX, Disney,
PBS, etc. This might mean that your kid can no longer visit the
Sesame Street website reliably, because AOL has reduced the amount
of bandwidth allowed to that service — but any media site in the
TWC would get optimal access, so they could get to Cartoon Network.
Not to slam Cartoon Network (I love it), but would you rather have
your kid visiting cartoonnetwork.com or pbskids.org? Basically,
content providers would not need to compete based on the value of
their content, but on who they can get to subscribe to their
service.</xhtml:p>
<xhtml:p>Here's another idea: your ISP is MSN. You want to use Google…
but MSN has limited the bandwidth to Google because it's a
competitor, and won't accept any amount of money to increase that
bandwidth. They do the same with Yahoo! So, now you're limited to
MSN search, because that's the only one that responds reliably —
regardless of whether or not you like their search results. By
doing so, they've just artificially inflated the value of their
search engine — without needing to compete based on merit.</xhtml:p>
<xhtml:p>Additionally, let's say Barnes and Noble has paid MSN to ensure
good bandwidth, but part of that agreement is a non-compete clause.
Now you find your connections to Amazon timing out, meaning that
you can't even see which book provider has the better price on the
book you want; you're stuck looking and buying from B&amp;N.</xhtml:p>
<xhtml:p>Now, let's look at something a little more close to home for
those of us developing web applications. There have been a number
of success stories the last few years: MySpace, Digg, and Flickr
all come to mind. Would these endeavors have been as successful had
they needed to pay multiple times for bandwidth, once to their ISP
and once each to each telco charging for content providers? Indeed,
some of these are still free services — how would they ever have
been able to pay the extra amounts to the telcos in the first
place?</xhtml:p>
<xhtml:p>So, basically, the only winners here are the telcos.</xhtml:p>
<xhtml:p>Considering how ludicrous this scheme is, one must be thinking,
isn't the US Government going to step in and regulate against such
behaviour? <xhtml:a href="http://www.businessweek.com/technology/content/apr2006/tc20060426_553893.htm?chan=technology_technology+index+page_more+of+today">
The answer, sadly, is no.</xhtml:a> The GOP doesn't like regulation, and
so they want market forces to decide. Sadly, what this will likely
do is force a number of content providers to offshore their
internet operations — which is likely to have some pretty negative
effects on the economy.</xhtml:p>
<xhtml:p>The decision isn't final — efforts can still be made to prevent
it (the above link references a Senate committee meeting; there's
been no vote on it). Call your representatives today and give them
an earful. Tell them it's not just about regulation of the
industry, but about fair competition in the market. Allowing the
telcos to extort money from content providers will only reduce the
US' economic chances in the world, and stifle innovation and
choice.</xhtml:p>
<xhtml:div class="h-entry"><xhtml:img class="u-photo photo" width="50" src="https://avatars0.githubusercontent.com/u/25943?v=3&amp;u=79dd2ea1d4d8855944715d09ee4c86215027fa80&amp;s=140" alt="matthew"/> <xhtml:a class="u-url u-uid p-name" href="https://mwop.net/blog/107-Telcos-are-Attacking-the-Internet.html">Telcos
are Attacking the Internet</xhtml:a> was originally published
<xhtml:time class="dt-published" datetime="2006-04-28T11:31:00-05:00">28
April 2006</xhtml:time> on <xhtml:a href="https://mwop.net">https://mwop.net</xhtml:a> by <xhtml:a rel="author" class="p-author" href="https://mwop.net">Matthew Weier
O'Phinney</xhtml:a>.</xhtml:div>
</xhtml:div>
    </content>
  </entry>
  <entry xmlns:xhtml="http://www.w3.org/1999/xhtml">
    <title type="html"><![CDATA[PHP error reporting for Perl users]]></title>
    <published>2006-03-27T23:10:00-06:00</published>
    <updated>2006-03-28T09:19:35-06:00</updated>
    <link rel="alternate" type="text/html" href="https://mwop.net/blog/105-PHP-error-reporting-for-Perl-users.html"/>
    <id>https://mwop.net/blog/105-PHP-error-reporting-for-Perl-users.html</id>
    <author>
      <name>Matthew Weier O'Phinney</name>
      <email>contact@mwop.net</email>
      <uri>https://mwop.net</uri>
    </author>
    <content xmlns:xhtml="http://www.w3.org/1999/xhtml" type="xhtml">
      <xhtml:div xmlns:xhtml="http://www.w3.org/1999/xhtml"><xhtml:p>On <xhtml:a href="http://www.perlmonks.org">perlmonks</xhtml:a> today, a
user was needing to maintain a PHP app, and wanted to know what the
PHP equivalent of <xhtml:code>perl -wc script.pl</xhtml:code> was —
specifically, they wanted to know how to run a PHP script from the
commandline and have it display any warnings (ala perl's strict and
warnings pragmas).</xhtml:p>
<xhtml:p>Unfortunately, there's not as simple a way to do this in PHP as
in perl. Basically, you need to do the following:</xhtml:p>
<xhtml:ul>
<xhtml:li>
<xhtml:p><xhtml:strong>To display errors:</xhtml:strong></xhtml:p>
<xhtml:ul>
<xhtml:li>In your <xhtml:code>php.ini</xhtml:code> file, set <xhtml:code>display_errors =
On</xhtml:code>, <xhtml:strong>or</xhtml:strong></xhtml:li>
<xhtml:li>In your script, add the line <xhtml:code>ini_set('display_errors',
true);</xhtml:code></xhtml:li>
</xhtml:ul>
</xhtml:li>
<xhtml:li>
<xhtml:p><xhtml:strong>To show notices, warnings, errors, deprecation
notices:</xhtml:strong></xhtml:p>
<xhtml:ul>
<xhtml:li>In your <xhtml:code>php.ini</xhtml:code> file, set <xhtml:code>error_reporting =
E_ALL | E_STRICT</xhtml:code>, <xhtml:strong>or</xhtml:strong></xhtml:li>
<xhtml:li>In your script, add the line <xhtml:code>error_reporting(E_ALL |
E_STRICT);</xhtml:code></xhtml:li>
</xhtml:ul>
</xhtml:li>
</xhtml:ul>
<xhtml:p>Alternatively, you can create a file with the lines:</xhtml:p>
<xhtml:pre><xhtml:code class="language-php hljs php" data-lang="php"><xhtml:span class="hljs-meta">&lt;?php</xhtml:span>
error_reporting(E_ALL | E_STRICT);
ini_set(<xhtml:span class="hljs-string">'display_errors'</xhtml:span>, <xhtml:span class="hljs-keyword">true</xhtml:span>);
</xhtml:code></xhtml:pre>
<xhtml:p>and then set the <xhtml:code>php.ini</xhtml:code> setting
<xhtml:code>auto_prepend_file</xhtml:code> to the path to that file.</xhtml:p>
<xhtml:p><xhtml:strong>NOTE: do not do any of the above on a production
system!</xhtml:strong> PHP's error messages often reveal a lot about your
applications, including file layout and potential vectors of
attack. Turn <xhtml:code>display_errors</xhtml:code> off on production
machines, set your <xhtml:code>error_reporting</xhtml:code> somewhat lower, and
<xhtml:code>log_errors</xhtml:code> to a file so you can keep track of what's
going on on your production system.</xhtml:p>
<xhtml:p>The second part of the question was how to run a PHP script on
the command line. This is incredibly simple: <xhtml:code>php
myscript.php</xhtml:code>. No different than any other scripting
language.</xhtml:p>
<xhtml:p>You can get some good information by using some of the switches,
though. <xhtml:strong><xhtml:code>-l</xhtml:code></xhtml:strong> turns the PHP interpreter
into a linter, and can let you know if your code is well-formed
(which doesn't necessarily preclude runtime or parse errors).
<xhtml:strong><xhtml:code>-f</xhtml:code></xhtml:strong> will run the script through the
parser, which can give you even more information. I typically bind
these actions to keys in vim so I can check my work as I go.</xhtml:p>
<xhtml:p>If you plan on running your code <xhtml:em>solely</xhtml:em> on the
commandline, add a shebang to the first line of your script:
<xhtml:code>#!/path/to/php</xhtml:code>. Then make the script executable, and
you're good to go. This is handy for cronjobs, or batch processing
scripts.</xhtml:p>
<xhtml:p>All of this information is readily available in <xhtml:a href="http://www.php.net/manual">the PHP manual</xhtml:a>, and the commandline
options are always available by passing the <xhtml:code>--help</xhtml:code>
switch to the PHP executable. So, start testing your scripts
already!</xhtml:p>
<xhtml:div class="h-entry"><xhtml:img class="u-photo photo" width="50" src="https://avatars0.githubusercontent.com/u/25943?v=3&amp;u=79dd2ea1d4d8855944715d09ee4c86215027fa80&amp;s=140" alt="matthew"/> <xhtml:a class="u-url u-uid p-name" href="https://mwop.net/blog/105-PHP-error-reporting-for-Perl-users.html">
PHP error reporting for Perl users</xhtml:a> was originally published
<xhtml:time class="dt-published" datetime="2006-03-27T23:10:00-06:00">27
March 2006</xhtml:time> on <xhtml:a href="https://mwop.net">https://mwop.net</xhtml:a> by <xhtml:a rel="author" class="p-author" href="https://mwop.net">Matthew Weier
O'Phinney</xhtml:a>.</xhtml:div>
</xhtml:div>
    </content>
  </entry>
  <entry xmlns:xhtml="http://www.w3.org/1999/xhtml">
    <title type="html"><![CDATA[Sign of a Geek]]></title>
    <published>2004-11-17T16:04:39-06:00</published>
    <updated>2004-11-17T16:05:42-06:00</updated>
    <link rel="alternate" type="text/html" href="https://mwop.net/blog/51-Sign-of-a-Geek.html"/>
    <id>https://mwop.net/blog/51-Sign-of-a-Geek.html</id>
    <author>
      <name>Matthew Weier O'Phinney</name>
      <email>contact@mwop.net</email>
      <uri>https://mwop.net</uri>
    </author>
    <content xmlns:xhtml="http://www.w3.org/1999/xhtml" type="xhtml">
      <xhtml:div xmlns:xhtml="http://www.w3.org/1999/xhtml"><xhtml:p>It's now been confirmed: I'm a geek.</xhtml:p>
<xhtml:p>Okay, so that probably comes as no shocker to those of you who
know me, but it's the little things that make me realize it
myself.</xhtml:p>
<xhtml:p>I've been frequenting <xhtml:a href="http://www.perlmonks.org">Perl
Monks</xhtml:a> for a couple of years now, mainly to garner ideas and
code to help me with my personal or work projects. I rarely post
comments, and I've only once submitted a question to the site.
However, I <xhtml:strong>do</xhtml:strong> frequent the site regularly, and the
few comments I've put in — generally regarding usage of <xhtml:a href="http::/search.cpan.org/search?query=CGI%3A%3AApplication">CGI::Application</xhtml:a>
— have been typically well-moderated.</xhtml:p>
<xhtml:p>Well, yesterday I <xhtml:a href="http://www.perlmonks.org/?node_id=408255">made a comment</xhtml:a> to a
user <xhtml:a href="http://www.perlmonks.org/?node_id=408231">asking
about editors to use with perl</xhtml:a>. I was incensed by a remark he
made about <xhtml:a href="http://www.vim.org">VIM</xhtml:a> not having the
features he needed. Now, as I said in my comment, I've used VIM on
a daily basis for over two years, and I'm <xhtml:em>still</xhtml:em>
discovering new features — and I've used all of the features he was
looking for.</xhtml:p>
<xhtml:p>This is where I discovered I'm a geek: my comment made it into
the <xhtml:a href="http://www.perlmonks.org/?node=Best%20Nodes">Daily
Best</xhtml:a> for today, peaking around number 5. The fact that that
made my day indicates to me that I <xhtml:em>must</xhtml:em> be a geek.</xhtml:p>
<xhtml:p>Oh — and VIM rules!</xhtml:p>
<xhtml:div class="h-entry"><xhtml:img class="u-photo photo" width="50" src="https://avatars0.githubusercontent.com/u/25943?v=3&amp;u=79dd2ea1d4d8855944715d09ee4c86215027fa80&amp;s=140" alt="matthew"/> <xhtml:a class="u-url u-uid p-name" href="https://mwop.net/blog/51-Sign-of-a-Geek.html">Sign of a Geek</xhtml:a>
was originally published <xhtml:time class="dt-published" datetime="2004-11-17T16:04:39-06:00">17 November 2004</xhtml:time> on <xhtml:a href="https://mwop.net">https://mwop.net</xhtml:a> by <xhtml:a rel="author" class="p-author" href="https://mwop.net">Matthew Weier
O'Phinney</xhtml:a>.</xhtml:div>
</xhtml:div>
    </content>
  </entry>
  <entry xmlns:xhtml="http://www.w3.org/1999/xhtml">
    <title type="html"><![CDATA[PHP_SELF versus SCRIPT_NAME]]></title>
    <published>2004-10-12T21:34:57-05:00</published>
    <updated>2004-10-12T21:35:03-05:00</updated>
    <link rel="alternate" type="text/html" href="https://mwop.net/blog/45-PHP_SELF-versus-SCRIPT_NAME.html"/>
    <id>https://mwop.net/blog/45-PHP_SELF-versus-SCRIPT_NAME.html</id>
    <author>
      <name>Matthew Weier O'Phinney</name>
      <email>contact@mwop.net</email>
      <uri>https://mwop.net</uri>
    </author>
    <content xmlns:xhtml="http://www.w3.org/1999/xhtml" type="xhtml">
      <xhtml:div xmlns:xhtml="http://www.w3.org/1999/xhtml"><xhtml:p>I've standardized my PHP programming to use the environment
variable <xhtml:code>SCRIPT_NAME</xhtml:code> when I want my script to refer to
itself in links and form actions. I've known that
<xhtml:code>PHP_SELF</xhtml:code> has the same information, but I was more
familiar with the name <xhtml:code>SCRIPT_NAME</xhtml:code> from using it in
perl, and liked the feel of it more as it seems to describe the
resource better (<xhtml:code>PHP_SELF</xhtml:code> could stand for the path to
the PHP executable if I were to go by the name only).</xhtml:p>
<xhtml:p>However, I just noticed a post on the php.general newsgroup
where somebody asked what the difference was between them.
Semantically, there isn't any; they should contain the same
information. However, historically and technically speaking, there
is. <xhtml:code>SCRIPT_NAME</xhtml:code> is defined in the CGI 1.1
specification, and is thus a standard. <xhtml:em>However</xhtml:em>, not all
web servers actually implement it, and thus it isn't necessarily
<xhtml:em>portable</xhtml:em>. <xhtml:code>PHP_SELF</xhtml:code>, on the other hand, is
implemented directly by PHP, and as long as you're programming in
PHP, will always be present.</xhtml:p>
<xhtml:p>Guess I have some grep and sed in my future as I change a bunch
of scripts…</xhtml:p>
<xhtml:div class="h-entry"><xhtml:img class="u-photo photo" width="50" src="https://avatars0.githubusercontent.com/u/25943?v=3&amp;u=79dd2ea1d4d8855944715d09ee4c86215027fa80&amp;s=140" alt="matthew"/> <xhtml:a class="u-url u-uid p-name" href="https://mwop.net/blog/45-PHP_SELF-versus-SCRIPT_NAME.html">PHP_SELF
versus SCRIPT_NAME</xhtml:a> was originally published <xhtml:time class="dt-published" datetime="2004-10-12T21:34:57-05:00">12 October
2004</xhtml:time> on <xhtml:a href="https://mwop.net">https://mwop.net</xhtml:a> by
<xhtml:a rel="author" class="p-author" href="https://mwop.net">Matthew
Weier O'Phinney</xhtml:a>.</xhtml:div>
</xhtml:div>
    </content>
  </entry>
</feed>
