<?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>Fri, 06 Jan 2012 18:12:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<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>0</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>0</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 to 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 32 bit version, however it may be possible to run the 64 bit version as well.</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>6</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>7</slash:comments>
		</item>
		<item>
		<title>UPS &amp; FedEx Shipment Tracking URL</title>
		<link>http://verysimple.com/2011/07/06/ups-tracking-url/</link>
		<comments>http://verysimple.com/2011/07/06/ups-tracking-url/#comments</comments>
		<pubDate>Wed, 06 Jul 2011 17:17:27 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Random Thoughts]]></category>

		<guid isPermaLink="false">http://verysimple.com/?p=951</guid>
		<description><![CDATA[Direct URL for UPS shipment tracking: http://wwwapps.ups.com/WebTracking/track?track=yes&#038;trackNums=1ZXXXXXXXXXXXXXXXX If any value is provided for the &#8220;track&#8221; parameter then the confirmation page is skipped and the user goes directly to the tracking page.  If you&#8217;d rather send the user to the confirmation page then just omit that parameter. Direct URL for FedEx shipment tracking: http://www.fedex.com/Tracking?action=track&#038;tracknumbers=XXXXXXXXXXXXXXXXX]]></description>
			<content:encoded><![CDATA[<h4>Direct URL for UPS shipment tracking:</h4>
<p>http://wwwapps.ups.com/WebTracking/track?track=yes&#038;trackNums=1ZXXXXXXXXXXXXXXXX</p>
<p>If any value is provided for the &#8220;track&#8221; parameter then the confirmation page is skipped and the user goes directly to the tracking page.  If you&#8217;d rather send the user to the confirmation page then just omit that parameter.</p>
<h4>Direct URL for FedEx shipment tracking:</h4>
<p>http://www.fedex.com/Tracking?action=track&#038;tracknumbers=XXXXXXXXXXXXXXXXX</p>
]]></content:encoded>
			<wfw:commentRss>http://verysimple.com/2011/07/06/ups-tracking-url/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Evaluating Math in PHP</title>
		<link>http://verysimple.com/2011/06/28/evaluating-math-in-php/</link>
		<comments>http://verysimple.com/2011/06/28/evaluating-math-in-php/#comments</comments>
		<pubDate>Wed, 29 Jun 2011 01:02:38 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://verysimple.com/?p=930</guid>
		<description><![CDATA[This is a simple math formula parser for PHP.  This is based off of various comments at php.net.  For security all alphabetical characters are stripped which means that functions like sin, cos, etc are not supported.  Please leave any improvements or suggestions in the comments below. /** * Evaluates a math equation and returns the result, [...]]]></description>
			<content:encoded><![CDATA[<p>This is a simple math formula parser for PHP.  This is based off of various comments at <a href="http://php.net/eval" target="_blank">php.net</a>.  For security all alphabetical characters are stripped which means that functions like sin, cos, etc are not supported.  Please leave any improvements or suggestions in the comments below.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
* Evaluates a math equation and returns the result, sanitizing
* input for security purposes.  Note, this function does not
* support math functions (sin, cos, etc)
*
* @param string the math equation to evaluate (ex:  100 * 24)
* @return number
*/</span>
<span style="color: #000000; font-weight: bold;">function</span> evalmath<span style="color: #009900;">&#40;</span><span style="color: #000088;">$equation</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// sanitize imput</span>
<span style="color: #000088;">$equation</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/[^0-9+\-.*\/()%]/&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$equation</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// convert percentages to decimal</span>
<span style="color: #000088;">$equation</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/([+-])([0-9]{1})(%)/&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;*(1<span style="color: #000099; font-weight: bold;">\$</span>1.0<span style="color: #000099; font-weight: bold;">\$</span>2)&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$equation</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$equation</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/([+-])([0-9]+)(%)/&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;*(1<span style="color: #000099; font-weight: bold;">\$</span>1.<span style="color: #000099; font-weight: bold;">\$</span>2)&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$equation</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$equation</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/([0-9]+)(%)/&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;.<span style="color: #000099; font-weight: bold;">\$</span>1&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$equation</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$equation</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">&quot;&quot;</span> <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><span style="color: #990000;">eval</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;return &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$equation</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;;&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span> <span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Unable to calculate equation&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">return</span> <span style="color: #000088;">$result</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://verysimple.com/2011/06/28/evaluating-math-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Update WordPress SimplePie to 1.3-dev</title>
		<link>http://verysimple.com/2011/06/18/update-wordpress-simplepie-to-1-3-dev/</link>
		<comments>http://verysimple.com/2011/06/18/update-wordpress-simplepie-to-1-3-dev/#comments</comments>
		<pubDate>Sat, 18 Jun 2011 21:47:34 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://verysimple.com/?p=907</guid>
		<description><![CDATA[WordPress includes an RSS parsing library called SimplePie.  WordPress utilizes this open source project to handle the low-level details of parsing RSS feeds. The version included with WordPress (as of 3.1.3) is 1.2.  However this is not the most recent version of SimplePie.  Attached to this post is SimplePie 1.3-dev which is compatible with version [...]]]></description>
			<content:encoded><![CDATA[<p>WordPress includes an RSS parsing library called <a href="http://simplepie.org" target="_blank">SimplePie</a>.  WordPress utilizes this open source project to handle the low-level details of parsing RSS feeds.</p>
<p>The version included with WordPress (as of 3.1.3) is 1.2.  However this is not the most recent version of SimplePie.  Attached to this post is SimplePie 1.3-dev which is compatible with version 1.2 but addresses various issues.</p>
<p>If you are having trouble parsing feeds, you may try downloading this file and replacing the file /wp-includes/class-simplepie.php with this one.  Be sure to back up your original file in case anything goes wrong.</p>
<p>Click the package below to download the file:</p>
<p><a href="http://verysimple.com/wp-content/uploads/2011/06/simplepie-1.3-dev.zip" title="Download SimplePie 1.3-dev"><img class="alignnone" title="Download SimplePie 1.3-dev" src="http://verysimple.com/wp-includes/images/crystal/archive.png" alt="Download SimplePie 1.3-dev" width="46" height="60" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://verysimple.com/2011/06/18/update-wordpress-simplepie-to-1-3-dev/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>MySQL can&#8217;t specify target table for update in FROM clause</title>
		<link>http://verysimple.com/2011/03/30/mysql-cant-specify-target-table-for-update-in-from-clause/</link>
		<comments>http://verysimple.com/2011/03/30/mysql-cant-specify-target-table-for-update-in-from-clause/#comments</comments>
		<pubDate>Wed, 30 Mar 2011 21:50:54 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://verysimple.com/?p=865</guid>
		<description><![CDATA[If you&#8217;re at this page you probably have encountered an error similar to &#8220;Error Code: 1093 You can&#8217;t specify target table &#8216;my_table&#8217; for update in FROM clause&#8221; The reason for this error is that MySQL doesn&#8217;t allow updates to a table when you are also using that same table in an inner select as your [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re at this page you probably have encountered an error similar to &#8220;Error Code: 1093 You can&#8217;t specify target table &#8216;my_table&#8217; for update in FROM clause&#8221;  The reason for this error is that MySQL doesn&#8217;t allow updates to a table when you are also using that same table in an inner select as your update criteria.  I don&#8217;t know why MySQL has this limitation, but my best guess is that it causes some issue due to file locking or perhaps could cause an infinite loop.  Other databases support this type of statement but MySQL requires a workaround.</p>
<p>Luckily there&#8217;s a solution.  As an example below is a query that will set the priority to &#8220;1&#8243; for all customers who have at least one matching purchase record.  <em>I realize this is a stupid way to run this particular query, however I am merely posting a simple example of a query to demonstrate the error and workaround.  Jeez, get off my back!</em></p>
<p><em><span id="more-865"></span></em></p>
<h3>A Non-Working Example:</h3>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">UPDATE</span> customer
<span style="color: #993333; font-weight: bold;">SET</span> customer<span style="color: #66cc66;">.</span>priority <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">1</span>
<span style="color: #993333; font-weight: bold;">WHERE</span> customer<span style="color: #66cc66;">.</span>id <span style="color: #993333; font-weight: bold;">IN</span>
<span style="color: #66cc66;">&#40;</span>
  <span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #993333; font-weight: bold;">DISTINCT</span> customer<span style="color: #66cc66;">.</span>id <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: #66cc66;">&#41;</span></pre></div></div>

<p>The above query will give you the MySQL target table error because we are trying to update the customer table, but the customer table is also used to supply the list of IDs.</p>
<h3>A Working Version of the Example Above:</h3>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">UPDATE</span> customer
<span style="color: #993333; font-weight: bold;">SET</span> customer<span style="color: #66cc66;">.</span>priority <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">1</span>
<span style="color: #993333; font-weight: bold;">WHERE</span> customer<span style="color: #66cc66;">.</span>id <span style="color: #993333; font-weight: bold;">IN</span>
<span style="color: #66cc66;">&#40;</span>
  <span style="color: #993333; font-weight: bold;">SELECT</span> id <span style="color: #993333; font-weight: bold;">FROM</span>
  <span style="color: #66cc66;">&#40;</span>
    <span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #993333; font-weight: bold;">DISTINCT</span> customer<span style="color: #66cc66;">.</span>id <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: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> tmptable
<span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>The query is basically the same, except the inner select is wrapped inside another select.  The most important thing to note is that the original select has been given an alias &#8220;<strong>tmptable</strong>&#8220;.  (The name tmptable is arbitrary, you can give it any alias name.)  The alias is important because assigning one will tell MySQL to create a temporary table from this select query.  The temporary table may then be used as the source criteria for the update statement.</p>
<p>The reason it is wrapped inside another query is because MySQL syntax does not let you assign an alias to a select query when it is part of an update statement.  So we have to put it inside another query which, I suppose separates it from the update statement.</p>
<p>The information about creating the temporary table was borrowed from <a href="http://www.xaprb.com/blog/2006/06/23/how-to-select-from-an-update-target-in-mysql/" target="_blank">Xaprb&#8217;s blog</a>, who goes into a little more detail about the mechanics.</p>
]]></content:encoded>
			<wfw:commentRss>http://verysimple.com/2011/03/30/mysql-cant-specify-target-table-for-update-in-from-clause/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Connect to VNC over SSH</title>
		<link>http://verysimple.com/2011/03/27/connect-to-vnc-over-ssh/</link>
		<comments>http://verysimple.com/2011/03/27/connect-to-vnc-over-ssh/#comments</comments>
		<pubDate>Mon, 28 Mar 2011 03:07:11 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[*NIX]]></category>
		<category><![CDATA[Digital Life]]></category>
		<category><![CDATA[OSX]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://verysimple.com/?p=861</guid>
		<description><![CDATA[Connecting to your VNC server over SSH is easily done and you most likely don&#8217;t need any special software to do so. Any system that has SSH installed can connect using an SSH Tunnel. I go into more detail about the concept on a separate post about mounting OSX AFS shares over SSH. First you [...]]]></description>
			<content:encoded><![CDATA[<p>Connecting to your VNC server over SSH is easily done and you most likely don&#8217;t need any special software to do so.  Any system that has SSH installed can connect using an SSH Tunnel.  I go into more detail about the concept on a separate post about <a href="http://verysimple.com/2008/03/09/mount-an-osx-afs-shared-drive-over-ssh/">mounting OSX AFS shares over SSH</a>.</p>
<p>First you need to have a server that is running VNC, but most likely only has it&#8217;s SSH port exposed.  I&#8217;ll assume that SSH is on port 22 and VNC is on port 5900 (these are the default ports for these services).  I&#8217;ll also assume that you have the ssh command and a VNC client installed on your client machine.</p>
<p><span id="more-861"></span>1. On your client machine, open a command line window and enter the following to create the SSH tunnel:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ssh</span> <span style="color: #660033;">-N</span> <span style="color: #660033;">-p</span> <span style="color: #000000;">22</span> USERNAME<span style="color: #000000; font-weight: bold;">@</span>YOURSERVER <span style="color: #660033;">-L</span> <span style="color: #000000;">5901</span><span style="color: #000000; font-weight: bold;">/</span>localhost<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">5900</span></pre></div></div>

<p><em>Replace USERNAME with your server username, and replace YOURSERVER with your server address (ie verysimple.com or 192.168.1.99)</em></p>
<p>2. Once you enter this command you&#8217;ll be prompted for the server password.  Enter the password.  You will see no feedback in the terminal window, but the SSH tunnel is now active.</p>
<p>3. Open your VNC client and connect to the address &#8220;localhost:5901&#8243;  If you have a password set for VNC access then you will need to enter that now.  If all goes well, you should see your server VNC desktop!</p>
<p>It might seem weird that you are connecting to localhost in your VNC client.  But the the SSH tunnel you created is actually routing port 5901 on your localhost to port 5900 on your server.</p>
]]></content:encoded>
			<wfw:commentRss>http://verysimple.com/2011/03/27/connect-to-vnc-over-ssh/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

