<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

  <title><![CDATA[Jason McCreary]]></title>
  <link href="http://jason.pureconcepts.net/atom.xml" rel="self"/>
  <link href="http://jason.pureconcepts.net/"/>
  <updated>2013-05-18T12:05:45-04:00</updated>
  <id>http://jason.pureconcepts.net/</id>
  <author>
    <name><![CDATA[Jason McCreary]]></name>
    
  </author>
  <generator uri="http://octopress.org/">Octopress</generator>

  
  <entry>
    <title type="html"><![CDATA[Contribute]]></title>
    <link href="http://jason.pureconcepts.net/2013/05/contribute/"/>
    <updated>2013-05-18T10:36:00-04:00</updated>
    <id>http://jason.pureconcepts.net/2013/05/contribute</id>
    <content type="html"><![CDATA[<p>Before I talk about contributing to Open Source, I want to define <em>Open Source</em>. In asking people I&#8217;d hear words like: <em>public</em>, <em>free</em>, <em>software</em>, and <em>shared</em>. I want to discard <em>software</em>. As explained in <a href="http://haacked.com/archive/2012/02/16/open-source-and-open-source-software-are-not-the-same.aspx">Open Source and Open Source Software are not the same thing</a>… well you get the idea.</p>

<p>For the purpose of this post, the best of these is free. But not <em>free</em> in the sense you might think. Consider this quote:</p>

<blockquote><p>Not free as in beer, but free as in freedom.</p></blockquote>

<p>There&#8217;s a spirit behind Open Source. A free-spirit. I consider Open Source a philosophy. A philosophy to freely share with others. This philosophy creates an interdependence. Open Source could not exist without these free-spirits contributing back to the source.</p>

<p>But how do you contribute? Because of the strong link between Open Source and Open Source Software, many think you have to develop code. While this is one way to contribute, there are many others. My hope is you will find one that allows you to contribute to Open Source.</p>

<h2>Open Source Software</h2>

<p>As noted the most obvious way to contribute to Open Source is code. And most obvious way to do that is <a href="http://github.com" title="Social Coding">Github</a>.</p>

<p>GitHub makes it incredibly easy to release (push), copy (fork), and contribute (pull request) code. They&#8217;ve also done an excellent job of abstracting this process, while still keeping good development practices - source control.</p>

<p>Github is built atop <a href="http://git-scm.com">git</a>. If you&#8217;re just getting started with Github or git, I suggest browsing <a href="https://help.github.com">Github&#8217;s Help</a> and reading <a href="free%20digital%20copy">Pro Git</a>.</p>

<h2>Open Data</h2>

<p>We&#8217;ve reached the data age. You&#8217;ve probably heard the latest buzzword <em>Big Data</em>. Data, big or small, drives the Internet. And there is a growing movement towards <a href="http://www.opendatafoundation.org">Open Data</a>.</p>

<p>Many organizations have released their data to the public. Often in formats readily used by developers. A good example of this is <a href="https://explore.data.gov">U.S. Census Data</a>.</p>

<p>You don&#8217;t have to have big data to contribute. You just need data. If so, contribute your data.</p>

<h2>Open Service</h2>

<p>Similar to Open Data, services also drive the Internet. API&#8217;s are everywhere. Twitter and Google have led the way by opening their services. In turn, these services created entire ecosystems.</p>

<p>If you provide a service, consider releasing it as an Open Service. If you can not open all your services, you could adopt a <a href="http://mashable.com/category/freemium/">freemium model</a>. Your service could help foster another.</p>

<h2>Open Support</h2>

<p>Releasing code, data, or services is the easy part. Out in the wild, it needs support. It needs your help. To me this is the lifeblood of Open Source - its community. Without you, these projects would not survive.</p>

<p>Open source projects need communities. People to help support the project by testing, reporting bugs, and promoting growth. You don&#8217;t need to be a guru to support a project. Jump in and get started by sharing your experiences.</p>

<h2>Open Documentation</h2>

<p>Often Open Source projects lack documentation. After all developers hate documenting. If you use an Open Source project that lacks documentation, contribute by writing or expanding the documentation. You can also write tutorials. If you know another language contribute by translating the documentation to help the project reach more people.</p>

<h2>Open Design</h2>

<p>Developers rarely design. An Open Source project often lacks color. As a designer, contribute your creativity by helping brand the project.</p>

<h2>Open Sharing</h2>

<p>Finally, you can contribute by simply spreading the word about the Open Source projects you use. The goal of any Open Source project is to reach people. You promoting the project helps accomplish that goal. Write a blog post, tweet, or email the author to say <em>thanks</em>.</p>

<h2>Why Contribute</h2>

<p>Why should <em>you</em> contribute? Well, <em>sharing is caring</em>. We all just want to help, right? As noted, the Open Source spirit is a free-spirit.</p>

<p>Let&#8217;s be honest, we live in a  material world. Sometimes we follow more along the lines of <em>show me the money</em>. Contributing to Open Source is not without recognition.</p>

<p>Contributing can be a form of self-promotion. Employers often request Github accounts from potential candidates. Personally, my reputation on StackOverflow has led to many recruiter calls and talking points during interviews.</p>

<p>It&#8217;s also not uncommon for an author to earn money from their project. Organizations often use open source project, but will pay for consulting, installation, or support. In some cases, end-users pay to fix or improve projects.</p>

<p>Whatever your reason, start small. Any contribution helps. I know you&#8217;ll find the experience rewarding.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Buying a hatchet in Manhattan]]></title>
    <link href="http://jason.pureconcepts.net/2013/05/buying-a-hatchet-in-manhattan/"/>
    <updated>2013-05-07T07:05:00-04:00</updated>
    <id>http://jason.pureconcepts.net/2013/05/buying-a-hatchet-in-manhattan</id>
    <content type="html"><![CDATA[<p>I enjoy the outdoors. Last year I hiked 156 miles of the <a href="http://jason.pureconcepts.net/2012/04/bootstrapping-the-appalachian-trail/" title="Bootstrapping the Appalachian Trail">Appalachian Trail</a>. As soon as I finished I knew I would hike more.</p>

<p>I recently moved to New York. So once Spring was here to stay, I broke out the trail map. A train stops right along the Appalachian Trail 86 miles north of New York City.</p>

<p>Unfortunately not all of my gear made the move. Several items were left behind. One of which was my hatchet. I needed a replacement.</p>

<p>I set out to the local Home Depot over lunch. You see I am from Kentucky. Where Home Depot has a whole aisle of axes and a guy who could tell you about each one. So I didn&#8217;t think anything of it.</p>

<p>I jumped on the subway to midtown. There was a Home Depot off 23rd Street and Fifth Avenue in the Flatiron District.</p>

<p>This happened to be the fanciest Home Depot ever. Storefront windows. Elegant displays. The look of a retail store, not the concrete and orange steel of a standard Home Depot.</p>

<p>I walked straight in and asked:</p>

<blockquote><p>&#8220;Where are your axes and hatchets?&#8221;</p></blockquote>

<p>The preppiest Home Depot worker ever answered awkwardly:</p>

<blockquote><p>&#8220;Ahh. What are you doing?&#8221;</p></blockquote>

<p>I did not respond. Only stared at him waiting for the answer. Which I now realize likely made things more awkward.</p>

<p>He quickly became helpful.</p>

<blockquote><p>&#8220;Downstairs. In the back.&#8221;</p></blockquote>

<p>Needless to say, their selection was not great. Then again, why would anyone in Manhattan buy a hatchet?</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Common debugging for PHP and MySQL]]></title>
    <link href="http://jason.pureconcepts.net/2013/04/common-debugging-php-mysql/"/>
    <updated>2013-04-28T22:28:00-04:00</updated>
    <id>http://jason.pureconcepts.net/2013/04/common-debugging-php-mysql</id>
    <content type="html"><![CDATA[<p>I see <a href="http://stackoverflow.com/search?q=%5Bphp%5D+%5Bmysql%5D+%22database+error%22">many questions</a> on StackOverflow about database issues. This post aims to provide a checklist to help diagnose common issues. While this post contains PHP and MySQL code samples, this debugging checklist applies to other database platforms.</p>

<p>First, <a href="http://blog.jvroom.com/2012/02/08/debugging-hard-problems/" title="Debugging hard problems">debugging is hard</a>. Especially debugging database issues. Often times the best approach is to systematically rule out what cannot be the problem. This checklist adopts such an approach from a low to high level.</p>

<h2>Can you connect to the database outside your application?</h2>

<p>Verify you can connect to your database by logging into MySQL from the command line.</p>

<pre><code>mysql -u dbuser -p -h localhost database
</code></pre>

<p>If you have a specific database user for your application, be sure to verify their credentials as well.</p>

<p>If you do not have command line access, you can use another database administration tool (e.g. PHPMyAdmin).</p>

<p>If you cannot connect to the database, you need to start at the beginning: Ensure MySQL is running, your database exists, and your credentials are correct.</p>

<h2>Can you connect to the database insider your application?</h2>

<p>Verify you can connect to the database from PHP. Test with a separate script to also rule out bugs in your codebase:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
</pre></td><td class='code'><pre><code class='php'><span class='line'><span class="cp">&lt;?php</span>
</span><span class='line'><span class="nv">$link</span> <span class="o">=</span> <span class="nb">mysqli_connect</span><span class="p">(</span><span class="s1">&#39;localhost&#39;</span><span class="p">,</span> <span class="s1">&#39;my_user&#39;</span><span class="p">,</span> <span class="s1">&#39;my_password&#39;</span><span class="p">,</span> <span class="s1">&#39;my_db&#39;</span><span class="p">);</span>
</span><span class='line'>
</span><span class='line'><span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nv">$link</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'>    <span class="k">die</span><span class="p">(</span><span class="s1">&#39;Connect Error (&#39;</span> <span class="o">.</span> <span class="nx">mysqli_connect_errno</span><span class="p">()</span> <span class="o">.</span> <span class="s1">&#39;) &#39;</span>
</span><span class='line'>            <span class="o">.</span> <span class="nx">mysqli_connect_error</span><span class="p">());</span>
</span><span class='line'><span class="p">}</span>
</span><span class='line'>
</span><span class='line'><span class="k">echo</span> <span class="s1">&#39;Connected... &#39;</span> <span class="o">.</span> <span class="nx">mysqli_get_host_info</span><span class="p">(</span><span class="nv">$link</span><span class="p">)</span> <span class="o">.</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">;</span>
</span></code></pre></td></tr></table></div></figure>


<p>If this code connects, but your application code does not, debug your application code.</p>

<p>If this code does not connect use the output for clues. You can also check your PHP error logs. It&#8217;s likely your MySQL module is misconfigured. Use <code>phpinfo()</code> to review your MySQL configuration.</p>

<h2>Does your query run successfully?</h2>

<p>More often than not the query is the problem. Especially if the query is generated dynamically. The best way to verify your query it to output and run it yourself.</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
</pre></td><td class='code'><pre><code class='php'><span class='line'><span class="x">$sql = &#39;SELECT column FROM table WHERE column = $bad_var&#39;;</span>
</span><span class='line'><span class="x">echo $sql;</span>
</span><span class='line'><span class="x">if (!$mysqli-&gt;query($sql)) {</span>
</span><span class='line'><span class="x">    echo &#39;Error: &#39;, $mysqli-&gt;error;</span>
</span><span class='line'><span class="x">}</span>
</span></code></pre></td></tr></table></div></figure>


<p>In this case, we&#8217;d see that $bad_var is not set. As such, the query becomes:</p>

<pre><code>SELECT column FROM table WHERE column = 
</code></pre>

<p><strong>Note:</strong> This code above is a contrived example of a dynamic query. If you do not see <em>what else</em> is wrong with this query, please read about <a href="http://stackoverflow.com/questions/60174/how-to-prevent-sql-injection-in-php/60496" title="How to prevent SQL injection in PHP">SQL injection</a>.</p>

<p>You can debug in any order. Top down or bottom up. Just remember this is by no means exhaustive. Nonetheless, following this debugging checklist will help diagnose a <em>majority</em> of your database issues. Please share other common database debugging you use.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Updated: WordPress Multitenacy]]></title>
    <link href="http://jason.pureconcepts.net/2013/04/updated-wordpress-multitenancy/"/>
    <updated>2013-04-08T12:33:00-04:00</updated>
    <id>http://jason.pureconcepts.net/2013/04/updated-wordpress-multitenancy</id>
    <content type="html"><![CDATA[<p>Although I <a href="http://jason.pureconcepts.net/2013/01/migrating-wordpress-octopress/" title="Migrate WordPress to Octopress">migrated this blog to Octopress</a>, I still develop with WordPress. A few months ago I shared a solution for <a href="http://jason.pureconcepts.net/2012/08/wordpress-multitenancy/" title="WordPress Multitenancy">WordPress multitenancy</a>. This post received great feedback. I incorporated several suggestions into an updated WordPress multitenant install.</p>

<h2>A single WordPress symlink</h2>

<p>My original solution symlinked all-the-things. The entire top-level WordPress structure symlinked to the core WordPress install. While this works, it&#8217;s brittle. If the top-level WordPress structure changed in a new version the tenant install may break. Although I mitigated this with an install script, there was room for improvement.</p>

<p><em>Bastiaan</em> pointed out that you could <a href="http://codex.wordpress.org/Giving_WordPress_Its_Own_Directory">move WordPress into its own directory</a>. After following the steps outlined in the WordPress Codex (carefully in order) you can use a single symlink. A much cleaner solution.</p>

<p>Having a single symlink also makes maintaining tenant installs easier. I can quietly install a new version of WordPress while tenant sites safely point to an old. Then update their symlink (thus updating WordPress) as needed.</p>

<h2>WordPress Must Use Plugins</h2>

<p>WordPress also introduced <a href="http://codex.wordpress.org/Must_Use_Plugins">Must Use Plugins</a>. A WordPress install <em>must use</em> these plugins - meaning they are automatically activated, and can not be deactivated. Using <code>WPMU_PLUGIN_DIR</code> and <code>WPMU_PLUGIN_URL</code> I can configure the location of <code>mu-plugins</code> just as I did for <code>wp-content</code>. Now the WordPress multitenant install can share even more between the tenants.</p>

<h2>A note about security</h2>

<p><em>Strebel</em> left a comment that there were <em>&#8220;significant security concerns&#8221;</em> with my WordPress multitenant solution. Unfortunately he did not elaborate. Thanks <em>Strebel</em>…</p>

<p>I am not a sysadmin. Nonetheless, to mitigate any security concerns I set permissions of the core WordPress directories and files to 755 and 644 respectively. In addition, all of the core WordPress are owned by a non-tenant, non-web user. <strong>Note:</strong> This will not work in an suPHP environment.</p>

<p>In addition, I have moved some of the configuration settings related to the multitenant install to the core <code>wp-config.php</code>. This prevents tenants from changing their configuration. And as you can not redeclare PHP contants, they can not overwrite this configuration.</p>

<figure class='code'><figcaption><span>Core wp-config.php</span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
</pre></td><td class='code'><pre><code class='php'><span class='line'><span class="x">// set global configurations</span>
</span><span class='line'><span class="x">define(&#39;WP_CONTENT_DIR&#39;, $_SERVER[&#39;DOCUMENT_ROOT&#39;] . &#39;/wp-content&#39;);</span>
</span><span class='line'><span class="x">define(&#39;WP_CONTENT_URL&#39;, &#39;http://&#39; . $_SERVER[&#39;SERVER_NAME&#39;] . &#39;/wp-content&#39;);</span>
</span><span class='line'>
</span><span class='line'><span class="x">// load site-specific configurations</span>
</span><span class='line'><span class="x">require_once dirname($_SERVER[&#39;DOCUMENT_ROOT&#39;]) . &#39;/wp-config.php&#39;;</span>
</span></code></pre></td></tr></table></div></figure>


<p>I also follow common WordPress secuity practices, such moving <code>wp-config.php</code> outside webroot for both the core and tenant installs.</p>

<h2>WordPress multitenant structure</h2>

<p>The web directory of a tenant using the updated WordPress multitenant install:</p>

<pre><code>webroot$ ls -l
total 16
-rw-r--r--  1 jason  staff  200 Mar 30 13:35 .htaccess
-rw-r--r--  1 jason  staff  405 Mar 30 16:17 index.php
lrwxr-xr-x  1 jason  staff   20 Apr  6 14:30 wordpress -&gt; /opt/wordpress/3.5.1
drwxr-xr-x  6 jason  staff  204 Mar 30 16:35 wp-content
</code></pre>

<p>A few notes:</p>

<ul>
<li>Core WordPress files live in a versioned subdirectory of <code>/opt/wordpress/</code>. Such a structure allows for multiple WordPress installs.</li>
<li><code>wp-content</code> lives at the top-level.</li>
<li><code>mu-plugins</code> is a symlink under <code>wp-content</code>.</li>
</ul>


<p>As always, I welcome your feedback.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[PHP Namespaces: Avoid use]]></title>
    <link href="http://jason.pureconcepts.net/2013/04/php-namespaces-avoid-use/"/>
    <updated>2013-04-01T22:46:00-04:00</updated>
    <id>http://jason.pureconcepts.net/2013/04/php-namespaces-avoid-use</id>
    <content type="html"><![CDATA[<p><code>use</code> breaks the fundamental aspects of PHP namespaces. Avoid <code>use</code>.</p>

<p>Oh, you want to know <em>why</em>? Fine. Keep reading.</p>

<p>Let&#8217;s review the fundamental aspects of PHP namespaces as stated in the <a href="http://www.php.net/manual/en/language.namespaces.rationale.php">PHP Docs Namespace Overview</a>:</p>

<blockquote><p>namespaces are designed to solve two problems that authors of libraries and applications encounter when creating re-usable code elements</p></blockquote>

<p>So namespaces focus on  <em>re-usable code elements</em>. Let&#8217;s look at the two problems:</p>

<blockquote><ol>
<li>Name collisions between code you create, and internal PHP classes/functions/constants or third-party classes/functions/constants.</li>
<li>Ability to alias (or shorten) Extra_Long_Names designed to alleviate the first problem, improving readability of source code.</li>
</ol>
</blockquote>

<p><code>namespace</code> solves problem #1. <code>use</code> solves problem #2. But things can get circular. <code>use</code> can introduce name collisions and confusion. Which respectively reintroduces problem #1 and is the opposite of <em>improving readability</em>.</p>

<p>Consider the following namespaces and classes:</p>

<figure class='code'><figcaption><span>MyApp/Service.php</span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
</pre></td><td class='code'><pre><code class='php'><span class='line'><span class="x">namespace MyApp;</span>
</span><span class='line'>
</span><span class='line'><span class="x">class Service {</span>
</span><span class='line'><span class="x">  public function method() {</span>
</span><span class='line'><span class="x">      echo __NAMESPACE__ . &#39;\Service&#39;;</span>
</span><span class='line'><span class="x">  }</span>
</span><span class='line'><span class="x">}</span>
</span></code></pre></td></tr></table></div></figure>




<figure class='code'><figcaption><span>MyApp/ComponentA/Service.php</span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
</pre></td><td class='code'><pre><code class='php'><span class='line'><span class="x">namespace MyApp\ComponentA;</span>
</span><span class='line'>
</span><span class='line'><span class="x">class Service {</span>
</span><span class='line'><span class="x">  public function method() {</span>
</span><span class='line'><span class="x">      echo __NAMESPACE__ . &#39;\Service&#39;;</span>
</span><span class='line'><span class="x">  }</span>
</span><span class='line'><span class="x">}</span>
</span></code></pre></td></tr></table></div></figure>


<p>A <code>Controller</code> class with <code>use</code>:</p>

<figure class='code'><figcaption><span>MyApp/Controller.php</span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
</pre></td><td class='code'><pre><code class='php'><span class='line'><span class="x">namespace MyApp;</span>
</span><span class='line'>
</span><span class='line'><span class="x">use MyApp\ComponentA\Service;</span>
</span><span class='line'>
</span><span class='line'><span class="x">class Controller {</span>
</span><span class='line'><span class="x">  public function output() {</span>
</span><span class='line'><span class="x">      $service = new Service();</span>
</span><span class='line'><span class="x">      $service-&gt;method();</span>
</span><span class='line'><span class="x">  }</span>
</span><span class='line'><span class="x">}</span>
</span></code></pre></td></tr></table></div></figure>


<p>Which <code>Service</code> class is created? <code>MyApp\Service</code> or <code>MyApp\ComponentA\Service</code>?</p>

<p>It may be straightfoward with the entire codebase in front of you. But consider a larger codebase. What if you refactored <code>output()</code> into another class? It all depends on the <code>use</code> statement. Meaning the code is tightly coupled with <code>use</code>.</p>

<p>The same <code>Controller</code> class without <code>use</code>:</p>

<figure class='code'><figcaption><span>MyApp/Controller.php</span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
</pre></td><td class='code'><pre><code class='php'><span class='line'><span class="x">namespace MyApp;</span>
</span><span class='line'>
</span><span class='line'><span class="x">class Controller {</span>
</span><span class='line'><span class="x">  public function output() {</span>
</span><span class='line'><span class="x">      $service = new MyApp\ComponentA\Service();</span>
</span><span class='line'><span class="x">      $service-&gt;method();</span>
</span><span class='line'><span class="x">  }</span>
</span><span class='line'><span class="x">}</span>
</span></code></pre></td></tr></table></div></figure>


<p>No question on which <code>Service</code> class is created and no coupling.</p>

<p>There are other problems with <code>use</code>, such as dynamic naming. But you don&#8217;t need more convincing. <code>use</code> breaks what namespaces solve.</p>

<p>Spend a few extra keystrokes typing absolute namespaces for code clarity and portability. Future developers will thank you.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Why I leave a job]]></title>
    <link href="http://jason.pureconcepts.net/2013/03/why-i-leave-a-job/"/>
    <updated>2013-03-25T21:51:00-04:00</updated>
    <id>http://jason.pureconcepts.net/2013/03/why-i-leave-a-job</id>
    <content type="html"><![CDATA[<p>After a short time I decided to leave my job as a Software Engineer at <a href="http://nytimes.com">The New York Times</a>. <em>The New York Times!</em> A dream job with a prestigious company. When people ask, &#8220;Where do you work?&#8221;, they don&#8217;t <em>really</em> care. But when I said, &#8220;The New York Times&#8221;, they started listening.</p>

<p>So why did I leave? It&#8217;s unfair to look at any specific job. I liked the The New York Times. So the question isn&#8217;t <em>why I left The New York Times</em>, but instead <em>why I leave a job</em>.</p>

<p>This is something I&#8217;ve reflected on after leaving each of my former jobs. Actually, I first drafted this post after leaving Humana in 2010. Over the years, I reduced the citeria down to three.</p>

<h2>Good Leader</h2>

<p>There&#8217;s an <a href="http://www.alaisterlow.com/employees-leave-managers-not-companies/">entire article</a> bouncing around the web recently dedicated to this topic. So I will not go into great detail on the importance of a good manager. We all want to work for someone we respect. A true leader. Someone in the chain of upper management must be a good leader.</p>

<h2>Talented Coworkers</h2>

<p><a href="http://jason.pureconcepts.net/2009/12/good_developer_routines/">Good developers learn</a>. I believe the best way to learn is to surround yourself with talented people. While I <em>believe</em> I am talented, I <em>know</em> I&#8217;m not the most talented. I want to be among peers not only so I improve, but we improve together. Anything else and you risk becoming a big fish in a little pond.</p>

<h2>A Bright Future</h2>

<p>Either personally or professionally, your job must offer growth. We&#8217;re human. We want to know that whatever we do, it&#8217;s done for the better. If your job isn&#8217;t going somewhere, you should go somewhere else.</p>

<p>Our society pushes a <em>live to work</em> mentality. I&#8217;ve never bought into that notion. In the words of <a href="http://en.wikipedia.org/wiki/Fight_Club">Tyler Durden</a>, &#8220;you&#8217;re not your fucking job&#8221;.</p>

<p>The average American spends a third of their adult life working. You should find a job you like. So I use these criterion to form my own mentality:</p>

<ul>
<li>Missing one - fine, nothing is perfect.</li>
<li>Missing two - the grass looks greener at a new job.</li>
<li>Missing all three - I give two-weeks notice.</li>
</ul>


<p>Some day my work/life balance will shift, and these things may not matter as much. But today is not that day.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[How to win Family Feud]]></title>
    <link href="http://jason.pureconcepts.net/2013/03/win-family-feud/"/>
    <updated>2013-03-03T15:32:00-05:00</updated>
    <id>http://jason.pureconcepts.net/2013/03/win-family-feud</id>
    <content type="html"><![CDATA[<p>Family Feud is my game show. I watched it growing up, at college, even on lunch breaks at work. To this day the <em>common</em> strategy frustrates me. I believe in an alternative strategy which will put you into the final round every time. I&#8217;m going to share it in hopes of changing the game of Family Feud forever.</p>

<p>First, for those not familiar, <a href="http://www.familyfeud.com" title="Family Feud Game Show">Family Feud</a> is a television game show. Two teams - typically families - compete against one another. They face-off to guess the top answers of a survey question. If you win the face-off, your family has three individual attempts to guess the rest of the top answers. If your family can not, the other family has the chance to <em>steal</em> if they guess one of the remaining answers. One family is awarded points from each round. The family with most points after a few rounds goes to the final round.</p>

<p>Now the <em>common</em> strategy is to <em>play</em> if you win the face-off. This is wrong. In fact, it&#8217;s ridiculous. Yes, I am saying everyone who has ever played Family Feud is wrong.</p>

<p>So what&#8217;s the secret to winning Family Feud&#8230; <em>defer</em>.</p>

<p>That&#8217;s right. It&#8217;s that simple. If you win the face-off, defer.</p>

<p>I&#8217;ve crunched the numbers on this (from my extensive viewership). You can flip the odds in your favor by defering. Put the pressure on the other family to guess all the answers. When they don&#8217;t (and they won&#8217;t) you <em>steal</em>.</p>

<p>Not convinced? Allow me to introduce something called <a href="http://en.wikipedia.org/wiki/Probability" title="Probability">Probability</a>. Family Feud surveys 100 people. You have to guess the top most common answers of these 100 people. Seems easy enough. And it is for a few answers. The rest of the answers occur far less frequently. This is called a <a href="http://en.wikipedia.org/wiki/Long_tail" title="Long Tail Distribution">long tail distribution</a>.</p>

<p>So, if you <em>play</em>, your family must guess <strong>all</strong> the top answers answers. That&#8217;s unlikely. Or shall I say improbable. Remember this survey is not from factual data. It&#8217;s from people. People who provide what I&#8217;ll call a subjective answer.</p>

<p>The probability of guessing the top answers in the face-off is very high. But the probability of guessing <strong>all</strong> the remaining long tail answers is low. So, instead, defer. Have the other family try, while your family has the time to think of <strong>one</strong> of the long tail answers together.</p>

<p>To this day, I have yet to see a family <em>defer</em> after winning the face-off. The desire to <em>play</em> is too great.</p>

<p>If you&#8217;re a contestent on Family Feud (or if Family Feud would like to put my family and I on the show) try this. You&#8217;ll make it to the finals. Just don&#8217;t forget to thank me when you win.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Forward-Compatible Code]]></title>
    <link href="http://jason.pureconcepts.net/2013/02/forward-compatibile-code/"/>
    <updated>2013-02-05T22:01:00-05:00</updated>
    <id>http://jason.pureconcepts.net/2013/02/forward-compatibile-code</id>
    <content type="html"><![CDATA[<p>Most developers know about backward-compatibility &mdash; ensuring code runs under past versions. But what about forward-compatibility? Developing code compatible with future versions can be equally important.</p>

<p>I recently had a task to update some legacy code. This code was high-profile. All of our stacks ran a version. So I needed to ensure that my updates were compatible.</p>

<p>Upon reviewing the code it contained a version variable (<code>VER</code>). Perfect! A version variable is perfect to use as a <a href="http://code.flickr.net/2009/12/02/flipping-out/" title="Feature Flags">feature flag</a>. I could wrap my updated code inside conditionals until the rest of the stacks were upgraded.</p>

<pre><code>if (thisver == 101) {
    // new code
}
</code></pre>

<p>Done. Right? Well, yes and no. <em>Yes</em>, this code is backward-compatible. I safely wrapped my new code in featured flags. So I can rest assured it will only run when the feature flag is set. In this case, when <code>thisversion</code> equals <code>101</code>. However, <em>no</em> because unit tests failed for old versions of the code.</p>

<p>After some debugging, I found the issue:</p>

<pre><code>if (thisver &gt; VER || thisver &lt; 100) {
    return;
}
</code></pre>

<p>Although I incremented <code>VER</code> for my new version, the old version still had the previous version number. While my code was indeed backward-compatible, old versions always failed this little gem: <code>thisver &gt; VER</code>. The old code was not <em>forward-compatible</em>. This logic prevented me from using an ideal version variable as a feature flag.</p>

<p>I will not speculate on the original developer&#8217;s intention. However, given the code&#8217;s high-profile and the existence of <code>VER</code> the logic above is <em>odd</em> and a good demonstration of code that is not forward-compatible.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Benchmark: Octopress vs. WordPress]]></title>
    <link href="http://jason.pureconcepts.net/2013/01/benchmark-octopress-wordpress/"/>
    <updated>2013-01-28T14:50:00-05:00</updated>
    <id>http://jason.pureconcepts.net/2013/01/benchmark-octopress-wordpress</id>
    <content type="html"><![CDATA[<p>I recently <a href="http://jason.pureconcepts.net/2013/01/migrating-wordpress-octopress/" title="Migrating from WordPress to Octopress">migrated from WordPress to Octopress</a>. During the migration I benchmarked the performance between WordPress and Octopress.</p>

<h2>Server Configuation</h2>

<p>Last summer I <a href="http://jason.pureconcepts.net/2012/07/migrating-wordpress-to-amazon-ec2/" title="Migrating WordPress to EC2">migrated WordPress to Amazon EC2</a>. I decided to stay on EC2 for Octopress for two reasons. First, a <a href="http://aws.amazon.com/ec2/instance-types/" title="EC2 Micro Instance">micro instance</a> is, essentially, free. Second, if the micro instance can serve a WordPress blog, it can serve a static HTML blog.</p>

<p>I made a few optimizations to the Apache configuration. Namely decreased <code>Timeout</code>, <code>KeepAlive</code> enabled, and tweaked connection limits. I also disabled <code>AllowOverride</code>.</p>

<p>For PHP I installed and enabled <a href="http://php.net/manual/en/book.apc.php" title="Alternative PHP Cache">APC</a>.</p>

<p>WordPress used <a href="http://wordpress.org/extend/plugins/apc/" title="APC Object Cache Backend">object-cache</a> and <a href="http://wordpress.org/extend/plugins/hyper-cache/" title="Hyper Cache">Hyper Cache</a>.</p>

<h2>Benchmark Configurations</h2>

<p>I benchmarked the following configurations using the <a href="http://httpd.apache.org/docs/2.2/programs/ab.html" title="Apache benchmarking tool">Apache benchmarking tool</a> (<code>ab</code>):</p>

<ol>
<li>WordPress Page Request</li>
<li>WordPress Post Request</li>
<li>Octopress Page Request</li>
<li>Octopress Post Request</li>
</ol>


<p>Each benchmark made 1000 requests for 50, 100, 150, and 200 concurrent connections using both <code>close</code> and <code>keep-alive</code>. I performed each benchmark 3 times to average the result.</p>

<h2>Benchmark Results</h2>

<p>I created two graphs from the benchmark results:</p>

<ul>
<li>Average request per second</li>
<li>Average time per request (in milliseconds).</li>
</ul>


<h3>Request Per Second</h3>

<figure>
  <img src="http://jason.pureconcepts.net/images/benchmark-request-per-second.png" alt="Graph: Requests Per Second" title="Graph: Requests Per Second" />
  <figcaption>Requests Per Second (<code>Connection: close</code>)</figcaption>
</figure>




<figure>
  <img src="http://jason.pureconcepts.net/images/benchmark-request-per-second-keep-alive.png" alt="Graph: Requests Per Second (keep-alive)" title="Graph: Requests Per Second (keep-alive)" />
  <figcaption>Requests Per Second (<code>Connection: keep-alive</code>)</figcaption>
</figure>


<p>Without surprise, Octopress is faster than WordPress. Roughly 3 times faster (300%). In some cases reaching an impressive 2,000 requests per second for <code>close</code> connections, and nearly 3,000 requests per second for <code>keep-alive</code> connections.</p>

<p>Octopress performed the same as WordPress for page requests with 200 concurrent <code>close</code> connections. However, this implicates the micro instance more than Octopress or WordPress.</p>

<h3>Time Per Request</h3>

<figure>
  <img src="http://jason.pureconcepts.net/images/benchmark-time-per-request.png" alt="Graph: Time Per Request" title="Graph: Time Per Request" />
  <figcaption>Time Per Request (<code>Connection: close</code>)</figcaption>
</figure>




<figure>
  <img src="http://jason.pureconcepts.net/images/benchmark-time-per-request-keep-alive.png" alt="Graph: Time Per Request (keep-alive)" title="Graph: Time Per Request (keep-alive)" />
  <figcaption>Time Per Request (<code>Connection: keep-alive</code>)</figcaption>
</figure>


<p>The time per request results are similar to the requests per second results. Even the page request anomaly appeared. Nevertheless, Octopress is still faster than WordPress.</p>

<p>For most of the benchmarks, Octopress response times were under 100 milliseconds. This not only improves user experience, but search engine optimization as well.</p>

<h3>Sever Stats</h3>

<p>The following are screenshots of memory and CPU usage graphs taken from my <a href="http://newrelic.com" title="New Relic">New Relic</a> dashboard during the benchmarks.</p>

<figure>
  <img src="http://jason.pureconcepts.net/images/wordpress-server-stats.png" alt="Server Stats: WordPress" title="Server Stats: WordPress" />
  <figcaption>Server Stats: WordPress</figcaption>
</figure>


<p>With WordPress, the server spikes well above its physically memory and CPU limits.</p>

<figure>
  <img src="http://jason.pureconcepts.net/images/octopress-server-stats.png" alt="Server Stats: Octopress" title="Server Stats: Octopress" />
  <figcaption>Server Stats: Octopress</figcaption>
</figure>


<p>With Octopress, the server has 60% of its physical memory available and <code>vi</code> shows up in the <em>Top 5</em> processes &mdash; wow.</p>

<h2>Benchmark Conclusion</h2>

<p>It&#8217;s no surprise Octopress is faster than WordPress. Octopress uses static files whereas WordPress uses 10,000 lines of PHP code performing various database queries. While <a href="http://jason.pureconcepts.net/2012/08/21-ways-wordpress-fast/" title="21 ways to make WordPress fast">you can make WordPress faster</a>, it&#8217;s worth nothing that without caching WordPress did not finish any of the benchmarks above. In fact, it crashed my server.</p>

<p>I plan to add another benchmark configuration for <a href="http://wiki.nginx.org/Main">nginx</a> and possibly <a href="https://www.varnish-cache.org/">Varnish</a>. In addition, I&#8217;m monitoring the potential search engine optimizations from this migration. Look for posts on both in the coming months. In the meantime, I welcome your feedback.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Why Apple should buy Spotify]]></title>
    <link href="http://jason.pureconcepts.net/2013/01/why-apple-should-buy-spotify/"/>
    <updated>2013-01-18T11:51:00-05:00</updated>
    <id>http://jason.pureconcepts.net/2013/01/why-apple-should-buy-spotify</id>
    <content type="html"><![CDATA[<p>I&#8217;m not always up-to-date with music. I listen to what I listen to. But as a developer music services interest me.</p>

<p>Years ago, I created <a href="http://jason.pureconcepts.net/2009/11/lastplayed_iphone_app/" title="LastPlayed App">LastPlayed</a> &mdash; an app around sharing your playlist with those around you. A social soundtrack to introduce you to new music. I&#8217;ve since let it die to the rise of giants like Pandora and Spotify.</p>

<p>Spotify spoke at our recent <a href="http://open.blogs.nytimes.com/timesopen-schedule/" title="The New York Times Open Hack Day">TimesOpen Hack Day</a>. I learned more about their service. Things which made me think of Apple, and why Apple should buy Spotify.</p>

<h2>Expanding iTunes</h2>

<p>For years, Apple has tried to expand iTunes with services like Ping (<a href="http://www.pcmag.com/article2/0,2817,2409675,00.asp" title="Apple shuts down iTunes Ping">#Fail</a>) and iTunes Match. Clearly Apple <em>wants</em> to evolve iTunes into a social network.</p>

<p>Buying Spotify would give iTunes the boast it needs. By integrating Spotify with iTunes both sides benefit. Spotify can grow subscribers with the appeal of the larger music collection offered by iTunes. Apple can up-sell music downloads.</p>

<h2>Expanding the App Store</h2>

<p>Spotify has its own <a href="https://developer.spotify.com/technologies/apps/" title="Spotify Apps">app ecosystem</a>. But as far as I can tell, all these apps are free. While a great a value add for Spotify subscribers, they&#8217;re missing an opportunity for monetization.</p>

<p>If Apple buys Spotify, Apple can package the Spotify API with in the next iOS SDK release. Opening the door to a larger developer base to develop both free and paid apps. I know I&#8217;d be very interested in developing such apps.</p>

<h2>The time to buy is now</h2>

<p>Apple <a href="http://techcrunch.com/2012/10/25/apple-now-has-121-3-billion-in-cash-more-than-amazons-market-cap-or-a-space-station/">has the cash</a>. I have to believe the revenue generated by expanding iTunes and the App Store alone would show a return on investment. Apple should buy Spotify &mdash; before Facebook does.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Migrating from WordPress to Octopress]]></title>
    <link href="http://jason.pureconcepts.net/2013/01/migrating-wordpress-octopress/"/>
    <updated>2013-01-14T15:21:00-05:00</updated>
    <id>http://jason.pureconcepts.net/2013/01/migrating-wordpress-octopress</id>
    <content type="html"><![CDATA[<p>This past weekend I migrated my blog from WordPress to Octopress. Before I explain the migration, let me explain why I migrated away from WordPress.</p>

<p>First, I am a fan of WordPress. I&#8217;ve written many <a href="http://www.google.com/search?q=site%3Ajason.pureconcepts.net&amp;q=wordpress" title="Read my WordPress posts">posts on WordPress</a>, <a href="http://www.google.com/search?q=site%3Ajason.pureconcepts.net&amp;q=wordcamp" title="My talks at WordCamps">spoken at WordCamps</a>, and will continue to develop with WordPress. But <a href="http://jason.pureconcepts.net/2012/08/21-ways-wordpress-fast/" title="21 Ways to Make WordPress Fast">WordPress is slow</a>. And I had a need&hellip; a need for speed. Greasy, fast speed.</p>

<p>Enter <a href="http://octopress.org" title="Octopress">Octopress</a>:</p>

<blockquote><p>Octopress is a framework designed for <a href="http://github.com/mojombo/jekyll" title="Jekyll">Jekyll</a> - the blog aware static site generator powering Github Pages.</p></blockquote>

<p><strong>Github</strong> uses it &mdash; that&#8217;s reassuring. <strong>Static site</strong> &mdash; you don&#8217;t get much faster than serving a static resource. Look for a follow-up post with the performance showdown between Octopress and WordPress soon.</p>

<p>I also wanted something simple. I don&#8217;t use all the features of WordPress. I just write posts from time to time. From <a href="http://jason.pureconcepts.net/2008/09/hello_world/" title="My first blog">the beginning</a> I&#8217;ve drafted my posts in Markdown. Jekyll uses <a href="http://daringfireball.net/projects/markdown/" title="Markdown">Markdown</a> in its templates. <em>Simple</em>.</p>

<p>You may be wondering the difference between Jekyll and Octopress. Jekyll is tool, Octopress is the packaging. Octopress nicely wraps some of the rough edges of Jekyll making it easier to manage. It also offers <a href="https://github.com/imathis/octopress/wiki/3rd-Party-Octopress-Themes" title="Octopress Themes">themes</a> and <a href="https://github.com/imathis/octopress/wiki/3rd-party-plugins" title="Octopress Plugins">plugins</a>.</p>

<p>Now if, like me, you&#8217;re sold on Octopress read on. If not, thanks for reading this far. Long live WordPress!</p>

<h2>Migrating from Octopress to WordPress</h2>

<p>Here is an outline of the steps for migrating from WordPress to Octopress with more details below.</p>

<ol>
<li>Installed Octopress</li>
<li>Migrated Content from WordPress</li>
<li>Previewed Site</li>
<li>Deploy Octopress</li>
</ol>


<h3>Installing OctoPress</h3>

<p>For the most part, I followed the <a href="http://octopress.org/docs/setup/" title="Octopress Setup">Octopress Setup</a>. The only exception being Ruby. I&#8217;m on Mac OS X Mountain Lion. So my Ruby version was 1.8.7. I updated Ruby with RVM.</p>

<pre><code>curl -L https://get.rvm.io | bash -s stable --ruby
</code></pre>

<h3>Migrating Content from WordPress to Octopress/Jekyll</h3>

<p>There were <a href="https://github.com/mojombo/jekyll/wiki/blog-migrations" title="Migrating from WordPress to Jekyll">several migration options</a>. I tried a few of them and found <a href="https://github.com/benbalter/wordpress-to-jekyll-exporter" title="Export to Jekyll">Export to Jekyll</a> best as it ran content through the approriate WordPress filters. While Export to Jekyll was the best of the bunch, it wasn&#8217;t perfect.</p>

<ul>
<li><strong>Encoding issues.</strong> After moving the files from Export to Jekyll <code>rake generate</code> erred about <code>gsub</code>. The issue was <a href="https://github.com/imathis/octopress/issues/148">UTF-8</a>. With some debugging, I found several UTF-8 characters in my posts. Mostly smart quotes and other artifacts like EM dashes from Mac OS X. Unfortunately I didn&#8217;t find a <a href="http://pradeepnayak.in/technology/2012/02/16/jekyll-character-encoding-problems/">quick fix</a>. I ended up replacing these with HTML entities using some <code>sed</code> commands. This was the worst part of the migration. And it wasn&#8217;t that bad.</li>
<li><strong>Missing meta data.</strong> Aside from the title, none of the WordPress SEO settings were exported. I wrote a PHP script to add the <code>description</code> and <code>keywords</code> to the Front Matter. I will likely fork Export to Jekyll soon. If you&#8217;re interested in these, please leave a comment.</li>
<li><strong>Misconfigured comments.</strong> The export did not set <code>comment</code> in the Front Matter. I fixed this with a quick <code>sed</code> command as all my posts allow comments. However, this is something Export to Jekyll <em>could</em> have done.</li>
<li><strong>Exporting comments.</strong> I migrated my <a href="http://help.disqus.com/customer/portal/articles/466255-exporting-comments-from-wordpress-to-disqus" title="Export WordPress comments to Disqus">WordPress comments to Disqus</a>. Suprisingly simple. But Disqus took several hours to process the import (130 comments).</li>
<li><strong>Static resources</strong>. I needed to download the static resources in my content (images, PDFs, etc). This is not necessary if you use a static domain. But if you use WordPress <strong>uploads/</strong>, you&#8217;ll need to download them to Octopress <strong>source/</strong>. I wrote a <code>curl</code> script to do so.</li>
</ul>


<h3>Deploying Octopress</h3>

<p>Octopress has a few <a href="http://octopress.org/docs/deploying/" title="Deploying Octopress">automated deployment options</a>. I used <code>rsync</code>. However, my blog runs on Amazon EC2. So I needed to <a href="https://github.com/mneorr/octopress/commit/7c9c4bad48d921e94a57c63167f88c95f10dd687" title="Set Octopress ssh-key">configure my EC2 private key to deploy Octopress</a>. After doing so, I deployed to Octopress to my Amazon EC2 instance by simply typing <code>rake deploy</code>.</p>

<h2>Blogging with Octopress</h2>

<p>Octopress is not without its own challenges. I found limited SEO out-of-the-box and I will need to learn the nuiances of Octopress themes. Look for future posts on both.</p>

<p>Nonetheless, with Octopress I can write like I always have. I don&#8217;t have to manage WordPress upgrades or plugins. I don&#8217;t have to make WordPress faster. I just write. This frees up my time for other things.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[A Response to &#8220;Micro-Optimizations in PHP&#8221;]]></title>
    <link href="http://jason.pureconcepts.net/2012/12/php-micro-optimizations/"/>
    <updated>2012-12-14T00:00:00-05:00</updated>
    <id>http://jason.pureconcepts.net/2012/12/php-micro-optimizations</id>
    <content type="html"><![CDATA[<p>Last week I read a post recommended in <a href="http://phpweekly.info">PHP Weekly</a> entitled – <a href="http://www.developerknowhow.com/micro-optimizing-in-php/">Micro-Optimizing in PHP</a>. Always striving to <a href="http://jason.pureconcepts.net/2012/08/better-php-developer/">be a better PHP developer</a>, I read this first. The post opens with common recommendations. Most I consider <em>micro</em> micro optimizations. As I continued reading some were not optimizations at all. In the end, the post was written without care – making absolute statements without support.</p>

<p>On a personal note, it bothers me to find such poor quality posts in a PHP newsletter. Posts like this confuse developers and in turn contribute to the poor code notorious in the PHP community. Adding fuel to the fire of the anti-PHP community for <a href="http://webonastick.com/php.html">why PHP sucks</a>.</p>

<p>I have no doubt the author had good intention. But at the least, he should have provided supporting evidence. After all, a good developer asks <em>Why</em>? I reviewed the recommended <em>optimizations</em> in the original post. Evaluating recommendations to be <em>absolute truths</em> and marking each <em>true</em> or <em>false</em>. Please read the full section before you segfault.</p>

<h2><code>foreach</code> vs. <code>for</code></h2>

<p><strong>False.</strong></p>

<p><code>foreach</code> is faster when looping over an array for <em>reading</em>. If you need to <em>write</em> to the array the performance of <code>foreach</code> degrades significantly. So <code>for</code> has its place.</p>

<p>Another case for using <code>for</code> is when the block contains counting logic.</p>

<p>Consider:</p>

<pre><code>for ($i = 0; …; ++$i) {
    // block
}
</code></pre>

<p>Versus the <code>foreach</code> equivalent:</p>

<pre><code>$i = 0;
foreach (…) {
    // block
    ++$i;
}
</code></pre>

<p><em>Exception:</em> When looping over a sequential numerically indexed array, the array key could serve as a counter.</p>

<h3><code>for</code> Truth</h3>

<p>Two absolute truths when using a <code>for</code> loop.</p>

<ol>
<li><strong>Pre-calculate parts of the condition expression.</strong> The condition within <code>for</code> evaluations the condition on each iteration. Avoiding the overhead function calls which return value will not change during the loop will optimize your code.</li>
<li><strong>Use pre-increment.</strong> <a href="http://stackoverflow.com/a/9205011/164998">By nature</a>, pre-increment is a faster expression.</li>
</ol>


<p>Code:</p>

<pre><code>$count = count($arr);
for ($i = 0; $i &lt; $count; ++$i) {
    // block
}
</code></pre>

<h2>Double vs. Single Quotes</h2>

<p><strong>False.</strong></p>

<p>Back in 2007 I emailed Ilia Alshanetsky about this very matter. He called it an <a href="http://www.ilia.ws/files/zend_performance.pdf">Optimization Myth</a>. However, that was PHP 4. Somewhere in PHP 5 double quotes were optimized (I <em>heard</em> PHP 5.1).</p>

<p>Double quotes performing better than single quotes is counter intuitive. Without the need for variable expansion, it stands to reason single quotes would be faster. Furthermore literal values (single quote) could be optimized in <em>memory</em>.</p>

<p>I&rsquo;ve benchmarked double quotes versus single quotes several times without finding anything conclusive. Maybe double quotes are indeed faster. But to <em>replace all single quotes with double quotes</em> as the original post suggests is not worth the time. In the end, following your <a href="http://jason.pureconcepts.net/2012/09/code-style-fashion/" title="Code: Style vs. Fashion">code style</a> is more important.</p>

<h2><code>UNION</code> vs. <code>OR</code></h2>

<p><strong>False.</strong></p>

<p>I am currently reading <a href="http://shop.oreilly.com/product/0636920022343.do">High Performance MySQL</a>. In fact, I just finished the chapter on query optimization. This recommendation actually put me on the path to writing this response post. Stating change all `OR` to `UNION` is just plain reckless.</p>

<p>First, the original example is bad. It suggests changing:</p>

<pre><code>select username from users where company = ‘bbc&amp;rsquo; or company = ‘itv&amp;rsquo;;
</code></pre>

<p>to:</p>

<pre><code>select username from users where company = ‘bbd&amp;rsquo;
union
select username from users where company = ‘itv&amp;rsquo;;
</code></pre>

<p>When using the same column, the opposite of what the author suggests is more performant. That is you should change from a <code>UNION</code> to an <code>OR</code> when the <code>WHERE</code> clause operates on the same column.</p>

<p>Second, changing <code>OR</code> to <code>UNION</code> in your queries may not return the same result. While <code>UNION</code> may be an optimization, you need to understand when to use it. <strong>Do not</strong> sweepingly replace <code>OR</code> with <code>UNION</code> in you codebase.</p>

<p>As I am admittedly still learning MySQL Optimizations, I posted the topic to the StackOverflow community. I encourage you to <a href="http://stackoverflow.com/questions/13750475/sql-performance-union-vs-or">read the answers</a> for more details on why <code>UNION</code> vs <code>OR</code> is not <strong>always</strong> an optimization.</p>

<h2>Additional PHP Optimizations</h2>

<p>The original post did contain a few true optimizations.</p>

<ul>
<li><strong>Use <code>echo</code> versus <code>print</code>.</strong> <a href="http://stackoverflow.com/questions/7094118/reference-comparing-phps-print-and-echo">True</a>.</li>
<li><strong>Use string functions over regular expressions.</strong> True, with the exception of complex pattern matching. The equivalent regular expressions code written using string functions will be more performant. This <a href="http://php.net/manual/en/function.preg-match.php">is noted</a> in the PHP documentation for the regular expression functions.</li>
</ul>


<h2>The Performance 80/20 Rule</h2>

<p>Performance follows the <a href="http://www.entrepreneurs-journey.com/397/80-20-rule-pareto-principle/">80/20 Rule</a>. If <em>single quotes vs double quotes</em> accounts for 80% – you&rsquo;re optimized. Congratulations. You can go home. That is an absolute truth.</p>

<h2>Remember</h2>

<p>There is no silver bullet. Be skeptic of absolute statements. There are many moving parts in a system. What works for someone else may not work for you. When it doubt, <a href="http://stackoverflow.com/questions/8291366/how-to-benchmark-efficiency-of-php-script">benchmark it yourself</a>.</p>

<h2>References</h2>

<p>If you are interested in PHP performance and optimizations, check out the following resources:</p>

<ul>
<li><a href="http://www.phpbench.com">The PHP Benchmark</a></li>
<li><a href="http://phpperf.com">PHP Performance Metrics</a></li>
</ul>


<p>Also, consult the <a href="http://php.net/docs.php">PHP Documentation</a>. The function definitions and user comments contain valuable information.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Why [certain language] developers are better developers.]]></title>
    <link href="http://jason.pureconcepts.net/2012/12/better-developers/"/>
    <updated>2012-12-05T00:00:00-05:00</updated>
    <id>http://jason.pureconcepts.net/2012/12/better-developers</id>
    <content type="html"><![CDATA[<p>During a lunch discussion on programming languages a co-worker made the notorious argument:</p>

<blockquote><p>&ldquo;[certain language] developers are better developers.&rdquo;</p></blockquote>

<p>I generalized the argument because I&rsquo;ve heard it before. We all have. Fill in the blank with any <a href="http://jason.pureconcepts.net/2012/09/code-style-fashion/">fashionable language</a> – Scala, Ruby, Go, Python…</p>

<p>This argument quickly degrades into a language debate. One filled with feature comparison and syntactical analysis to demonstrate superiority. Why? Well, let&rsquo;s face it – developers can be elitist when it comes to <em>their</em> language.</p>

<p>I also generalized to keep the focus off <em>[certain language]</em> and focus on the <em>developer</em>. I want to evaluate this argument objectively. And if I said, <em>&ldquo;PHP developers are better developers&rdquo;</em> you would have dumped core. Which proves the point.</p>

<p>From this argument, I propose the following, implied premises:</p>

<ul>
<li><em>[certain language]</em> is a fashionable language.</li>
<li>The developer learned <em>[certain language]</em>.</li>
</ul>


<p>Applying the <a href="http://en.wikipedia.org/wiki/Deductive_reasoning#Law_of_Syllogism">Law of Syllogism</a>:</p>

<blockquote><p>Developers that learn fashionable languages are better developers.</p></blockquote>

<p>This becomes a much more acceptable argument.</p>

<p>As recommended in <a href="http://pragprog.com/the-pragmatic-programmer"><em>The Pragmatic Programmer</em></a>, you should learn a new programming language every year. This being a <a href="http://jason.pureconcepts.net/2009/12/good_developer_routines/">routine of a good developer</a>. One I personally follow. The purpose is to learn something new from each language. In turn making you a better developer.</p>

<p>So next time you hear, <em>&ldquo;[certain language] developers are </em>better developers&rdquo;*, consider the developer. It might just be valid.</p></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Tough Mudder Kentucky]]></title>
    <link href="http://jason.pureconcepts.net/2012/11/tough-mudder-kentucky/"/>
    <updated>2012-11-06T00:00:00-05:00</updated>
    <id>http://jason.pureconcepts.net/2012/11/tough-mudder-kentucky</id>
    <content type="html"><![CDATA[<p>Last year four of us braved <a href="http://jason.pureconcepts.net/2011/12/tough-mudder-indiana/">Tough Mudder Indiana</a>. For those of you not familiar Tough Mudder, watch this <a href="http://www.youtube.com/watch?v=ObcX5ZopSZE">promotional video before</a> continuing. Tough Mudder Indiana was an incredible experience and immediately after we vowed to do another Mudder. So when Tough Mudder announced an event in our home state of Kentucky, we registered.</p>

<p>This year we named our team the <em>Kentucky Irregulars</em> from the movie <a href="http://www.imdb.com/title/tt0253556/">Reign of Fire</a>. Each of us adopted a theme from the movie. My brother wore a Hard Rock <em>London</em> shirt. Joel grew his dense beard to resemble <a href="http://www.imdb.com/character/ch0011439/">Quinn</a>. As the most extreme, I honored <a href="http://www.imdb.com/character/ch0011441/">Van Zan</a> by buzzing my head, growing a rugged beard, and replicating his bomber jacket vest.</p>

<figure>
  <img title="Tough Mudder - Kentucky Irregulars" src="http://jason.pureconcepts.net/images/tough-mudder-kentucky-irregulars.jpg" alt="Tough Mudder - Kentucky Irregulars" />
  <figcaption>Kentucky Irregulars – Joel Jacob, Jason McCreary, Jeff Krawiec (from left to right)</figcaption>
</figure>


<p>Similar to last year, the weather was overcast, windy, and in the 40s. We had an 8:00am start time. So limited sleep added to the challenge. But we prefer the early start for a fresh course. Free from obstacle lines and everything covered in mud.</p>

<p>Now the Tough Mudder is challenging all around. Beyond the obstacles. You&rsquo;re running on uneven ground over rock, sand, mud, or tall grass. You&rsquo;re constantly wet and often covered in mud. So you&rsquo;re constantly carrying a few extra pounds. The weather, hot or cold, also drains your energy.</p>

<h2>Most Dreaded Tough Mudder Obstacle</h2>

<p><strong>Arctic Enema</strong>.</p>

<p>Previously named Chernobyl Jacuzzi. This obstacle is a 30ft long pool of 5ft deep ice water. Literal ice water. You climb up one side and jump in. Instant shock. You struggle to breathe. A barrier divides the pool forcing you under the ice. You climb out the other side. The water, so cold, shrinks your clothes.</p>

<h2>Most Fun Tough Mudder Obstacle</h2>

<p><strong>Everest</strong>.</p>

<p>Everest is a 12ft quarter pipe. You get a running start and leap for the rim. Typically mud covers the approach and ramp, adding to the challenge. This obstacle requires a helping hand from your fellow Mudder. And it&rsquo;s that camaraderie which makes this obstacle fun. Headbands off to the Tough Mudders who tackle Everest solo.</p>

<h2>Toughest Tough Mudder Obstacle</h2>

<p><strong>Berlin Walls</strong>.</p>

<p>The Berlin Walls are a set of wooded barriers ranging from 6-12ft high. Typically each course contains a few sets. The first few are easy. But when you get to the series of 10-12ft walls, the fun stops. By that point in the course, it takes everything you have and a fellow Mudder, to get over these walls.</p>

<h2>Signature Tough Mudder Obstacle</h2>

<p><strong>Electroshock Therapy</strong>.</p>

<p>This is the signature obstacle of Tough Mudder. A 10-yard muddy gauntlet of dangling 10,000 volt hot wires. The finish line waits on the other side. My goal is always simple – don&rsquo;t fall.</p>

<h2>A Tough Mudder</h2>

<p>While everyone loves the pictures, people always ask <em>why</em>. <em>Why would you do that? It looks miserable.</em> My brother tells me, &ldquo;They wouldn&rsquo;t understand&rdquo;. I agree it is difficult to explain. Ultimately, you&rsquo;re not going to understand Tough Mudder until you do Tough Mudder. I consider Tough Mudder <em>hard fun</em>. I respect the challenge.</p>

<p>There are signs placed along the Tough Mudder course. I noticed one this time to this very point. It read:</p>

<blockquote><p>Be patient and tough. One day this pain will be useful to you.</p></blockquote>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Be a Better PHP Developer: Coding Standards]]></title>
    <link href="http://jason.pureconcepts.net/2012/11/php-coding-standards/"/>
    <updated>2012-11-02T00:00:00-04:00</updated>
    <id>http://jason.pureconcepts.net/2012/11/php-coding-standards</id>
    <content type="html"><![CDATA[<p>In the last article of <a href="http://www.google.com/search?q=site%3Ajason.pureconcepts.net&amp;q=%22Be+a+Better+PHP+Developer%22" title="How to be a Better PHP Developer">this series</a> we cover the basics of how to <a href="http://jason.pureconcepts.net/2012/08/better-php-developer/">be a better PHP developer</a>. Now I want to cover coding standards.</p>

<p>Coding standards vary greatly among developers. Even when writing the same code. And therein lies the problem. This becomes most evident when reviewing code that is not your own.</p>

<p>My own coding standards have changed over the years. As team lead, I drafted coding standards documents. This time, I wanted something active and easily adopted.</p>

<h2>PHP coding standards</h2>

<p>The <a href="http://pear.php.net/manual/en/standards.php" title="PEAR Coding Standard">PEAR coding standard</a> is arguably the most prevalent among the PHP community. However, it is exhaustive and therefore not easily adopted. When reading about <a href="https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md">PHP namespacing</a> last year, I came across the PHP Standard Requirements (PSR).</p>

<p>The latest version of this standard is <a href="https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md">PSR-2</a>, which expands <a href="https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-1-basic-coding-standard.md">PSR-1</a>, is a straightforward document outlining basic coding standards. It leaves some flexibility for <a href="http://jason.pureconcepts.net/2012/09/code-style-fashion/">developer style</a>. And while I may not agree with every standard – mainly the curly brace conventions – it passes the governance.</p>

<h2>Stick to the coding standards</h2>

<p>It is human nature to bend the rules. But there&rsquo;s no point in adopting a standard only to break it. I wanted to follow PSR-2 strictly. Not just the parts I liked. So I needed something to keep me honest.</p>

<p>A while back I came across PHP CodeSniffer. I intended to use it for automated code validation with an svn post-hook. PHP CodeSniffer features pluggable coding standards you can validate against. In addition, one for PSR-2 exist.</p>

<p>You can download PHP CodeSniffer. If you have <a href="http://jason.pureconcepts.net/2012/10/install-pear-pecl-mac-os-x/" title="Install PEAR on Mac OS X">PEAR installed</a>, it&rsquo;s easier:</p>

<pre><code>pear install PHP_CodeSniffer
</code></pre>

<p>Verify PHP CodeSniffer with:</p>

<pre><code>phpcs --version
</code></pre>

<p><strong>Note:</strong> If you receive <em>warnings</em>, your PHP <code>include_path</code> likely does not include the PEAR directory. <a href="https://pear.php.net/manual/en/installation.checking.php">Check your PEAR installation</a> to resolve this issue.</p>

<p>You can run PHP CodeSniffer against an entire directory.</p>

<pre><code>phpcs --standard=PSR2 api/
</code></pre>

<h2>Format legacy code</h2>

<p>Since I just adopted the PSR-2 coding standard, I had several violations in my current projects. However, as traditional lazy developer, I didn&rsquo;t want to edit hundreds of lines of code.</p>

<p>I found <a href="https://github.com/fabpot/PHP-CS-Fixer">PHP CS Fixer</a>. It auto-formats code to meet PSR-2 (among others). While it doesn&rsquo;t correct everything, it fixes the tedious ones.</p>

<pre><code>php-cs-fixer fix api/ --level=psr2 --dry-run
</code></pre>

<p><strong>Note:</strong> I added <code>--dry-run</code> for demonstration purposes. Remove it to update your files.</p>

<h2>Go forth and be a better PHP developer</h2>

<p>A good developer should follow a coding standard. While I am advocating PSR-2 here, it is really up to you. What matters is that you follow it strictly. Hopefully the tools above can help you do so.</p>

<p><em>This post is part of a series on <a href="http://www.google.com/search?q=site%3Ajason.pureconcepts.net&amp;q=%22Be+a+Better+PHP+Developer%22" title="How to be a Better PHP Developer">How to be a Better PHP Developer</a>.</em></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Install PEAR and PECL on Mac OS X]]></title>
    <link href="http://jason.pureconcepts.net/2012/10/install-pear-pecl-mac-os-x/"/>
    <updated>2012-10-16T00:00:00-04:00</updated>
    <id>http://jason.pureconcepts.net/2012/10/install-pear-pecl-mac-os-x</id>
    <content type="html"><![CDATA[<p>The following instructions install <a href="http://pear.php.net" title="PEAR">PEAR</a> and <a href="http://pecl.php.net" title="PECL">PECL</a> on Mac OS X under <strong>/usr/local/</strong>. PECL is bundled with PEAR. So this is as simple as installing PEAR on Mac OS X.</p>

<p>PEAR is PHP&rsquo;s <em>Package</em> Repository and makes it easy to download and install PHP tools like <a href="https://github.com/sebastianbergmann/phpunit">PHPUnit</a> and <a href="http://xdebug.org">XDebug</a>. I specifically recommend these two for every PHP developer.</p>

<h2>Download PEAR</h2>

<pre><code>curl -O http://pear.php.net/go-pear.phar
sudo php -d detect_unicode=0 go-pear.phar
</code></pre>

<h2>Configure and Install PEAR</h2>

<p>You should now be at a prompt to configure PEAR.</p>

<ol>
<li>Type <kbd>1</kbd> and press <kbd>return</kbd>.</li>
<li><p>Enter:</p>

<pre><code>/usr/local/pear
</code></pre></li>
<li><p>Type <kbd>4</kbd> and press <kbd>return</kbd>.</p></li>
<li><p>Enter:</p>

<pre><code>/usr/local/bin
</code></pre></li>
<li><p>Press <kbd>return</kbd></p></li>
</ol>


<h2>Verify PEAR</h2>

<p>You should be able to type:</p>

<pre><code>pear version
</code></pre>

<p>Eventually, if you use any extensions or applications from PEAR, you may need to update <a href="http://pear.php.net/manual/en/installation.checking.php">PHP&rsquo;s include path</a>.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Speaking at WordCamp Louisville 2012]]></title>
    <link href="http://jason.pureconcepts.net/2012/10/speaking-wordcamp-louisville-2012/"/>
    <updated>2012-10-10T00:00:00-04:00</updated>
    <id>http://jason.pureconcepts.net/2012/10/speaking-wordcamp-louisville-2012</id>
    <content type="html"><![CDATA[<p>I&rsquo;ll be speaking at <a href="http://2012.louisville.wordcamp.org/" title="WordCamp Louisville 2012">WordCamp Louisville 2012</a> this weekend. This will be my fifth time speaking at WordCamp and second time giving this talk – <a href="http://jason.pureconcepts.net/2012/08/21-ways-wordpress-fast/" title="21 Ways to Make WordPress Fast">21 Ways to Make WordPress Fast</a>. With some new material of course.</p>

<p>In addition, I will be co-speaking with <a href="http://www.intellispire.com/blog/" title="Nick Temple's Blog">Nick Temple</a> about <em>WordPress Deployment</em>. This talk includes open-discussion of the following:</p>

<h2>Hosting WordPress</h2>

<ul>
<li>Shared Hosting</li>
<li>Tailored WordPress Hosting</li>
<li>Cloud Hosting</li>
</ul>


<h2>Deploying WordPress</h2>

<ul>
<li><a href="http://viastudio.com/2011/02/08/configuring-wordpress-multiple-environments/" title="Configuring for WordPress in Multiple Environments">Configuring for WordPress in Multiple Environments</a></li>
<li><a href="http://markjaquith.wordpress.com/2012/05/26/wordpress-skeleton/" title="WordPress Skeleton">WordPress Skeleton</a></li>
<li><a href="http://www.knewton.com/tech/blog/2012/07/announcing-wp-stack/" title="WP Stack">WP Stack</a></li>
<li><a href="http://jason.pureconcepts.net/2012/08/wordpress-multitenancy/" title="WordPress Multitenancy">WordPress Multitenancy</a></li>
</ul>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Installing Apache, PHP, and MySQL on Mac OS X]]></title>
    <link href="http://jason.pureconcepts.net/2012/10/install-apache-php-mysql-mac-os-x/"/>
    <updated>2012-10-09T00:00:00-04:00</updated>
    <id>http://jason.pureconcepts.net/2012/10/install-apache-php-mysql-mac-os-x</id>
    <content type="html"><![CDATA[<p>I have installed Apache, PHP, and MySQL on Mac OS X since Leopard. Each time doing so by hand. Each version of Mac OS X having some minor difference. This post serves as much for my own record as to outline how to install Apache, MySQL, and PHP for a local development environment on Mac OS X Mountain Lion.</p>

<p>I am aware of the several packages available, notably <a href="http://www.mamp.info/en/index.html" title="MAMP">MAMP</a>. These packages help get you started quickly. But they forego the learning experience and, as most developers report, eventually break. Personally, the choice to do it myself has proven invaluable.</p>

<p>It is important to remember Mac OS X runs atop UNIX. So all of these technologies install easily on Mac OS X. Furthermore, Apache and PHP are included by default. In the end, you only <em>install</em> MySQL then simply turn everything on.</p>

<p>First, open <em>Terminal</em> and switch to <code>root</code> to avoid permission issues while running these commands.</p>

<pre><code>sudo su -
</code></pre>

<h2>Enable Apache on Mac OS X</h2>

<pre><code>apachectl start
</code></pre>

<p><strong>Note</strong>: Prior to Mountain Lion this was an option for <em>Web Sharing</em> in <em>System Prefrences → Sharing</em>.</p>

<p>Verify <em>It works!</em> by accessing <a href="http://localhost">http://localhost</a></p>

<h2>Enable PHP for Apache</h2>

<p>First, make a backup of the default Apache configuration. This is good practice and serves as a comparison against future versions of Mac OS X.</p>

<pre><code>cd /etc/apache2/
cp httpd.conf httpd.conf.bak
</code></pre>

<p>Now edit the Apache configuration. Feel free to use <em>TextEdit</em> if you are not familiar with <em>vi</em>.</p>

<pre><code>vi httpd.conf
</code></pre>

<p>Uncomment the following line (remove <code>#</code>):</p>

<pre><code>LoadModule php5_module libexec/apache2/libphp5.so
</code></pre>

<p>Restart Apache:</p>

<pre><code>apachectl restart
</code></pre>

<h2>Install MySQL</h2>

<ol>
<li><a href="http://dev.mysql.com/downloads/mysql/">Download</a> the MySQL DMG for Mac OS X</li>
<li>Install <em>MySQL</em></li>
<li>Install <em>Preference Pane</em></li>
<li>Open <em>System Preferences → MySQL</em></li>
<li>Ensure the MySQL Server is running</li>
<li>Optionally, you can enable MySQL to start automatically. I do.</li>
</ol>


<p>The <strong>README</strong> also suggests creating aliases for <code>mysql</code> and <code>mysqladmin</code>. However there are other commands that are helpful such as <code>mysqldump</code>. Instead, I <a href="http://superuser.com/questions/69130/where-does-path-get-set-in-os-x-10-6-snow-leopard">updated my path</a> to include <code>/usr/local/mysql/bin</code>.</p>

<pre><code>export PATH=/usr/local/mysql/bin:$PATH
</code></pre>

<p><strong>Note</strong>: You will need to open a new <em>Terminal</em> window or run the command above for your path to update.</p>

<p>I also run <code>mysql_secure_install</code>. While this isn&rsquo;t necessary, it&rsquo;s good practice.</p>

<h3>Connect PHP and MySQL</h3>

<p>You need to ensure PHP and MySQL can communicate with one another. There are <a href="http://stackoverflow.com/questions/4219970/warning-mysql-connect-2002-no-such-file-or-directory-trying-to-connect-vi">several options</a> to do so. I do the following:</p>

<pre><code>cd /var 
mkdir mysql
cd mysql
ln -s /tmp/mysql.sock mysql.sock
</code></pre>

<h2>Creating <em>VirtualHosts</em></h2>

<p>You could stop here. PHP, MySQL, and Apache are all running. However, all of your sites would have URLs like <a href="http://localhost/somesite/">http://localhost/somesite/</a> pointing to <strong>/Library/WebServer/Documents/somesite</strong>. Not ideal for a local development environment.</p>

<p>To run sites individually you need to enable <em>VirtualHosts</em>. To do so, we&#8217;ll edit the Apache Configuration again.</p>

<pre><code>vi /etc/apache2/httpd.conf
</code></pre>

<p>Uncomment the following line:</p>

<pre><code>Include /private/etc/apache2/extra/httpd-vhosts.conf
</code></pre>

<p>Now Apache will load <strong>httpd-vhosts.conf</strong>. Let&rsquo;s edit this file.</p>

<pre><code>vi /etc/apache2/extra/httpd-vhosts.conf
</code></pre>

<p>Here is an example of <em>VirtualHosts</em> I&rsquo;ve created.</p>

<pre><code>&lt;VirtualHost *:80&gt;
    DocumentRoot "/Library/WebServer/Documents"
&lt;/VirtualHost&gt;

&lt;VirtualHost *:80&gt;
        DocumentRoot "/Users/Jason/Documents/workspace/dev"
        ServerName jason.local
        ErrorLog "/private/var/log/apache2/jason.local-error_log"
        CustomLog "/private/var/log/apache2/jason.local-access_log" common

        &lt;Directory "/Users/Jason/Documents/workspace/dev"&gt;
                AllowOverride All
                Order allow,deny
                Allow from all
        &lt;/Directory&gt;
&lt;/VirtualHost&gt;
</code></pre>

<p>The first <code>VirtualHost</code> points to <code>/Library/WebServer/Documents</code>. The first <code>VirtualHost</code> is important as it behaves like the default Apache configuration and used when no others match.</p>

<p>The second <code>VirtualHost</code> points to my <em>dev</em> workspace and I can access it directly from <em>http://jason.local</em>. For ease of development, I also configured some custom logs.</p>

<p><strong>Note</strong>: I use the extension <em>local</em>. This avoids conflicts with any <em>real</em> extensions and serves as a reminder I&rsquo;m in my <em>local</em> environment.</p>

<p>Restart Apache:</p>

<pre><code>apachectl restart
</code></pre>

<p>In order to access <a href="http://jason.local">http://jason.local</a>, you need to edit your <strong>hosts</strong> file.</p>

<pre><code>vi /etc/hosts
</code></pre>

<p>Add the following line to the bottom:</p>

<pre><code>127.0.0.1       jason.local
</code></pre>

<p>I run the following to clear the local DNS cache:</p>

<pre><code>dscacheutil -flushcache
</code></pre>

<p>Now you can access <a href="http://jason.local">http://jason.local</a>.</p>

<p><strong>Note:</strong> You will need to create a new <code>VirtualHost</code> and edit your <strong>hosts</strong> file each time you make a new local site.</p>

<h3>A note about permissions</h3>

<p>You may receive <em>403 Forbidden</em> when you visit your local site. This is likely a permissions issue. Simply put, the Apache user (<code>_www</code>) needs to have access to read, and sometimes write, your web directory.</p>

<p>If you are not familiar with permissions, <a href="http://www.library.yale.edu/wsg/docs/permissions/">read more</a>. For now though, the easiest thing to do is ensure your web directory has permissions of <code>755</code>. You can change permissions with the command:</p>

<pre><code>chmod 755 some_directory/
</code></pre>

<p>In my case, all my files were under my local <code>~/Documents</code> directory. Which by default is only readable by me. So I had to change permissions for my web directory all the way up to <code>~/Documents</code> to resolve the <em>403 Forbidden</em> issue.</p>

<p><strong>Note</strong>: There are many ways to solve permission issues. I have provided this as the <em>easiest</em> solution, not the <em>best</em>.</p>

<h2>Install PHPMyAdmin</h2>

<p>Unless you want to administer MySQL from the command line, I recommend installing <a href="http://www.phpmyadmin.net/" title="PHPMyAdmin">PHPMyAdmin</a>. I won&rsquo;t go into the details. Read the installation guide for more information. I install utility applications in the default directory. That way I can access them under, in this case, <a href="http://localhost/phpmyadmin">http://localhost/phpmyadmin</a>.</p>

<pre><code>cd /Library/WebServer/Documents/
tar -xvf ~/Downloads/phpMyAdmin-3.5.2.2-english.tar.gz
mv phpMyAdmin-3.5.2.2-english/ phpmyadmin
cd phpmyadmin
mv config.sample.inc.php config.inc.php
</code></pre>

<h2>Closing</h2>

<p>A local development environment is a mandatory part of the <a href="http://en.wikipedia.org/wiki/Software_development_process">Software Development Process</a>. Given the ease at which you can install Apache, PHP, and MySQL on Mac OS X there really no excuse.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Updating SVN for Mac OS X]]></title>
    <link href="http://jason.pureconcepts.net/2012/10/updating-svn-mac-os-x/"/>
    <updated>2012-10-04T00:00:00-04:00</updated>
    <id>http://jason.pureconcepts.net/2012/10/updating-svn-mac-os-x</id>
    <content type="html"><![CDATA[<p>I downloaded the latest version of <a href="http://subversion.apache.org/download/">Eclipse</a> and <a href="http://subclipse.tigris.org">Subclipse</a> for my new work Macbook Pro. When I ran <code>svn</code> commands in <em>Terminal</em> I received some odd messages. After some confusion, I realized Subclipse checked out the repository using SVN version 1.7. Unfortunately Mac OS X Mountain Lion runs SVN version 1.6.</p>

<p>I could have downgraded Subclipse. However, I had already checked out several repositories. Furthermore, I liked the smaller footprint of SVN 1.7. In typical lazy developer fashion, I went with updating SVN to version 1.7 for Mac OS X.</p>

<p>To give due credit, the foundations of this post came from a post on <a href="http://nicoduplessis.com/blog/2012/05/06/building-svn-1-dot-7-on-mac-os-x-lion/">Building SVN 1.7</a>. Although I expanded on it, I encourage you to read the original post. For completeness, I outlined the full process below.</p>

<p><strong>Note</strong>: To compile and install SVN 1.7 you need <a href="http://stackoverflow.com/questions/9329243/xcode-4-4-command-line-tools">Xcode with the Command Line Tools installed</a>.</p>

<h2>Download the SVN Source</h2>

<pre><code>cd ~/Downloads/
curl -o subversion-latest.tar.gz http://apache.mirrors.tds.net/subversion/subversion-1.7.8.tar.gz
tar -xvf subversion-latest.tar.gz
</code></pre>

<p><strong>Note</strong>: You may need to update the <code>curl</code> command to download the <a href="http://subversion.apache.org/download/">latest SVN 1.7 source</a>.</p>

<h2>Build and Install SVN</h2>

<p>The default SVN install on Mac OS X uses neon. neon allows you to connect to remote SVN repositories via HTTP and HTTPS. Lines 2-7 installs neon. Line 8 builds SVN using the <code>--with-neon</code> configuration flag.</p>

<pre><code>cd ~/Downloads/subversion-1.7.*
sh get-deps.sh neon
cd neon/
./configure --with-ssl
make
sudo make install
cd ..
./configure --prefix=/usr/local --with-neon
make
sudo make install
</code></pre>

<h2>Using the New SVN</h2>

<p>Your environment will still use SVN version installed with Mac OS X:</p>

<pre><code>svn --version
</code></pre>

<p>To use the SVN version you just installed, you can <a href="http://www.tech-recipes.com/rx/2621/os_x_change_path_environment_variable/">update your <code>PATH</code></a>. Assuming you are using the bash shell, add or edit the following line in your <code>~/.bash_profile</code>:</p>

<pre><code>export PATH=/usr/local/bin:$PATH
</code></pre>

<p>You should now see the SVN version you installed:</p>

<pre><code>svn --version
</code></pre>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Drunkwalking]]></title>
    <link href="http://jason.pureconcepts.net/2012/09/drunkwalking/"/>
    <updated>2012-09-18T00:00:00-04:00</updated>
    <id>http://jason.pureconcepts.net/2012/09/drunkwalking</id>
    <content type="html"><![CDATA[<p>I remember my first weekend at Purdue. It was the last weekend before classes started. Everyone was moving in and the campus was filling up with kids ready to experience college. I joined several of my dorm hall neighbors and went out to party.</p>

<p>Upon returning to the dorm Liam noticed his roommate arrived. He was paired with a roommate from Sumatra. Liam, a good old boy from Pennsylvania, felt a little uneasy without having first met the foreigner. My roommate was gone for the weekend. So I told Liam he could sleep in his bed. We passed out.</p>

<p>Some hours later I woke up. Something was off. As my brain began to function I noticed things. These weren&rsquo;t my sheets. I didn&rsquo;t have a dehumidifier. And that sure wasn&rsquo;t Liam in the bunk across from me. I got down from the loft. I&rsquo;m in my boxers. Where the fuck am I? I unlock and open the door. I&rsquo;m in my dorm hall. After stepping into the hallway, I realize I&rsquo;m next door in Liam&rsquo;s room.</p>

<p>I go to open my door, expecting it to be unlocked. It&rsquo;s locked. I knock. I hear Liam scramble around. He opens the door, &ldquo;Dude, what the hell?&rdquo; I explain. He assures me we went to sleep in my room. We try to figure it out for a minute, laugh, and go back to sleep.</p>

<p>In the morning, we ask Liam&rsquo;s roommate if he remembered anything. He didn&rsquo;t let me in. I didn&rsquo;t have keys. How did I get out of my bed, lock my door, and get into Liam&rsquo;s room without a key?</p>

<p>To this day, it&rsquo;s still a mystery…</p>
]]></content>
  </entry>
  
</feed>
