<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>VerySimple</title>
	<atom:link href="http://verysimple.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://verysimple.com</link>
	<description>Custom Software</description>
	<lastBuildDate>Tue, 15 May 2012 07:40:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>RE: ORM Haters:  In Defense of ORMs</title>
		<link>http://verysimple.com/2012/05/14/re-orm-haters-in-defense-of-orms/</link>
		<comments>http://verysimple.com/2012/05/14/re-orm-haters-in-defense-of-orms/#comments</comments>
		<pubDate>Mon, 14 May 2012 17:42:21 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://verysimple.com/?p=1252</guid>
		<description><![CDATA[This article is in response to a discussion on hacker news regarding ORMs (or object-relational mapping) which is a programming technique where a database is abstracted into classes. Instead of writing SQL at the application level all database interaction is done through objects. There are many ORMs out there, to name just a few: Hibernate for [...]]]></description>
			<content:encoded><![CDATA[<p>This article is in response to a <a href="http://news.ycombinator.com/item?id=3970566" target="_blank">discussion on hacker news</a> regarding ORMs (or object-relational mapping) which is a programming technique where a database is abstracted into classes. Instead of writing SQL at the application level all database interaction is done through objects. There are many ORMs out there, to name just a few: Hibernate for Java, Linq for .NET, Doctrine for PHP, SQLAlchemy for Python, ActiveRecord for Ruby, etc.  As the author of an ORM myself (<a href="http://phreeze.com/">Phreeze</a> for PHP) I felt that I could contribute to the conversation.</p>
<p>I do agree with the author that using an ORM incorrectly can lead to horrible database performance.  The problem, as I see it, with ORMs is that it&#8217;s easy to get up and running with only a basic understanding.  But it only takes one simple, common requirement before you need a deeper understanding of the ORM to prevent disastrous performance.  I&#8217;m going to describe the problem as well as the common solutions using one such example:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> customer<span style="color: #66cc66;">.</span>first_name<span style="color: #66cc66;">,</span> customer<span style="color: #66cc66;">.</span>last_name<span style="color: #66cc66;">,</span> purchase<span style="color: #66cc66;">.</span>grand_total
<span style="color: #993333; font-weight: bold;">FROM</span> customer
<span style="color: #993333; font-weight: bold;">INNER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> purchase <span style="color: #993333; font-weight: bold;">ON</span> customer<span style="color: #66cc66;">.</span>id <span style="color: #66cc66;">=</span> purchase<span style="color: #66cc66;">.</span>customer_id
<span style="color: #993333; font-weight: bold;">WHERE</span> customer<span style="color: #66cc66;">.</span>last_name <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">'%smith%'</span></pre></div></div>

<p>This is a fairly basic SQL query by any standard.  We&#8217;re simply joining a purchase and customer table together and returning a small number of columns from each table.  It&#8217;s not the most simple query possible, but I would still consider this to be SQL 101 level code.  This is also the kind of query that you would see in the most basic web applications.  Yet returning this result from an ORM with efficient database performance can be surprisingly tricky.</p>
<p>My personal opinion is that some ORM authors and users mistakenly rely on an ORM to avoid ever writing any SQL code.  I&#8217;m of the opinion that the benefit is more simply to separate and abstract SQL from the application logic.  If you feel that the point of an ORM is to avoid writing any SQL at all, then the ORM has to be very, very smart (and often overly complicated).  If you feel that the point of an ORM is to abstract the SQL, then custom SQL code can stil be written in your app, but it simply stays separate from the business logic.  I find this an easier approach because otherwise the ORM becomes bloated trying to handle every possible edge case can be done with SQL statements.</p>
<p>Both have pros and cons.  If you don&#8217;t write any SQL then theoretically you are abstracted from the dialect of one database vendor.  So you could later migrate from, say MySQL to Oracle without worrying that your application has MySQL-specific code.  In my experience this almost never happens, and when it does there still winds up being problems anyway.  If you feel that the point is to separate the SQL from the application level then your application will wind up with SQL code and that may tie you somewhat to the database engine.  However you don&#8217;t have to go to such great lengths configuring the ORM and your SQL is fairly well organized and contained at one level of the application.  In case it isn&#8217;t obvious, I favor the later, simpler approach.</p>
<p>The problem with the example query at the basic level is that it doesn&#8217;t match 1-to-1 with a single database table and requires an ORM to do a SQL join in order to have efficient performance.  If the ORM relationships are not configured and it doesn&#8217;t understand how the two tables relate to each other then the ORM would be forced to do a query on one table first, then loop through the results and query the other table.  For example, there may be 1 query for the customers first and then &#8220;n&#8221; queries where &#8220;n&#8221; is the number of customers.  This is what is known as an <a href="http://stackoverflow.com/questions/97197/what-is-the-n1-selects-problem" target="_blank">n+1 query</a> and if you work with ORMs they are a performance destroyer that should be avoided.</p>
<p>ORMs tend to take one of two approaches: a) be very smart with a lot of &#8220;magic&#8221; or b) be simplistic and require the user to configure everything.  To my knowledge there are 4 common techniques that an ORM uses to deal with the above query:</p>
<p>1. Configure the object mapping at compile time for the foreign key relationship<br />
2. Override the fetching strategy at run-time for the foreign key relationship<br />
2. Use a ORM-specific query language to customize the query at run-time<br />
3. Create a custom object mapping at compile time that abstracts the query</p>
<p><strong>Configure the Object Mapping</strong></p>
<p>With most ORMs there is a concept of a &#8220;mapping&#8221; where you assign database tables, columns and relationships to objects.  Each ORM is a little different in it&#8217;s implementation.  Some require configuration files in the form of XLM, some have compiler directives or meta-data that is added to class itself.  Basically this configuration file then indicates to the ORM how to create the SQL query that will ultimately be sent to the database server.</p>
<p><strong>Override the Fetching Strategy</strong></p>
<p>A &#8220;fetching strategy&#8221; is what tells the ORM how to join tables.  This is usually configured along with the object mapping, but usually can be overridden at run-time.  The two common strategies are &#8220;lazy&#8221; and &#8220;eager.&#8221;  This tells the ORM, for example, when querying the purchases table whether it should always do a join with the customer table (eager), or whether it should query the customer table only when necessary (lazy).  In <a href="http://phreeze.com/">Phreeze</a> the fetching strategy can be overridden globally for the application or just prior to retrieving some data.</p>
<p><strong>ORM-Specific Query Language</strong></p>
<p>Many ORMs provide a query language that controls the SQL which is ultimately created.  The point of this is that you are writing in a vendor-neutral langage so that you are not tied to one database.  In my opinion this strategy simply trades one language dialect for another and doesn&#8217;t separate the SQL logic from the business logic.  I have not personally experienced a business decide to change their database vendor and simple swap it out with zero issues thanks to an ORM.  It&#8217;s a beautiful idea but I&#8217;ve never seen it work and so I question the point.  Additionally you have to learn a psuedo-language and remote-control the SQL that is generated.  I am not personally in favor of this strategy.</p>
<p><strong>Custom Object Mapping</strong></p>
<p>In my opinion the simplest approach is often the best.  A custom object mapping is a technique where you simply create objects and the ORM allows you to provide the SQL that it will use to issue queries.  This allows you to write the most efficient SQL possible for retrieving the data that you want.  In <a href="http://phreeze.com/">Phreeze</a> these are called &#8220;Reporters&#8221;</p>
<p>The main negative to this approach is that you can wind up with overlap in your objects.  For example you may have a Customer object and a Purchase object.  Now additionally you may have a CustomerPurchase object as well which combines the two.  You may have multiple variations of the CustomerPurchase object.  Some people don&#8217;t like this duplication, but in my opinion the ORM &#8211; relational mismatch has to occur someplace.  I&#8217;d rather see some class redundancy than deal with DB performance issues or an overly complex ORM system.</p>
<p>Obviously I&#8217;m a fan of using ORMs and my reasoning is separation of SQL from application logic (rather than avoidance of writing SQL code).  Used properly I feel they are a valuable technique for keeping code organized.  I&#8217;m sure some ORM and non-ORM users would disagree with my opinions on the matter, but we most likely agree that it is an interesting technical problem.  If you have any thoughts feel free to post a comment.</p>
]]></content:encoded>
			<wfw:commentRss>http://verysimple.com/2012/05/14/re-orm-haters-in-defense-of-orms/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Great Programmers Don&#8217;t Trust Their Own Code</title>
		<link>http://verysimple.com/2012/04/05/great-programmers-dont-trust-their-own-code/</link>
		<comments>http://verysimple.com/2012/04/05/great-programmers-dont-trust-their-own-code/#comments</comments>
		<pubDate>Thu, 05 Apr 2012 07:51:43 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Digital Life]]></category>

		<guid isPermaLink="false">http://verysimple.com/?p=1224</guid>
		<description><![CDATA[Great programmers don&#8217;t trust their own code and assume that they&#8217;ve made mistakes. What exactly do I mean by that?  Notice I didn&#8217;t say that great programmers actually make a lot of mistakes.  In fact great programmers probably make a lot less mistakes than their novice counterparts.  But they approach their code with the attitude [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-1229" title="code-wide" src="http://verysimple.com/wp-content/uploads/2012/04/code-wide.png" alt="" width="600" height="260" /></p>
<h4>Great programmers don&#8217;t trust their own code and assume that they&#8217;ve made mistakes.</h4>
<p>What exactly do I mean by that?  Notice I didn&#8217;t say that great programmers actually <em>make</em> a lot of mistakes.  In fact great programmers probably make a lot less mistakes than their novice counterparts.  But they approach their code with the attitude that there are bugs that need to be discovered.  If something isn&#8217;t working, they tend to assume first that their code is problematic until proven otherwise.  Novices are often quick to blame an API, framework or even the language when their code isn&#8217;t working.  I&#8217;ve literally gotten into yelling matches with frustrated programmers trying to convince me that a framework is broken.</p>
<p>I think there must be an exponential improvement as you grow.  The better you get, the more you scrutinize your code, the less mistakes you make, the more you scrutinize, etc.</p>
<p>There&#8217;s tools and techniques to help ensure code is solid, but the best programmers I&#8217;ve known will write solid code with or without them.  Their code is good because they approach programming with a defensive attitude.  It doesn&#8217;t matter how many unit tests you write if you are too trusting of your own code.  Buggy software tends to assume best-case-scenarios.  The solid programmer obsesses over his/her code, looking for edge cases.</p>
<p>Do you have a mental process for reviewing your own code?  Leave it in the comments!</p>
]]></content:encoded>
			<wfw:commentRss>http://verysimple.com/2012/04/05/great-programmers-dont-trust-their-own-code/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Apple Address Book not Syncing With iCloud</title>
		<link>http://verysimple.com/2012/04/01/apple-address-book-not-syncing-with-icloud/</link>
		<comments>http://verysimple.com/2012/04/01/apple-address-book-not-syncing-with-icloud/#comments</comments>
		<pubDate>Mon, 02 Apr 2012 04:46:30 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[OSX]]></category>

		<guid isPermaLink="false">http://verysimple.com/?p=1207</guid>
		<description><![CDATA[I recently started using Apple&#8217;s iCloud service to sync the address book, contacts and calendar between my desktop and phone.  It&#8217;s a fantastic service that allows you to add or edit a contact in one place and have that contact appear on all of your other devices instantly without plugging in your phone to sync. [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://verysimple.com/wp-content/uploads/2012/04/icloud2.png" rel="shadowbox[sbpost-1207];player=img;" title="icloud2"><img class="alignright  wp-image-1209" title="icloud2" src="http://verysimple.com/wp-content/uploads/2012/04/icloud2-248x300.png" alt="" width="149" height="180" /></a>I recently started using Apple&#8217;s iCloud service to sync the address book, contacts and calendar between my desktop and phone.  It&#8217;s a fantastic service that allows you to add or edit a contact in one place and have that contact appear on all of your other devices instantly without plugging in your phone to sync.  I was having a strange problem, though.  The Address Book wasn&#8217;t syncing consistently.  Most contacts would sync right away but a few of them I added from the desktop would never seem to sync to my iPhone.</p>
<p>I discovered that there&#8217;s two Address Book &#8220;accounts&#8221; on the desktop.  There&#8217;s a local account called &#8220;On My Mac&#8221; and another &#8220;iCloud&#8221; account.  It&#8217;s possible that you might have even more accounts, for example Gmail.  Only contacts added to the iCloud account will sync.  It seems obvious except that there&#8217;s no visual indication of which contacts belong to which accounts.   As it turns out &#8220;On My Mac&#8221; was set as the default account so whenever I created a new contact on my desktop it wouldn&#8217;t sync.</p>
<p>My solution was to to first set iCloud as the default account.  From that point on all new contacts would be added to the iCloud account and sync instantly.</p>
<p><a href="http://verysimple.com/wp-content/uploads/2012/04/icloud1.png" rel="shadowbox[sbpost-1207];player=img;" title="icloud1"><img class="alignright size-medium wp-image-1208" title="icloud1" src="http://verysimple.com/wp-content/uploads/2012/04/icloud1-300x159.png" alt="" width="300" height="159" /></a>That left me with the problem of moving the existing &#8220;On My Mac&#8221; contacts into iCloud.  So that I could see which accounts were part of the local account I unchecked the &#8220;enable&#8221; checkbok for the iCloud account.  All of my iCloud contacts became hidden and only the 10 or so local contacts remained visible.  I selected all of the local contacts and dragged them to the desktop, which exported them as vCards.  Next I deleted the local contacts so I wouldn&#8217;t have duplicates when I re-import them.  Finally I re-enabled iCloud and dragged the exported vCards back into Address Book.  At this point all of my contacts were in the iCloud account and everything synced as expected.</p>
<p>Once all of my contacts were moved to iCloud I disabled the local account.</p>
]]></content:encoded>
			<wfw:commentRss>http://verysimple.com/2012/04/01/apple-address-book-not-syncing-with-icloud/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Your connection had to be retried using SSL 3.0 &#8211; Apache 2 SSL Certificate Configuration</title>
		<link>http://verysimple.com/2012/03/12/your-connection-had-to-be-retried-using-ssl-3-0-apache-2-ssl-certificate-configuration/</link>
		<comments>http://verysimple.com/2012/03/12/your-connection-had-to-be-retried-using-ssl-3-0-apache-2-ssl-certificate-configuration/#comments</comments>
		<pubDate>Tue, 13 Mar 2012 04:45:33 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[*NIX]]></category>
		<category><![CDATA[Apache]]></category>

		<guid isPermaLink="false">http://verysimple.com/?p=1202</guid>
		<description><![CDATA[When viewing your SSL certification details in Chrome you may notice an annoying yellow warning icon with the error message &#8220;Your connection had to be retried using SSL 3.0 This typically means the server is using very old software and may have other security issues&#8221; This warning technically doesn&#8217;t affect or hurt anything but of [...]]]></description>
			<content:encoded><![CDATA[<p>When viewing your SSL certification details in Chrome you may notice an annoying yellow warning icon with the error message &#8220;Your connection had to be retried using SSL 3.0 This typically means the server is using very old software and may have other security issues&#8221;</p>
<p>This warning technically doesn&#8217;t affect or hurt anything but of course after paying for the SSL cert and going through the trouble of installing it, we all want our users to see the green lock icon and not a yellow warning icon!  If you&#8217;re running Apache2 the reason for this is that Chrome prefers to use TLS encryption but had to fall back to SSL encryption.  Apache2 supports TLS out of the box but may not be enabled by default.</p>
<p>To enable TLS, open your apache configuration file and add the two lines below:  (The config file is where you previously configured SSLCertificateFile and SSLCertificateKeyFile.  It&#8217;s possibly located in /etc/apache2/sites-enabled)</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">SSLProtocol <span style="color: #660033;">-all</span> +TLSv1 +SSLv3
SSLCipherSuite HIGH:MEDIUM:<span style="color: #000000; font-weight: bold;">!</span>aNULL:+SHA1:+MD5:+HIGH:+MEDIUM</pre></div></div>

<p>What these lines do is specify that both TLS version 1 and SSL version 3 are supported.  Once you&#8217;ve added these lines you need to restart Apache (/etc/init.d/apache2 restart).</p>
<p>If you refresh your browser at this point it&#8217;s likely that the warning icon is still there.   Shutting down and re-starting your browser should resolve it.  I suspect that the browser negotiates an SSL connection once and continues to use it until the session expires or the browser is restarted.</p>
]]></content:encoded>
			<wfw:commentRss>http://verysimple.com/2012/03/12/your-connection-had-to-be-retried-using-ssl-3-0-apache-2-ssl-certificate-configuration/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Auto Accept.applescript for OSX Messages</title>
		<link>http://verysimple.com/2012/02/16/auto-accept-applescript-for-osx-messages/</link>
		<comments>http://verysimple.com/2012/02/16/auto-accept-applescript-for-osx-messages/#comments</comments>
		<pubDate>Thu, 16 Feb 2012 23:38:03 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[OSX]]></category>

		<guid isPermaLink="false">http://verysimple.com/?p=1185</guid>
		<description><![CDATA[iChat will be replaced in the next version of OSX &#8220;Mountain Lion&#8221; with an app called simply &#8220;Messages.&#8221; This new app is an improvement to iChat and includes some nice features like multiple chats in a single window and the ability to send messages to iPhones via iMessage. You can download the BETA version now [...]]]></description>
			<content:encoded><![CDATA[<p>iChat will be replaced in the next version of OSX &#8220;Mountain Lion&#8221; with an app called simply &#8220;Messages.&#8221; This new app is an improvement to iChat and includes some nice features like multiple chats in a single window and the ability to send messages to iPhones via iMessage. You can <a href="http://www.apple.com/macosx/mountain-lion/messages-beta/" target="_blank">download the BETA version now from Apple</a>.</p>
<p>One thing that was not packaged in the initial beta release is the Apple Script to automatically accept text invitations.  I find it a huge annoyance to click &#8220;Accept&#8221; every time a new text comes through.  Fortunately the original iChat AppleScripts work on Messages but you just have to obtain and save it to ~/Library/Scripts/Messages.</p>
<p>Download Auto Accept below and enjoy&#8230;</p>
<p><a href="http://verysimple.com/wp-content/uploads/2012/02/AutoAccept.zip">Download AutoAccept.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://verysimple.com/2012/02/16/auto-accept-applescript-for-osx-messages/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Kill imagent</title>
		<link>http://verysimple.com/2011/12/23/kill-imagent/</link>
		<comments>http://verysimple.com/2011/12/23/kill-imagent/#comments</comments>
		<pubDate>Fri, 23 Dec 2011 09:33:07 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[OSX]]></category>

		<guid isPermaLink="false">http://verysimple.com/?p=1169</guid>
		<description><![CDATA[For some reason after upgrading to Lion I have to kill the process for imagent regularly in order to use iChat.  Otherwise iChat stays stuck saying &#8220;unavailable.&#8221;  I don&#8217;t know exactly why this is happening to some people and not others but I&#8217;m one of the unlucky people who has been experiencing it ever since [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://verysimple.com/wp-content/uploads/2011/12/kill-imagent.png" rel="shadowbox[sbpost-1169];player=img;" title="kill-imagent"><img class="alignright size-full wp-image-1171" title="kill-imagent" src="http://verysimple.com/wp-content/uploads/2011/12/kill-imagent.png" alt="" width="247" height="228" /></a>For some reason after upgrading to Lion I have to kill the process for imagent regularly in order to use iChat.  Otherwise iChat stays stuck saying &#8220;unavailable.&#8221;  I don&#8217;t know exactly why this is happening to some people and not others but I&#8217;m one of the unlucky people who has been experiencing it ever since I upgraded.  It seems to happen when I let my computer go to sleep.  iChat doesn&#8217;t connect after the laptop wakes up.</p>
<p>Since it&#8217;s turned into almost a daily thing for me to open terminal and kill imagent, I decided to write that into applescript and make an icon so I can just click it.  It&#8217;s only one line of applescript:</p>
<p><code>do shell script "killall imagent"</code></p>
<p>That&#8217;s all there is to it, but in case you don&#8217;t know or want to deal with compiling that yourself, you can download this <a href="http://verysimple.com/wp-content/uploads/2011/12/kill-imagent.zip">pre-built version of kill-imagent</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://verysimple.com/2011/12/23/kill-imagent/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Install Image Magick for PHP on OSX</title>
		<link>http://verysimple.com/2011/12/21/install-image-magick-for-php-on-osx/</link>
		<comments>http://verysimple.com/2011/12/21/install-image-magick-for-php-on-osx/#comments</comments>
		<pubDate>Thu, 22 Dec 2011 05:34:56 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[OSX]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://verysimple.com/?p=1160</guid>
		<description><![CDATA[These instructions will install the ImageMagick binaries as well as the PHP extension for the default OSX Apache/PHP setup.  If you prefer not to use MacPorts there are binaries available, however you may have to deal with some dependencies and configuration on your own. 1. Install ImageMagick sudo port install ImageMagick 2. Install imagic module [...]]]></description>
			<content:encoded><![CDATA[<p>These instructions will install the ImageMagick binaries as well as the PHP extension for the default OSX Apache/PHP setup.  If you prefer not to use MacPorts there are binaries available, however you may have to deal with some dependencies and configuration on your own.</p>
<h3>1. Install ImageMagick</h3>
<p><code>sudo port install ImageMagick</code></p>
<h3>2. Install imagic module</h3>
<p>You&#8217;d expect to just be able to run &#8220;pecl install imagick&#8221; and I would probably try it first.  However the instructions below will work if the automatic installation returns the error: ImageMagick MagickWand API configuration program&#8230; configure: error: not found. Please provide a path to MagickWand-config or Wand-config program. ERROR: &#8216;/private/tmp/pear/temp/imagick/configure &#8211;with-imagick=/opt/local/bin/&#8217; failed.</p>
<p><em>Note version is 3.0.1 in these instructions, adjust the commands depending on the version that is downloaded by pecl.</em></p>
<p><code>pecl download imagick<br />
tar xvzf imagick-3.0.1.tgz<br />
cd imagick-3.0.1<br />
phpize<br />
./configure --with-imagick=/opt/local<br />
make<br />
sudo make install</code></p>
<p>The install process will create a file &#8220;imagick.so&#8221;, but it may not be automatically installed in the correct location depending on your PHP path settings.  The install will output the location of the .so file so if necessary, you can manually move that file to the extensions directory for your web server.</p>
<h3>3. Append to php.ini</h3>
<p><code>extension=imagick.so</code></p>
<p>That should be it.  Restart Apache and view phpinfo.php. There should be a section for ImageMagick</p>
]]></content:encoded>
			<wfw:commentRss>http://verysimple.com/2011/12/21/install-image-magick-for-php-on-osx/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Four Reasons to NOT use try/catch</title>
		<link>http://verysimple.com/2011/11/14/four-reasons-to-not-use-trycatch/</link>
		<comments>http://verysimple.com/2011/11/14/four-reasons-to-not-use-trycatch/#comments</comments>
		<pubDate>Mon, 14 Nov 2011 20:39:24 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Languages]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://verysimple.com/?p=1111</guid>
		<description><![CDATA[I was reading an argument discussion on google groups regarding the try/catch statement and node.js. In particular there was a suggestion that try/catch is an anti-pattern, meaning a poor development habit that is in common use. I can&#8217;t really agree that try/catch on it&#8217;s own is a bad thing but it is certainly easy to [...]]]></description>
			<content:encoded><![CDATA[<p>I was reading an <span style="text-decoration: line-through;">argument</span> discussion on <a href="https://groups.google.com/forum/#!topic/nodejs/1ESsssIxrUU">google groups</a> regarding the try/catch statement and node.js.  In particular there was a suggestion that try/catch is an anti-pattern, meaning a poor development habit that is in common use.  I can&#8217;t really agree that try/catch on it&#8217;s own is a bad thing but it is certainly easy to abuse. I started thinking about bad code that I&#8217;ve seen due to try/catch and wondered if I could identify concrete examples of when try/catch is the wrong solution to a problem.  I came up with four of them.</p>
<p>Most of these errors I feel are due to developer fear and paranoia that the end user will see an error message.  Nobody wants their customer to encounter bugs and errors, but there is a difference between an app that is solid and one that simply hides problems.  It&#8217;s much harder to fix a bug that nobody knows is there.  I&#8217;ve written about this before in my article about <a href="http://verysimple.com/2009/04/03/insidious-bugs/">insidious bugs</a>.</p>
<h3>1. Sticking Your Head in the Sand:</h3>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">try <span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// ... code here...</span>
<span style="color: #009900;">&#125;</span> catch <span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// hope this never happens!</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>A try/catch statement with no error handling inside the catch statement is a great way to mask errors. (masking errors is bad!) Your code quietly suppresses the error and no user or developer will see a problem unless they notice unusual behavior of the app or <strong>data loss</strong>.  This seems to be a strategy used when the code contains an expected error that can be safely ignored and shouldn&#8217;t halt the program. That is a dubious assumption but assuming it is true, the danger with this strategy is that a different, unexpected error might also occur. Because this try/catch doesn&#8217;t discriminate it will mask all errors that occur and will hide a situation that wasn&#8217;t anticipated.</p>
<p>A better approach (assuming the exception that can be safely ignored) might be to first ensure the try/catch surrounds only the most minimal code or line in question.  Then when the error is caught, verify that this is the expected exception and not something else by checking the exception type, id, etc (depending on the language).  It can be helpful to at least write a &#8220;warning&#8221; to the console or a log file so that when another developer is trying to fix your bugs, he/she will have some clues as to what your logic was when you were writing this code.</p>
<h3>2. Attempting to Set Things Right:</h3>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">try <span style="color: #009900;">&#123;</span>
  i <span style="color: #339933;">=</span> x<span style="color: #339933;">.</span>toUpperCase<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> catch <span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// x must be null.  wonder why...?  oh well, let's fix it!</span>
  i <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Handling an exception by ignoring faulty input and setting variables to arbitrary, default values can be dangerous. This has a high probability of creating &#8220;insidious&#8221; bugs because they don&#8217;t always address the cause of the exception and simply try to fix it.  Again, this masks problems and makes apps extremely difficult to debug.</p>
<p>The optimal way to handle this scenario is to prevent the invalid input at it&#8217;s source, before it gets passed into a method or function.  If this method is supposed to gracefully handle bad input then it should do so by checking for legitimate values explicitly instead before using them.  If the input doesn&#8217;t validate then throw an exception.  This is a scary concept to novice and sloppy programmers alike because they are afraid of  creating errors that must then be hunted down and fixed at the source.  However what this really does is to *reveal* bugs in faulty calling code.  Revealing bugs is a good thing.  It can, unfortunately, open a can of worms and a lot of sloppy calling code now becomes your problem!</p>
<h3>3. The Hot Potato:</h3>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">try <span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// ... code here...</span>
<span style="color: #009900;">&#125;</span> catch <span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// whew!  good thing we caught this!</span>
  <span style="color: #b1b100;">throw</span> e<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>A useless try/catch that simply re-throws the original exception does nothing to improve the code. This is probably the least harmful mistake because it doesn&#8217;t mask errors.  However the code is worthless and does nothing to help with debugging or make the app more stable.</p>
<p>The solution is to just remove the try/catch and let the original error occur. The end result is the same.</p>
<h3>4. Re-branding Exceptions:</h3>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">try <span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// ... code here...</span>
<span style="color: #009900;">&#125;</span> catch <span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// jason said throwing exceptions is good. i wonder what he meant?</span>
  <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span> e<span style="color: #339933;">.</span>getMessage<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Catching an exception and then throwing a new exception with some of the original info. This example may not mask bugs but it can make the original problem difficult to locate. The stack trace of the original exception probably contains clues about the original source of the error, but you lose all of that information when you create and throw a new exception.</p>
<p>Believe it or not, a good way to handle this is to remove the try/catch. There is one legit reason (in my opinion) to throw a new exception. If you anticipate an exception to occur and 1) you are able to keep the application in a known state and 2) you need the error text to be more friendly or understandable. For example, if you expect a network connection exception to be thrown under normal conditions then you may want to create your own exception that says &#8220;Network Unavailable&#8221; instead of a allowing a cryptic error message to come from a low-level network API. However you do need to be meticulous and add logic to verify that you are catching only the expected exception and not something else. Because if you are expecting a network exception but instead get an &#8220;index out of bounds&#8221; then your &#8220;Network Unavailable&#8221; message is not only masking a bug, but potentially sending another developer on a wild goose chase.</p>
<p>Those are the situations that I was able to think of off the top of my head.  Do you have any other try/catch situations worth mentioning? Feel free to leave them in the comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://verysimple.com/2011/11/14/four-reasons-to-not-use-trycatch/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Installing LAMP Stack on OSX 10.7 Lion</title>
		<link>http://verysimple.com/2011/08/18/installing-lamp-stack-on-osx-10-7-lion/</link>
		<comments>http://verysimple.com/2011/08/18/installing-lamp-stack-on-osx-10-7-lion/#comments</comments>
		<pubDate>Thu, 18 Aug 2011 22:14:41 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[OSX]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://verysimple.com/?p=998</guid>
		<description><![CDATA[This is a follow-up to my previous article on installing a LAMP Stack on Snow Leopard and explains the steps that you need to get Lion up and running for LAMP development.  (Linux, Apache, MySQL and PHP in case you don&#8217;t already know).  Lion comes pre-installed with Apache and PHP 5.3.6 so you only need [...]]]></description>
			<content:encoded><![CDATA[<p>This is a follow-up to my previous article on <a href="http://verysimple.com/2009/09/18/installing-lamp-stack-on-osx-10-6-snow-leopard/" target="_blank">installing a LAMP Stack on Snow Leopard</a> and explains the steps that you need to get Lion up and running for LAMP development.  (Linux, Apache, MySQL and PHP in case you don&#8217;t already know).  Lion comes pre-installed with Apache and PHP 5.3.6 so you only need to enable those features.  MySQL is the only component that you have to install.</p>
<h3>1.Turn on Apache</h3>
<p>Go to System Settings-&gt;Sharing and turn on Web Sharing. If necessary click the button that says &#8220;Create Home Folder&#8221; which will create a folder called &#8220;Sites&#8221; in your home directory.  You now have a web server that you can access at http://localhost/~username/  (&#8220;username&#8221; being your own account login name)</p>
<h3>2. Edit /private/etc/apache2/httpd.conf</h3>
<p>To enable PHP uncomment (remove the number sign at the beginning of) the line:</p>
<p>#LoadModule php5_module libexec/apache2/libphp5.so</p>
<p>(optional) you can re-map the server root to your home website directory by editing DocumentRoot:</p>
<p>DocumentRoot “/Users/username/Sites”</p>
<p>If you wish to use .htaccess files then look a bit further down AllowOverride and set it to &#8220;All&#8221; like so:</p>
<p>Options FollowSymLinks<br />
AllowOverride All<br />
Order deny,allow<br />
Deny from all</p>
<h3>3. Edit /private/etc/apache2/users/username.conf</h3>
<p>Your user directory has it&#8217;s own permissions as well which are located in this separate file.  You may wish to enable FollowSymLinks and AllowOverride again here by changing these two lines like so:</p>
<p>Options Indexes MultiViews FollowSymLinks<br />
AllowOverride All</p>
<h3>4. Copy /private/etc/php.ini.default to /private/etc/php.ini</h3>
<p>OSX includes a default php.ini file that you can use but you must rename or copy it first.  If you don&#8217;t do this then PHP will still run but it will just be using the default initialization settings with no way for you to override them.</p>
<p>Edit these settings in <strong>php.ini</strong> (some of these settings will not come into play until they are installed)</p>
<p>display_errors = On<br />
mysql.default_socket = /tmp/mysql.sock<br />
pdo_mysql.default_socket=/tmp/mysql.sock<br />
date.timezone = &#8216;America/Chicago&#8217;<br />
include_path = &#8220;.:/usr/lib/php/pear&#8221;</p>
<h3>5. (Optional) Install PEAR</h3>
<p>If you use the PEAR libraries you can install them using the included phar file like so:</p>
<p>sudo php /usr/lib/php/install-pear-nozlib.phar<br />
sudo pear config-set php_ini /private/etc/php.ini<br />
sudo pecl config-set php_ini /private/etc/php.ini<br />
sudo pear upgrade-all</p>
<h3>6.  Install MySQL</h3>
<p>This doesn&#8217;t really require instructions, simply download the latest MySQL from <a href="http://mysql.com/">mysql.com</a>.  I installed the 64 bit version.</p>
<h3>7. (Optional) Install Apache Plugins</h3>
<p>If you use encryption you may need to install mcrypt.  <a href="http://michaelgracie.com/2011/07/21/plugging-mcrypt-into-php-on-mac-os-x-lion-10-7/" target="_blank">Instructions</a> have been provided by Michael Gracie</p>
<p>If you use the Zend debugger you can install that using <a href="http://verysimple.com/2011/08/16/installing-zend-php-debugger-in-eclipse-on-osx/" target="_blank">these instructions</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://verysimple.com/2011/08/18/installing-lamp-stack-on-osx-10-7-lion/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Installing Zend PHP Debugger in Eclipse on OSX</title>
		<link>http://verysimple.com/2011/08/16/installing-zend-php-debugger-in-eclipse-on-osx/</link>
		<comments>http://verysimple.com/2011/08/16/installing-zend-php-debugger-in-eclipse-on-osx/#comments</comments>
		<pubDate>Tue, 16 Aug 2011 21:02:08 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[OSX]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://verysimple.com/?p=993</guid>
		<description><![CDATA[This walk-through video shows how to install  and enable PHP debugging using the Zend debugger in Eclipse on OSX.  Instead of using print_r and die statements you can step through your code line-by-line, inspect variables and objects, set breakpoints and view the call stack. Using a debugger really pays off in the long run in [...]]]></description>
			<content:encoded><![CDATA[<p>This walk-through video shows how to install  and enable PHP debugging using the Zend debugger in Eclipse on OSX.  Instead of using print_r and die statements you can step through your code line-by-line, inspect variables and objects, set breakpoints and view the call stack.</p>
<p>Using a debugger really pays off in the long run in my opinion.  It gives you so much visibility and insight into what&#8217;s happening in your code and allows you to work faster.  Most developers that I know don&#8217;t bother installing a debugger for PHP web applications because either they either aren&#8217;t aware of how well it works and/or they think the initial setup is a pain.  The setup does have a few steps but actually isn&#8217;t difficult.  This video walks you through all of the steps to install the Zend debugger.</p>
<p><a href="http://verysimple.com/2011/08/16/installing-zend-php-debugger-in-eclipse-on-osx/"><em>Click here to view the embedded video.</em></a></p>
<p><strong>Download links referenced in the video:</strong></p>
<p>Zend Studio Web Debugger (Apache Module):<br />
<a title="http://www.zend.com/en/products/studio/downloads" dir="ltr" href="http://www.zend.com/en/products/studio/downloads" rel="nofollow" target="_blank">http://www.zend.com/en/products/studio/downloads</a></p>
<p>Zend Debugger Plugin Install Site (Eclipse Plugin):<br />
<a title="http://downloads.zend.com/pdt" dir="ltr" href="http://downloads.zend.com/pdt" rel="nofollow" target="_blank">http://downloads.zend.com/pdt</a></p>
<p>Optionally you can download the Zend debugger plugin and install it manually by copying the files to your Eclipse folder instead of using the &#8220;Install Site&#8221;  That can be downloaded here: <a href="http://www.zend.com/en/community/pdt ">http://www.zend.com/en/community/pdt </a></p>
<p><strong>Configuration text for php.ini</strong></p>
<p>zend_extension=/usr/lib/php/extensions/ZendDebugger.so<br />
zend_debugger.expose_remotely=always<br />
zend_debugger.connector_port=10000<br />
zend_debugger.allow_hosts=127.0.0.1/32,192.168.*.*,10.*.*.*</p>
]]></content:encoded>
			<wfw:commentRss>http://verysimple.com/2011/08/16/installing-zend-php-debugger-in-eclipse-on-osx/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 1.645 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2012-05-16 22:28:17 -->

