<?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>Alex Korn</title>
	<atom:link href="http://www.alexkorn.com/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.alexkorn.com/blog</link>
	<description></description>
	<lastBuildDate>Mon, 05 Mar 2012 15:17:37 +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>Turning off text anti-aliasing with NetBeans 7.1 on OS X</title>
		<link>http://www.alexkorn.com/blog/2012/03/turning-off-text-anti-aliasing-with-netbeans-7-1-on-os-x/</link>
		<comments>http://www.alexkorn.com/blog/2012/03/turning-off-text-anti-aliasing-with-netbeans-7-1-on-os-x/#comments</comments>
		<pubDate>Mon, 05 Mar 2012 15:16:04 +0000</pubDate>
		<dc:creator>Alex Korn</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[fonts]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[netbeans]]></category>

		<guid isPermaLink="false">http://www.alexkorn.com/blog/?p=41</guid>
		<description><![CDATA[Another version of NetBeans, another hack to get it to turn off text anti-aliasing. Previously, I showed how with NetBeans 7.0. NetBeans 7.1.x is nearly the same, but a bit simpler. Just make the following changes to the definition of netbeans_default_options in /Applications/NetBeans/NetBeans\ 7.1.app/Contents/Resources/NetBeans/etc/netbeans.conf (or something similar if you didn&#8217;t install it in the default [...]]]></description>
			<content:encoded><![CDATA[<p>
Another version of NetBeans, another hack to get it to turn off text anti-aliasing. Previously, I <a href="http://www.alexkorn.com/blog/2011/05/turning-off-text-anti-aliasing-with-netbeans-7-on-os-x/">showed how with NetBeans 7.0</a>. NetBeans 7.1.x is nearly the same, but a bit simpler.
</p>
<p>
Just make the following changes to the definition of <code>netbeans_default_options</code> in <code>/Applications/NetBeans/NetBeans\ 7.1.app/Contents/Resources/NetBeans/etc/netbeans.conf</code> (or something similar if you didn&#8217;t install it in the default location):
</p>
<p style="margin-bottom:0;">Add:</p>
<pre>
-J-Dswing.aatext=false
</pre>
<p style="margin-bottom:0;">Change:</p>
<pre>
-J-Dapple.awt.graphics.UseQuartz=false
</pre>
<p>
Restart NetBeans and you should have non-anti-aliased fonts.
</p>
<h2>Notes</h2>
<p>
Note that, unlike NetBeans 7.0, you no longer need to add <code>-J-Dawt.useSystemAAFontSettings=off</code>.
</p>
<p>
See some <a href="http://wiki.netbeans.org/FaqFontRendering#Anti-aliasing_in_NetBeans_7.1">notes about text anti-aliasing on the NetBeans wiki</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alexkorn.com/blog/2012/03/turning-off-text-anti-aliasing-with-netbeans-7-1-on-os-x/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>This is how quickly we give up on resolutions</title>
		<link>http://www.alexkorn.com/blog/2012/01/this-is-how-quickly-we-give-up-on-resolutions/</link>
		<comments>http://www.alexkorn.com/blog/2012/01/this-is-how-quickly-we-give-up-on-resolutions/#comments</comments>
		<pubDate>Mon, 02 Jan 2012 05:11:57 +0000</pubDate>
		<dc:creator>Alex Korn</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.alexkorn.com/blog/?p=35</guid>
		<description><![CDATA[On Facebook today, I noticed one of my friends posted a picture with the label &#8220;1/365&#8243;. Like other people, she&#8217;s attempting to post one picture every day of the year. An admirable goal! This got me thinking: I wonder how long it takes most people to give up on resolutions? Well, the best (read: easiest [...]]]></description>
			<content:encoded><![CDATA[<p>
On Facebook today, I noticed one of my friends posted a picture with the label &#8220;1/365&#8243;. Like other people, she&#8217;s attempting to post one picture every day of the year. An admirable goal!
</p>
<p>
This got me thinking: I wonder how long it takes most people to give up on resolutions? Well, the best (read: easiest and cheapest) way to figure this out is to see how many Google results there are for &#8220;1/365&#8243;, &#8220;2/365&#8243;, etc.
</p>
<p>
This is how quickly we give up on our resolutions<a href="#disclaimer">*</a>:<br />
<a href="http://www.alexkorn.com/blog/wp-content/uploads/2012/01/resolutions2.png"><img src="http://www.alexkorn.com/blog/wp-content/uploads/2012/01/resolutions2.png" alt="" title="Resolutions" width="541" height="430" class="alignnone size-full wp-image-40" /></a>
</p>
<p>
It appears most people give up after the first week, and the vast majority give up after the first month or two. But if they stick with it for the first 10 months or so, they&#8217;re talking about it a lot until the end of the year.
</p>
<h2>The technical details</h2>
<p>
First off, <a href="http://blog.xkcd.com/2011/02/04/trochee-chart/">Google&#8217;s estimates of how many results a query has are grossly exaggerated</a> (<a href="https://twitter.com/#!/Roguelazer/status/153706247294681088">thanks, James</a>). The chart above uses <a href="http://azich.org/google/">Andrew Zich&#8217;s Google Search Matrix</a>.
</p>
<p>
I had to remove some outliers, which I set to be the average of up to 3 days on either side of them.
</p>
<ul>
<li>&#8220;7/365&#8243;: 719k (mostly in the form of &#8220;24/7/365&#8243;)</li>
<li>&#8220;364/365&#8243;: 1.8m (apparently a lot of sites just have numbers in sequence)</li>
</ul>
<p>
Below is the PHP script I used to generate the numbers initially. Note that the Google homepage (and thus the text around the number of results) looks different when you aren&#8217;t logged in.
</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;html&gt;&lt;table&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$matches</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;=</span> <span style="color: #cc66cc;">365</span><span style="color: #339933;">;</span> <span style="color: #339933;">++</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://www.google.com/search?q='</span> <span style="color: #339933;">.</span> <span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/365&quot;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/of about &lt;b&gt;(.*)&lt;\/b&gt; for/'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$result</span><span style="color: #339933;">,</span> <span style="color: #000088;">$matches</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;tr&gt;&lt;td&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/td&gt;&lt;td&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">','</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$matches</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/td&gt;&lt;/tr&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;/table&gt;&lt;/html&gt;'</span><span style="color: #339933;">;</span></pre></div></div>

<p>
Here is the chart created with the numbers that Google estimates on the first page of results:<br />
<a href="http://www.alexkorn.com/blog/wp-content/uploads/2012/01/resolutions.png"><img src="http://www.alexkorn.com/blog/wp-content/uploads/2012/01/resolutions.png" alt="" title="Resolutions" width="642" height="506" class="alignnone size-full wp-image-37" /></a>
</p>
<p>
The general shape of the data is the same, but the actual numbers of results are very different between the two.
</p>
<p><a name="disclaimer"></a></p>
<h2>The disclaimer</h2>
<p>
Oh man, this is so unscientific it almost hurts. Just because someone stops posting about their resolutions doesn&#8217;t mean they&#8217;ve given up. Not everyone who&#8217;s come up with a resolution posts about it online. Etc etc etc. I sacrificed a lot of scientific rigor to come up with a catchy title.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alexkorn.com/blog/2012/01/this-is-how-quickly-we-give-up-on-resolutions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Enable Key Repeat in OS X Lion (10.7)</title>
		<link>http://www.alexkorn.com/blog/2011/07/how-to-enable-key-repeat-in-os-x-lion-10-7/</link>
		<comments>http://www.alexkorn.com/blog/2011/07/how-to-enable-key-repeat-in-os-x-lion-10-7/#comments</comments>
		<pubDate>Fri, 22 Jul 2011 18:48:36 +0000</pubDate>
		<dc:creator>Alex Korn</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[key repeat]]></category>
		<category><![CDATA[lion]]></category>
		<category><![CDATA[os x]]></category>

		<guid isPermaLink="false">http://www.alexkorn.com/blog/?p=28</guid>
		<description><![CDATA[To enable key repeat in Mac OS 10.7 Lion, open up your Console, enter the following line, then restart your computer. defaults write -g ApplePressAndHoldEnabled -bool false The default behavior in 10.7 is to have a special keys selector pop up when holding down a key, similar to the behavior in iOS. This can be [...]]]></description>
			<content:encoded><![CDATA[<p>
To enable key repeat in Mac OS 10.7 Lion, open up your Console, enter the following line, then restart your computer.
</p>
<pre>
defaults write -g ApplePressAndHoldEnabled -bool false
</pre>
<p>
The default behavior in 10.7 is to have a special keys selector pop up when holding down a key, similar to the behavior in iOS. This can be handy for typing accented letters, but makes things like navigating in Vi much more difficult. As of now, there is no way to change this setting in the user interface.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alexkorn.com/blog/2011/07/how-to-enable-key-repeat-in-os-x-lion-10-7/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Turning off text anti-aliasing with NetBeans 7.0 on OS X</title>
		<link>http://www.alexkorn.com/blog/2011/05/turning-off-text-anti-aliasing-with-netbeans-7-on-os-x/</link>
		<comments>http://www.alexkorn.com/blog/2011/05/turning-off-text-anti-aliasing-with-netbeans-7-on-os-x/#comments</comments>
		<pubDate>Mon, 02 May 2011 07:21:39 +0000</pubDate>
		<dc:creator>Alex Korn</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[fonts]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[netbeans]]></category>

		<guid isPermaLink="false">http://www.alexkorn.com/blog/?p=29</guid>
		<description><![CDATA[See the updated post for NetBeans 7.1. The quick version For those who want to turn off text anti-aliasing in NetBeans 7.0.x on Mac OS X without reading my tirades, just make the following changes to the definition of netbeans_default_options in /Applications/NetBeans/NetBeans\ 7.0.app/Contents/Resources/NetBeans/etc/netbeans.conf (or something similar if you didn&#8217;t install it in the default location): [...]]]></description>
			<content:encoded><![CDATA[<p>
<a href="http://www.alexkorn.com/blog/2012/03/turning-off-text-anti-aliasing-with-netbeans-7-1-on-os-x/">See the updated post for NetBeans 7.1</a>.
</p>
<h2>The quick version</h2>
<p>
For those who want to turn off text anti-aliasing in NetBeans 7.0.x on Mac OS X without reading my tirades, just make the following changes to the definition of <code>netbeans_default_options</code> in <code>/Applications/NetBeans/NetBeans\ 7.0.app/Contents/Resources/NetBeans/etc/netbeans.conf</code> (or something similar if you didn&#8217;t install it in the default location):
</p>
<p style="margin-bottom:0;">Add:</p>
<pre>
-J-Dswing.aatext=false -J-Dawt.useSystemAAFontSettings=off
</pre>
<p style="margin-bottom:0;">Change:</p>
<pre>
-J-Dapple.awt.graphics.UseQuartz=false
</pre>
<p>
Restart NetBeans and you should have non-anti-aliased fonts.
</p>
<h2>The full story</h2>
<p>
The perfect programming font: many have searched; few have found.
</p>
<p>
It&#8217;s Monaco, 10pt, no anti-aliasing.
</p>
<p>
But I digress. My goal here is not to discuss fonts (but seriously, I love discussing fonts), but to write the most keyword-heavy post for those trying to figure out how to <em>turn off text anti-aliasing in NetBeans 7 on Mac OS X</em>. By default, NetBeans uses anti-aliasing for its editor, which, for most fonts, is great, but not for Monaco 10pt.
</p>
<p>
When I used NetBeans 6.x, I found <a href="http://ibnaziz.wordpress.com/2009/06/10/netbeans-anti-aliasing/">this page</a> to be quite useful. However, when I tried turning off anti-aliasing with NetBeans 7.0, it did not work.
</p>
<p>
After a bit of exploring, I found the key to be setting <code>-J-Dapple.awt.graphics.UseQuartz=false</code>. I believe Quartz refers to the <a href="http://en.wikipedia.org/wiki/Quartz_2D">2D graphics rendering API for OS X</a>, but for the sake of your non-anti-aliased font, you certainly don&#8217;t need it.
</p>
<h2>In-Application Setting</h2>
<p>
NetBeans has been well aware <a href="http://netbeans.org/bugzilla/show_bug.cgi?id=144715">of</a> <a href="http://netbeans.org/bugzilla/show_bug.cgi?id=144516">the</a> <a href="http://netbeans.org/bugzilla/show_bug.cgi?id=79453">issue</a> for quite some time, so don&#8217;t expect the anti-aliasing setting to be modifiable inside the application any time soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alexkorn.com/blog/2011/05/turning-off-text-anti-aliasing-with-netbeans-7-on-os-x/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Sending email from AWS in PHP with AmazonSES</title>
		<link>http://www.alexkorn.com/blog/2011/04/sending-email-aws-php-with-amazonses/</link>
		<comments>http://www.alexkorn.com/blog/2011/04/sending-email-aws-php-with-amazonses/#comments</comments>
		<pubDate>Thu, 28 Apr 2011 16:47:59 +0000</pubDate>
		<dc:creator>Alex Korn</dc:creator>
				<category><![CDATA[AWS]]></category>
		<category><![CDATA[Hosting]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.alexkorn.com/blog/?p=27</guid>
		<description><![CDATA[For those who have sent emails in PHP, the following code should look quite familiar: mail&#40;$to, $subject, $message&#41;; Unfortunately, this will silently fail on Amazon Web Services. But you do need to send those emails, right? Well, it&#8217;s pretty easy to get emails sent from AWS with Amazon Simple Email Service (Amazon SES). However, in [...]]]></description>
			<content:encoded><![CDATA[<p>
For those who have sent emails in <a href="http://www.php.net/">PHP</a>, the following code should look quite familiar:
</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">mail</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$to</span><span style="color: #339933;">,</span> <span style="color: #000088;">$subject</span><span style="color: #339933;">,</span> <span style="color: #000088;">$message</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>
Unfortunately, this will silently fail on <a href="http://aws.amazon.com/">Amazon Web Services</a>. But you do need to send those emails, right? Well, it&#8217;s pretty easy to get emails sent from AWS with <a href="http://aws.amazon.com/ses/">Amazon Simple Email Service (Amazon SES)</a>. However, in my research on this, I found several false leads and no good tutorials, so here goes: step by step, how to send emails with AWS.</p>
<p>First step: <a href="http://aws-portal.amazon.com/gp/aws/developer/subscription/index.html?ie=UTF8&#038;productCode=AmazonSES">sign up</a>.
</p>
<h2>AWS SDK for PHP</h2>
<p>
Next, install the source code code for <a href="https://github.com/amazonwebservices/aws-sdk-for-php">AWS SDK for PHP</a>. Run the following in the directory where you store external libraries (using <code>sudo</code> when needed):
</p>
<pre>
yum install git
git clone git://github.com/amazonwebservices/aws-sdk-for-php.git AWSSDKforPHP
</pre>
<p>
Now that you have the the AWS SDK on your server, include <code> AWSSDKforPHP/sdk.class.php</code> into your application. You now have access to the <code>AmazonSES</code> class.
</p>
<p>The following is a basic function to emulate PHP&#8217;s <code>mail()</code>.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> amazonSesEmail<span style="color: #009900;">&#40;</span><span style="color: #000088;">$to</span><span style="color: #339933;">,</span> <span style="color: #000088;">$subject</span><span style="color: #339933;">,</span> <span style="color: #000088;">$message</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$amazonSes</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> AmazonSES<span style="color: #009900;">&#40;</span>AWS_KEY<span style="color: #339933;">,</span> AWS_SECRET_KEY<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$response</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$amazonSes</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">send_email</span><span style="color: #009900;">&#40;</span>AWS_SES_FROM_EMAIL<span style="color: #339933;">,</span>
        <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ToAddresses'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$to</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
        <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
            <span style="color: #0000ff;">'Subject.Data'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$subject</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'Body.Text.Data'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$message</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$response</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isOK</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// handle error</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>
Note that you need to define the AWS_KEY and AWS_SECRET_KEY for your application. You can find these by going to your <a href="https://aws-portal.amazon.com/gp/aws/developer/account/index.html?ie=UTF8&#038;action=access-key">AWS Security Credentials page</a> and looking under &#8220;Access Keys&#8221;.
</p>
<h2>Validating the sending email address</h2>
<p><a name="backtoperlmodulesasterisk"></a></p>
<p>
Next, define <code>AWS_SES_FROM_EMAIL</code> to be the email address from which you want to send emails, e.g. <code>no-reply@example.com</code>. If you try to send an email at this point, you&#8217;ll get a <code>MessageRejected</code> error with the message &#8220;Email address is not verified.&#8221; Several pages I visited recommended I download the <a href="http://aws.amazon.com/code/Amazon-SES/8945574369528337">Amazon SES Scripts</a> (Perl), but don&#8217;t do it! You&#8217;ll need to subject yourself to a world of pain in the form of installing Perl modules<a href="#perlmodules">*</a> (and probably Perl too, given that you&#8217;re reading a post on PHP!).
</p>
<p>
Instead, you can actually use <code>AmazonSES</code> to verify email addresses in PHP.
</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$amazonSes</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> AmazonSES<span style="color: #009900;">&#40;</span>AWS_KEY<span style="color: #339933;">,</span> AWS_SECRET_KEY<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$amazonSes</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">verify_email_address</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fromEmailAddress</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>
Much easier than the Perl script shenanigans. This will send an email to your sending email address with a link to verify that you own that email address. Do the same for your recipient addresses (since you&#8217;re in <a href="http://aws.amazon.com/ses/faqs/#9">sandbox mode, which has restrictions</a> including the requirement to validate your recipient address). Verify each address and you should be good to go to send emails.
</p>
<h2>Setting up production access</h2>
<p>
At this point you&#8217;ll be able to send a couple test emails, but the volume is fairly limited. <a href="https://aws-portal.amazon.com/gp/aws/html-forms-controller/contactus/SESAccessRequest">Request production access</a> and you should be granted the ability to send many more emails.
</p>
<hr />
<h2>Reference</h2>
<p>
Visit the <a href="http://docs.amazonwebservices.com/AWSSDKforPHP/latest/index.html">AWS SDK for PHP reference page</a> for much more information on how AWS SDK for PHP works.
</p>
<p><a name="perlmodules"></a></p>
<h2>Amazon SES Scripts (Perl)</h2>
<p>
If you do want to install the <a href="http://aws.amazon.com/code/Amazon-SES/8945574369528337">Amazon SES Perl scripts</a> and are getting an error along the lines of &#8220;Can&#8217;t locate XML/LibXML.pm in @INC&#8230;&#8221;, you can use <code>yum</code> to install all of the necessary packages to get them to run.
</p>
<pre>
yum -y install perl-Digest-SHA perl-URI perl-libwww-perl perl-MIME-tools perl-Crypt-SSLeay perl-XML-LibXML
</pre>
<p>
Thanks to <a href="https://forums.aws.amazon.com/thread.jspa?messageID=219753#219753">this post</a> for that hint.
</p>
<p style="font-size:x-small;">
(<a href="#backtoperlmodulesasterisk">^ Back up</a>)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alexkorn.com/blog/2011/04/sending-email-aws-php-with-amazonses/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Ridiculously Simple Observer Pattern with PHP 5.3 and Closures</title>
		<link>http://www.alexkorn.com/blog/2011/03/observer-pattern-with-php-5-3-and-closures/</link>
		<comments>http://www.alexkorn.com/blog/2011/03/observer-pattern-with-php-5-3-and-closures/#comments</comments>
		<pubDate>Fri, 25 Mar 2011 21:00:14 +0000</pubDate>
		<dc:creator>Alex Korn</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[design patterns]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.alexkorn.com/blog/?p=24</guid>
		<description><![CDATA[The observer pattern is a handy design pattern often used in UI-focused languages like JavaScript, but not often used in PHP. Prior to PHP 5.3, the observer pattern was cumbersome to use and required a lot of objects &#8211; one for every possible observer. However, anonymous functions (Closures) in PHP 5.3 can replace the previously [...]]]></description>
			<content:encoded><![CDATA[<p>
The <a href="http://en.wikipedia.org/wiki/Observer_pattern">observer pattern</a> is a handy design pattern often used in UI-focused languages like JavaScript, but not often used in PHP. Prior to PHP 5.3, the observer pattern was cumbersome to use and required a lot of objects &#8211; one for every possible <em>observer</em>. However, <a href="http://php.net/manual/en/functions.anonymous.php">anonymous functions</a> (<code>Closures</code>) in PHP 5.3 can replace the previously used Observer objects. This makes the observer pattern much more practical by reducing the number of classes that you need to make, often for one-time use.
</p>
<p>
Let&#8217;s write up our basic Observable object. You may want to make this class abstract since it&#8217;s probably not useful on its own.
</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Observable
<span style="color: #009900;">&#123;</span>
    <span style="color: #009933; font-style: italic;">/**
     * @var array Map&lt;string eventName, List&lt;Closure observer&gt;&gt; $_observers
     */</span>
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$_observers</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * @param string $eventName
     * @param array $data
     */</span>
    <span style="color: #000000; font-weight: bold;">protected</span> final <span style="color: #000000; font-weight: bold;">function</span> _fireEvent<span style="color: #009900;">&#40;</span><span style="color: #000088;">$eventName</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span> <span style="color: #000088;">$data</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;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_observers<span style="color: #009900;">&#91;</span><span style="color: #000088;">$eventName</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_observers<span style="color: #009900;">&#91;</span><span style="color: #000088;">$eventName</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$observer</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$observer</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * @param string $eventName
     * @param Closure $observer With parameter (array $data)
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> final <span style="color: #000000; font-weight: bold;">function</span> addObserver<span style="color: #009900;">&#40;</span><span style="color: #000088;">$eventName</span><span style="color: #339933;">,</span> Closure <span style="color: #000088;">$observer</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_observers<span style="color: #009900;">&#91;</span><span style="color: #000088;">$eventName</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_observers<span style="color: #009900;">&#91;</span><span style="color: #000088;">$eventName</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_observers<span style="color: #009900;">&#91;</span><span style="color: #000088;">$eventName</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$observer</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * @param string $eventName
     * @param Closure $observer The observer to remove
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> final <span style="color: #000000; font-weight: bold;">function</span> removeObserver<span style="color: #009900;">&#40;</span><span style="color: #000088;">$eventName</span><span style="color: #339933;">,</span> Closure <span style="color: #000088;">$observer</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_observers<span style="color: #009900;">&#91;</span><span style="color: #000088;">$eventName</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_observers<span style="color: #009900;">&#91;</span><span style="color: #000088;">$eventName</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$existingObserver</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$existingObserver</span> <span style="color: #339933;">===</span> <span style="color: #000088;">$observer</span><span style="color: #009900;">&#41;</span>
                <span style="color: #009900;">&#123;</span>
                    <span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_observers<span style="color: #009900;">&#91;</span><span style="color: #000088;">$eventName</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>
Now that we have the basic observable class, let&#8217;s look at a simple example:
</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Person <span style="color: #000000; font-weight: bold;">extends</span> Observable
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$_name</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$_friends</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_name <span style="color: #339933;">=</span> <span style="color: #000088;">$name</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_name<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getIntroducedTo<span style="color: #009900;">&#40;</span>Person <span style="color: #000088;">$person</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_friends<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$person</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_fireEvent<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'introduced'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'other'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$person</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'me'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$this</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$sally</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Person<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Sally'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$sally</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addObserver</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'introduced'</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Hi, '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'other'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">', my name is '</span> <span style="color: #339933;">.</span>
            <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'me'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'.'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$sally</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getIntroducedTo</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Person<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Harry'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>
The output will be <code>"Hi, Harry, my name is Sally."</code>. Note that you can easy modify the greeting Sally uses from outside that <code>Person</code> object without changing the functionality of adding the friend.
</p>
<p>
And there you have it &#8211; the observer pattern and an example, in less than 75 lines of code!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alexkorn.com/blog/2011/03/observer-pattern-with-php-5-3-and-closures/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting PHP and MySQL running on Amazon EC2</title>
		<link>http://www.alexkorn.com/blog/2011/03/getting-php-mysql-running-amazon-ec2/</link>
		<comments>http://www.alexkorn.com/blog/2011/03/getting-php-mysql-running-amazon-ec2/#comments</comments>
		<pubDate>Thu, 17 Mar 2011 19:38:50 +0000</pubDate>
		<dc:creator>Alex Korn</dc:creator>
				<category><![CDATA[AWS]]></category>
		<category><![CDATA[Hosting]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[amazon]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[ec2]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.alexkorn.com/blog/?p=22</guid>
		<description><![CDATA[Do you know nothing about Amazon Web Services (AWS) or Linux server administration, but want to get a PHP/MySQL server set up on AWS? I was once like you, relying upon my web host to have PHP and MySQL installed and configured, so it was a bit daunting initially to work with AWS, but it&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>
Do you know nothing about Amazon Web Services (AWS) or Linux server administration, but want to get a PHP/MySQL server set up on AWS? I was once like you, relying upon my web host to have PHP and MySQL installed and configured, so it was a bit daunting initially to work with AWS, but it&#8217;s actually rather simple. Read on and I&#8217;ll show you how to set up PHP and MySQL on one of <a href="http://aws.amazon.com/free/">Amazon&#8217;s free servers</a> step by step. You can have a functioning site up and running within half an hour.
</p>
<h2>Amazon Web Services</h2>
<p>
First things first: Amazon Web Services has a ton of different products, but the one you want is <a href="http://aws.amazon.com/ec2/">Amazon Elastic Compute Cloud</a> (<em>EC2</em>). Go there, and click &#8220;Sign Up for Amazon EC2&#8243;.
</p>
<p>
Once you&#8217;ve gotten that set up, go to the <a href="https://console.aws.amazon.com/ec2/"><em>AWS Management Console</em></a>, and click on &#8220;Instances&#8221; in the Navigation panel. An <em>Instance</em> is just a virtual server &#8211; so let&#8217;s create one! Click &#8220;Launch Instance&#8221; under &#8220;My Instances&#8221;, and select &#8220;Basic 64-bit Amazon Linux AMI&#8221;. On the <em>Instance Details</em> phase, select &#8220;Micro&#8221; (which is Free tier eligible). Continue until you need to enter the &#8220;Name&#8221; &#8211; if you don&#8217;t know what else to call it, just use &#8220;Web/DB server&#8221;.
</p>
<p>
Next you create a <em>Key Pair</em> &#8211; this will be the credentials you&#8217;ll use to SSH into the box. The instructions here should be fairly straightforward. Next is the <em>Security Group</em>, which will be used to specify the firewall used for your instance. Feel free to use the default Group for now. Continue to the <em>Review</em> phase and launch it!
</p>
<p>
You should now be able to SSH into your instance using your .pem file with <code>ssh -i [FILE NAME].pem ec2-user@ec2-[IP ADDRESS].compute-1.amazonaws.com</code>. Alright, we&#8217;ve got a server up and running! However, you may notice that this server has very little installed on it. <code>which php</code>? Nothing. <code>which mysql</code>? The same. Let&#8217;s install some software.
</p>
<h2>Configuring the Linux Server</h2>
<p>
Below I&#8217;ll show you how to set up PHP and MySQL on the server. I&#8217;ve separated PHP and MySQL so that it&#8217;s easier to adapt this to having <a href="#twoInstances">two instances</a>.
</p>
<h3>PHP</h3>
<p>
First, the basics for PHP:
</p>
<pre>
sudo yum install php-mysql php php-xml php-mcrypt php-mbstring php-cli mysql httpd
</pre>
<p>
Press &#8216;y&#8217; for each of the prompts that shows up. Note that you&#8217;re logged in as ec2-user, so you need to <em>sudo</em> all of these commands.
</p>
<p>
You should now be able to create and run a PHP test file. Next, let&#8217;s get MySQL up and running.
</p>
<h3>MySQL server</h3>
<p>
First, install and begin running the server:
</p>
<pre>
sudo yum install mysql-server
sudo /etc/init.d/mysqld start
</pre>
<p>
Next, set the root password. I&#8217;ve found <a href="https://www.grc.com/passwords.htm">this password generator</a> to be just dandy.
</p>
<pre>
mysqladmin -u root password '[PASSWORD]'
</pre>
<p>
Now we set up two users for MySQL: the administrator, which you&#8217;ll use to create and modify tables; and the app user, which the app will use to query the DB (with more limited privileges). Log into MySQL as <code>root</code> (<code>mysql -u root -p</code>) and enter each of the following lines:
</p>
<pre>
CREATE DATABASE [DB NAME];
CREATE USER '[DB NAME]_admin'@'localhost' IDENTIFIED BY '[ADMIN PASSWORD]';
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, ALTER ON [DB NAME].* TO '[DB NAME]_admin'@'localhost';
CREATE USER '[DB NAME]_user'@'localhost' IDENTIFIED BY '[USER PASSWORD]';
GRANT SELECT, INSERT, UPDATE, DELETE ON [DB NAME].* TO '[DB NAME]_user'@'localhost';
</pre>
<p>
You may want to fine-tune your database settings further than this, but this is a good start.
</p>
<h2>Make it web-accessible</h2>
<p>
We now have PHP and MySQL running on the box, but cannot access it through a browser. We need to configure the web server and set up an <em>Elastic IP</em>.
</p>
<h3>Web Server</h3>
<p>
First, let&#8217;s create a test PHP file that will be accessed by the browser. Create directories so that you can put your file in <code>/opt/app/current</code><sup><a name="note1back" href="#note1">1</a></sup>. Make an <code>index.php</code> file that contains whatever you want.
</p>
<p>
If you want to FTP transfer files to your server, you&#8217;ll want to give the ec2-user permissions to modify files in your web directory:
</p>
<pre>sudo chown ec2-user /opt/app/current</pre>
<p>
To set up the web server, <em>httpd</em>, we need to first modify its configuration file, located at <code>/etc/httpd/conf/httpd.conf</code>. Open it up with <code>vim</code>, <code>emacs</code>, or your favorite text editor, and go to the bottom of the file. Here you&#8217;ll see a small section on the <em>VirtualHost</em> (between <code>&lt;VirtualHost *:80&gt;</code> and <code>&lt;/VirtualHost&gt;</code>). Uncomment it out and set DocumentRoot to <code>/opt/app/current</code>. Restart (or start) <code>httpd</code>:
</p>
<pre>
sudo /etc/init.d/httpd restart
</pre>
<h3><em>Elastic IP</em> and <em>Security Groups</em></h3>
<p>
In the <em>AWS Management Console</em>, click on &#8220;Elastic IPs&#8221;, then &#8220;Allocate New Address&#8221; under &#8220;Addresses&#8221;. Once the address is created, click on it, then &#8220;Associate Address&#8221;. Select the instance and associate it.
</p>
<p>
Now click on &#8220;Security Groups&#8221; in the Navigation panel. Select the <em>Security Group</em> that you used for the instance (probably the default one). Under the &#8220;Inbound&#8221; tab, add an HTTP rule (port 80). Click &#8220;Apply Rule Changes&#8221;, and you should now be able to access your website! In your browser, go to <code>http://ec2-[IP ADDRESS].compute-1.amazonaws.com/</code>, where the IP address is the <em>Elastic IP</em> you made with periods replaced with hyphens.
</p>
<h2>Hello World! <span style="font-style:italic;">or</span> Putting it all together</h2>
<p>
We now have all the pieces we need to access MySQL from PHP and serve that to the browser-accessible website. So let&#8217;s log into <code>mysql</code> and create a sample table:
</p>
<pre>
mysql -u [DB NAME]_admin -p
[type password]
mysql> use [DB NAME];
mysql> CREATE TABLE test (message VARCHAR(255));
mysql> INSERT INTO test (message) VALUES ('Hello world!');
</pre>
<p>
Now modify your index.php file (<code>/opt/app/current/index.php</code>) to be the following:
</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$conn</span> <span style="color: #339933;">=</span>  <span style="color: #000000; font-weight: bold;">new</span> mysqli<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'localhost'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'[DB NAME]_user'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'[USER PASSWORD]'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'[DB NAME]'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$conn</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT message FROM test;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$result</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetch_assoc</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'message'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>
We now have a fully functioning PHP and MySQL server!
</p>
<h2>Taking it further</h2>
<p>
That&#8217;s it for the basics, but there&#8217;s so much more that you can do now.
</p>
<h3><a href="http://www.phpunit.de/">PHPUnit</a></h3>
<pre>
sudo pear upgrade
sudo yum install php-pear
sudo pear channel-discover pear.phpunit.de
sudo pear channel-discover pear.symfony-project.com
sudo pear channel-discover components.ez.no
sudo pear install phpunit/PHPUnit
</pre>
<h3><a href="http://www.phpmyadmin.net/">phpMyAdmin</a></h3>
<p>
I&#8217;ve found it handy to set up an administration area for my sites using a different port on the same URL. Note that port 80 is the default for web traffic, but 8080 is also commonly used.
</p>
<p>
Create <code>/opt/app/admin</code>. Then, in <em>httpd.conf</em>, add the line <code>Listen 8080</code> after <code>Listen 80</code> and add another <em>VirtualHost</em> entry, using <code>&lt;VirtualHost *:8080&gt;</code> and pointing to the <code>/opt/app/admin</code> directory. Update your <em>Security Group</em> to allow traffic over port 8080. Make sure to restart Apache and you should now be able to access your <em>admin</em> folder through your browser at <code>yourdomain.com:8080</code>.
</p>
<p>
You can then download phpMyAdmin into <code>/opt/app/admin/pma</code> and unzip it. Using the <code>[DB NAME]_admin</code> user, you can now manage your databases there through your browser.
</p>
<p><a name="twoInstances"></a></p>
<h3>Using two <em>Instances</em></h3>
<p>
It can be very beneficial to performance to separate the web server and the DB server. To do this, you&#8217;ll need to set up two <em>Instances</em>, one of which has the web server <code>httpd</code> running and an <em>Elastic IP</em>, and the other of which has the MySQL server <code>mysqld</code> running.
</p>
<p>
They can use the same <em>Security Group</em>, but you&#8217;ll have to add the MySQL rule (port 3066) for Inbound traffic to allow the servers to talk to each other.
</p>
<p>
On the web box, instead of using &#8220;localhost&#8221; as the MySQL host, use the Internal IP address of the MySQL box. On the DB box, set up your <em>grant</em> permissions to allow from anywhere in <code>'%.ec2.internal'</code> (or just from your IPs).
</p>
<h2>Notes</h2>
<p><a name="note1"></a></p>
<ol>
<li>
<p>
<code>/opt/app/current</code> is a Rails convention that I enjoy. What you should do is put your releases in <code>/opt/app/releases/[release #]</code>, then have <code>/opt/app/current</code> be a <a href="http://en.wikipedia.org/wiki/Symbolic_link"><code>symlink</code></a> to the current release.
</p>
<p>
Another (much more) common standard is to put web-accessible code in <code>/var/www/html</code>. Feel free to put your HTML code wherever you want; just make sure to update <code>httpd.conf</code> appropriately (and restart Apache).
</p>
<p><a href="#note1back">^ Back up</a></p>
</li>
</ol>
<hr />
<p>
Thanks to <a href="http://www.twitter.com/rausanka">Ryan Ausanka-Crues</a> at <a href="http://www.palominolabs.com/">Palomino Labs</a> for help with this.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alexkorn.com/blog/2011/03/getting-php-mysql-running-amazon-ec2/feed/</wfw:commentRss>
		<slash:comments>29</slash:comments>
		</item>
		<item>
		<title>How to fully maximize Chrome windows in OS X</title>
		<link>http://www.alexkorn.com/blog/2010/07/maximize-chrome-in-os-x/</link>
		<comments>http://www.alexkorn.com/blog/2010/07/maximize-chrome-in-os-x/#comments</comments>
		<pubDate>Thu, 01 Jul 2010 07:03:27 +0000</pubDate>
		<dc:creator>Alex Korn</dc:creator>
				<category><![CDATA[Browsers]]></category>
		<category><![CDATA[Google Chrome]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[WTF]]></category>

		<guid isPermaLink="false">http://www.alexkorn.com/blog/?p=12</guid>
		<description><![CDATA[I, along with many of my friends and coworkers, have run into issues with maximizing Google Chrome windows on Mac OS X. It seems that, when clicking on the green button in the title bar, that the window resizes vertically, but not horizontally. And when you&#8217;re actually trying to get the window to fill up [...]]]></description>
			<content:encoded><![CDATA[<p>
I, along with many of my friends and coworkers, have run into issues with maximizing Google Chrome windows on Mac OS X.  It seems that, when clicking on the green button in the title bar, that the window resizes vertically, but not horizontally.  And when you&#8217;re actually trying to get the window to fill up the full screen, this is highly unfortunate.
</p>
<h2>What&#8217;s going on</h2>
<p>
The green button is not the <em>Maximize</em> button in OS X; it&#8217;s the <em>Zoom</em> button.  As described <a href="http://code.google.com/p/chromium/issues/detail?id=14185#c2">in Chrome&#8217;s issues tracker</a>, Chrome&#8217;s intended behavior for this button is to &#8220;size-to-best-fit, not fill-screen&#8221;.  Therefore, it will only make the window wider if there is some visible content on the page that&#8217;s wider than the window is currently, i.e., if there&#8217;s a horizontal scrollbar.  <a href="http://maximizechrome.com/">This page</a> shows it quite wonderfully: there&#8217;s a 65k-pixel-wide <code>div</code> at the bottom that will make the window expand to the full screen size when you Zoom.  Hide the <code>div</code>, and the window will only expand vertically.
</p>
<h2>How to make Zoom fill the full screen</h2>
<p>
Despite this somewhat unexpected default behavior, there are a couple ways to fill the screen anyway when Zooming:
</p>
<ul>
<li>
Press Shift when you click on the Zoom button.  This, as implemented by Chrome, will make the window fill the full screen.
</li>
<li>
This one has some subtlety: Under System Preferences->Keyboard->Keyboard Shortcuts->Application Shortcuts, add a shortcut for Chrome.  Make the Menu Title be &#8220;Zoom&#8221; (it&#8217;s under the Window menu).  Since Command+M is the keyboard shortcut for Minimize, let&#8217;s make the Keyboard Shortcut for Zoom be Command+Shift+M.  Go back to Chrome and try it out your keyboard shortcut.  Voila!  But wait&#8211;if you just click on Zoom in the menu, it will continue to resize only vertically.  What&#8217;s going on here?  Because you&#8217;re pressing Shift while activating Zoom with the keyboard shortcut, it works just like pressing Shift while clicking the green button.  No joke.
</li>
</ul>
<hr />
<p>Versions and such:</p>
<ul>
<li>Chrome version: 5.0.375.86</li>
<li>OS X version: 10.6.4</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.alexkorn.com/blog/2010/07/maximize-chrome-in-os-x/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to recover deleted JavaScript files using the cache in Chrome or Firefox</title>
		<link>http://www.alexkorn.com/blog/2010/05/how-to-recover-deleted-javascript-files-using-the-cache-in-chrome-or-firefo/</link>
		<comments>http://www.alexkorn.com/blog/2010/05/how-to-recover-deleted-javascript-files-using-the-cache-in-chrome-or-firefo/#comments</comments>
		<pubDate>Thu, 20 May 2010 03:42:06 +0000</pubDate>
		<dc:creator>Alex Korn</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Google Chrome]]></category>
		<category><![CDATA[Holmes]]></category>
		<category><![CDATA[Mozilla Firefox]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.alexkorn.com/blog/?p=3</guid>
		<description><![CDATA[How to recover a deleted JavaScript file using Chrome's or Firefox's cache and some regular expressions.]]></description>
			<content:encoded><![CDATA[<p>So you&#8217;ve been writing some JavaScript files (or HTML files or images) and testing them in Google Chrome or Mozilla Firefox.  Unfortunately, you&#8217;ve deleted the JavaScript files, forgot to check them into the repository, didn&#8217;t make a backup, and they&#8217;re gone.  Don&#8217;t fear!  There is still hope!</p>
<p>Your missing file is stored in your browser&#8217;s cache, which can be accessed by typing <code>about:cache</code> into the URL box in Chrome or <code>about:cache?device=disk</code> in Firefox.  This will list links to every file in your cache (and thus may take a moment to open).  Individual files can be accessed by going to <code>chrome://net-internals/view-cache/[[URL]]</code> in Chrome or <code>about:cache-entry?client=HTTP&#038;sb=1&#038;key=[[URL]]</code> in Firefox.</p>
<p>The cached version will look like the following in Chrome:</p>
<pre>
[[URL]]
<hr />HTTP/1.1 200 OK
Date: Wed, 19 May 2010 15:17:36 GMT
Server: Apache
Last-Modified: Wed, 19 May 2010 15:13:53 GMT
ETag: "18aa1e6-1761-486f3e7ebae40"
Accept-Ranges: bytes
Content-Length: 5985
Content-Type: application/javascript
<hr />00000000:  fb  00  00  00  01  00  00  00  34  62  bc  3d  8a  e5  2d  00  ........4b.=..-.
00000010:  ef  1a  be  3d  8a  e5  2d  00  e3  00  00  00  48  54  54  50  ...=..-.....HTTP
00000020:  2f  31  2e  31  20  32  30  30  20  4f  4b  00  44  61  74  65  /1.1 200 OK.Date
00000030:  3a  20  57  65  64  2c  20  31  39  20  4d  61  79  20  32  30  : Wed, 19 May 20
00000040:  31  30  20  31  35  3a  31  37  3a  33  36  20  47  4d  54  00  10 15:17:36 GMT.
00000050:  53  65  72  76  65  72  3a  20  41  70  61  63  68  65  00  4c  Server: Apache.L
00000060:  61  73  74  2d  4d  6f  64  69  66  69  65  64  3a  20  57  65  ast-Modified: We
00000070:  64  2c  20  31  39  20  4d  61  79  20  32  30  31  30  20  31  d, 19 May 2010 1
00000080:  35  3a  31  33  3a  35  33  20  47  4d  54  00  45  54  61  67  5:13:53 GMT.ETag
00000090:  3a  20  22  31  38  61  61  31  65  36  2d  31  37  36  31  2d  : "18aa1e6-1761-
000000a0:  34  38  36  66  33  65  37  65  62  61  65  34  30  22  00  41  486f3e7ebae40".A
000000b0:  63  63  65  70  74  2d  52  61  6e  67  65  73  3a  20  62  79  ccept-Ranges: by
000000c0:  74  65  73  00  43  6f  6e  74  65  6e  74  2d  4c  65  6e  67  tes.Content-Leng
000000d0:  74  68  3a  20  35  39  38  35  00  43  6f  6e  74  65  6e  74  th: 5985.Content
000000e0:  2d  54  79  70  65  3a  20  61  70  70  6c  69  63  61  74  69  -Type: applicati
000000f0:  6f  6e  2f  6a  61  76  61  73  63  72  69  70  74  00  00      on/javascript..
<hr />00000000:  2f  2a  2a  0a  20  2a  20  40  61  75  74  68  6f  72  20  41  /**. * @author A
00000010:  6c  65  78  20  4b  6f  72  6e  20  3c  61  6c  65  78  6b  6f  lex Korn &lt;alexko
<div style="display:block;text-align:center;">...</div>
</pre>
<p>The last section (in both browsers) displays the hexadecimal representation and the text of your file.  The last column of this section displays newline characters as periods in many text editors, so we can&#8217;t use it to recover the file.  We&#8217;ll have to use the hexadecimal.  I wrote the following PHP script, which will extract and convert the hexadecimal representation into the text version:</p>
<pre>
&lt;?php
$cacheString = ''; // COPY THE LAST SECTION IN HERE (Use /'/\\\'/g to escape quotation marks)

$matches = array();
preg_match_all('/\s[0-9a-f]{2}\s/', $cacheString, $matches);
foreach ($matches[0] as $match)
{
    echo chr(hexdec($match));
}
?&gt;
</pre>
<p>Voil&agrave;!  Your once-lost code is now found!</p>
<hr />
<p>A couple notes:</p>
<ul>
<li>If your server has compression enabled (such as gzip), you&#8217;ll have to go through the extra step of unzipping the content</li>
<li>Chrome version: 5.0.375.38 beta</li>
<li>Firefox version: 3.6.3</li>
</ul>
<hr />
<p>
<strong>Update 2011/05/14</strong>: I changed the \b&#8217;s in the RegEx to \s&#8217;s as recommended in <a href="http://www.frozax.com/blog/2011/05/recover-file-google-chrome-cache-gzipped/">this post on recovering gzipped files</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alexkorn.com/blog/2010/05/how-to-recover-deleted-javascript-files-using-the-cache-in-chrome-or-firefo/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

