<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Aaron Saray</title>
	
	<link>http://aaronsaray.com/blog</link>
	<description>Blog</description>
	<lastBuildDate>Fri, 05 Mar 2010 14:45:08 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/aaronsaray" /><feedburner:info uri="aaronsaray" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><image><link>http://aaronsaray.com</link><url>http://assets.aaronsaray.com/images/logo.png</url><title>Aaron Saray</title></image><feedburner:emailServiceId>aaronsaray</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><item>
		<title>Aaron on NDAs</title>
		<link>http://feedproxy.google.com/~r/aaronsaray/~3/Hi9uOKh0u_Q/</link>
		<comments>http://aaronsaray.com/blog/2010/03/05/aaron-on-ndas/#comments</comments>
		<pubDate>Fri, 05 Mar 2010 14:45:08 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[business]]></category>

		<guid isPermaLink="false">http://aaronsaray.com/blog/?p=585</guid>
		<description><![CDATA[From time to time, I get approached with a new project from an excited business person.  They are just bursting to tell me all about it, to see if I can help them out (or even make it for them), and looking for some clarification on their next steps.  This inevitably is hindered [...]<p><a href="http://aaronsaray.com/blog">Original Content - Aaron Saray</a></p>
]]></description>
			<content:encoded><![CDATA[<p>From time to time, I get approached with a new project from an excited business person.  They are just bursting to tell me all about it, to see if I can help them out (or even make it for them), and looking for some clarification on their next steps.  This inevitably is hindered by my reluctance to answer their first email.  You know that email.  The one that includes the attached Non Disclosure Agreement.</p>
<h2>Why the Entrepreneur Thinks They Need It</h2>
<p>Hey &#8211; it&#8217;s your baby, I understand.  You were watching the market, saw a need, and put together your thoughts.  You spawned this idea, mulled it around, and started coming up with a plan.  You put a lot of yourself into this idea and you don&#8217;t want anyone to steal this from you.  People who come up with new business ideas want to protect this intellectual process and product.  Once again, I understand that.  Your idea is amazing and you&#8217;re afraid that someone (like me??) will steal it.  I&#8217;m sorry, but let me burst your bubble:</p>
<p><strong>No one cares.</strong></p>
<h2>Ideas are Easy</h2>
<p>No one wants to hear that their ideas don&#8217;t matter.  It&#8217;s hurtful to one&#8217;s ego.  But it&#8217;s the truth.  Chances are you&#8217;ve worked under a boss before.  You came up with a great idea and brought it up the chain.  Finally, someone said &#8220;that&#8217;s great, but show me it in practice.&#8221;  You were sent back to your hideaway to actually implement the idea.  And that&#8217;s the key point here.</p>
<h2>Implementation is Key</h2>
<p>People are scared.  Implementation is scary.  This may mean loans, taking risks, and failure.  Lots of failure.  This is where the real value is.  Once you have your idea solidified, you move forward with gathering resources to implement this.  You still have an agile business so you can move into any niche and explore any market while planning your implementation.  </p>
<p>When is this less the case?  Giant, giant corporations.  These are guys who have no wiggle room, their market is heavily saturated, and they have the resources to implement anything their heart desires.  Think Insurance companies, auto mobile makers, grocery stores.  This is where that idea becomes valuable.  For the 99% of us left, however, it&#8217;s the implementation.</p>
<h2>It&#8217;s Legal</h2>
<p>First of all, there is not a lot of successful court cases where the NDA was upheld.  After doing a quick court search, you can verify this yourself.  To top it off, the cost you incur getting your lawyer all over this case (most likely while the other side ignores you), can be very detrimental to your overall business growth.  Basically, you&#8217;ll probably bankrupt your business at a chance that you won&#8217;t win.  Scroll up &#8211; it&#8217;s all about implementation.  </p>
<p>Second, it is a legal document.  I am not going to sign a legal document without a lawyer.  The only way I can balance my cost in this is to charge you to deliver a quote.  Cool?  Probably not.</p>
<p>Finally, do you know what you&#8217;re asking?  For the most part, the NDAs I&#8217;ve seen have been way too overarching.  They&#8217;ve attempted to take away rights that I have for my own products, thoughts and services that are not used to implement your product.  They also attempt to limit the knowledge that I submit to the general public in direct contrast to the license that we must agree with to use some open source products.  (This means, some products I will use to implement your idea have a license that requires any modification I do to them needs to be submitted back to the community.)</p>
<h2>What Does This Mean?</h2>
<p>I&#8217;m taking a bold step:</p>
<p><strong>I will not sign the NDA.</strong></p>
<p>With all of this background information, let me give you my reasons:</p>
<ul>
<li>Idea vs implementation.  You will be successful by your implementation.  Ideas are easy.  If you don&#8217;t believe me, lets go get a beer.  I&#8217;ll give you five free business ideas.</li>
<li>For every five ideas I can give you, there are five other people with their own idea.  I hear a lot of these.  I want to help you succeed but I can&#8217;t always be as invested as you.</li>
<li>You already trust me.  You must believe that I can do the work I say I can.  This is why you&#8217;re coming to me for a quote.  Also, the internet makes the world a small place.  It is not in my best interest to leak details &#8211; or I become Pariah #1.</li>
<li>It&#8217;s a legal document.  I am not a lawyer.</li>
<li>It&#8217;s just another document with my signature on it that I have to track.  I hate paper.</li>
<li>Chances are, it&#8217;s far too restrictive and I can&#8217;t agree to it in it&#8217;s current form.</il>
</ul>
<h2>This is a benefit for you</h2>
<p>If you&#8217;re still reticent to send me your idea and have me help you, let me state it a different way.  If we&#8217;re not busy working out details of our &#8217;secrets,&#8217; we can be working on the project. I bet you want this yesterday.  So do I.  Lets do it now &#8211; instead of waiting for something (such as an NDA) that is no longer providing any value to either of us.  Lets get it DONE! </p>
<p><a href="http://aaronsaray.com/blog">Original Content - Aaron Saray</a></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/aaronsaray?a=Hi9uOKh0u_Q:psbd8UCKaCU:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/aaronsaray?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/aaronsaray?a=Hi9uOKh0u_Q:psbd8UCKaCU:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/aaronsaray?i=Hi9uOKh0u_Q:psbd8UCKaCU:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/aaronsaray/~4/Hi9uOKh0u_Q" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://aaronsaray.com/blog/2010/03/05/aaron-on-ndas/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://aaronsaray.com/blog/2010/03/05/aaron-on-ndas/</feedburner:origLink></item>
		<item>
		<title>Javascript and CSS Compression and Cache</title>
		<link>http://feedproxy.google.com/~r/aaronsaray/~3/-yFy9c40zR0/</link>
		<comments>http://aaronsaray.com/blog/2010/02/25/javascript-and-css-compression-and-cache/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 18:31:27 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Misc Web Design]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://aaronsaray.com/blog/?p=568</guid>
		<description><![CDATA[I&#8217;ve been researching caching and compression techniques for my external resources for some time.  My first design of JEMDiary was very greedy with HTTP connections.  Couple that with having a less-than-perfect host (Dreamhost bleh&#8230;), users could feel the burn.  I didn&#8217;t like it because it would even take ME forever to use [...]<p><a href="http://aaronsaray.com/blog">Original Content - Aaron Saray</a></p>
]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been researching caching and compression techniques for my external resources for some time.  My first design of <a href="http://jemdiary.com">JEMDiary</a> was very greedy with HTTP connections.  Couple that with having a less-than-perfect host (Dreamhost bleh&#8230;), users could feel the burn.  I didn&#8217;t like it because it would even take ME forever to use my own website.  I went on to discover many different key points I use when creating sites now &#8211; the Steps to Optimize Assets.</p>
<h2>Steps to Optimize Assets</h2>
<p>There are a few steps I live by when I design my websites now.</p>
<ul>
<li><strong>Use a subdomain for images, js and css.</strong>  While I don&#8217;t go overkill with this (see: not 5 page brochure website), I do try to separate assets over multiple subdomains.  The important thing is not to have too many &#8211; but none what so ever limit your user from loading your site as quick as possible.  I generally use one for my assets and one for user submitted assets.</li>
<li><strong>Use sprites.</strong> Whenever possible, reduce the amount of HTTP requests by combining images.  It is faster to load an image that is 3x the size of the one you&#8217;re displaying than to open 2 more HTTP connections after you download the first image.</li>
<li><strong>Cache non changing elements as long as possible.</strong>  One of the biggest things I noticed on my dreamhost server was the misconfiguration of e-tags.  After disabling them, I went and looked further into caching techniques.  I found that most of my assets didn&#8217;t change &#8211; so I cached them up to a year.</li>
<li><strong>Compress away white space.</strong>  After you edit the source of your css, it doesn&#8217;t need to be pretty.  In fact, things like comments and white space in css and javascript are just wasted bytes&#8230; bytes you could remove&#8230; but bytes you shouldn&#8217;t remove from your source.  I deal with this by making a compressed copy on build.</li>
</ul>
<p>These are my main rules.  This article, however, is going to focus on how I deal with Javascript and CSS.</p>
<p><strong>Disclaimer: </strong> The methods I&#8217;m going to describe here can be labor intensive.  When you build your own system, you should strive to make some of these automated.</p>
<h2>Preparing CSS for deployment</h2>
<p>The first thing I do is create that subdomain.  For my site example.com, users can visit http://example.com for the content.  I create a subdomain called assets.example.com which is where I expect to get my content from.  I generally create a server alias in the main config.  This technically means that duplicate content could be served at both assets.example.com and example.com.  I finish up by adding the following lines to the .htaccess file:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p568code6'); return false;">View Code</a> APACHE</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p5686"><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="p568code6"><pre class="apache" style="font-family:monospace;"><span style="color: #adadad; font-style: italic;">#make sure assets load properly</span>
<span style="color: #00007f;">RewriteCond</span> %{HTTP_HOST} ^assets.example.com
<span style="color: #00007f;">RewriteCond</span> %{REQUEST_URI} !^/css
<span style="color: #00007f;">RewriteCond</span> %{REQUEST_URI} !^/js
<span style="color: #00007f;">RewriteCond</span> %{REQUEST_URI} !^/images
<span style="color: #00007f;">RewriteRule</span> ^(.*)$ http://example.com/$<span style="color: #ff0000;">1</span> [R=<span style="color: #ff0000;">301</span>,L]</pre></td></tr></table></div>

<p>This make sure that if the host is assets.example.com and the content is not coming form the css, js or images folder, to redirect with a 301 to the main domain.  This will stop duplicate content.</p>
<p>Enough about this, what about my CSS?</p>
<p>I actually hold my css in a different folder in my architecture &#8211; not some place that is world readable.  I usually call it the public_source folder &#8211; which is at the same level in the source tree as say the www or html folder.  In this example, I&#8217;m going to call my example file <strong>main.css</strong>.  So it is actually located at /var/www/public_source/main.css.</p>
<p>Next, I&#8217;ll create a file called dev.php in the assets folder where I plan to test my css from.  So, this file is located at /var/www/html/css/dev.php.  It may contain this content:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p568code7'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p5687"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p568code7"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">header</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-type: text/css'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">readfile</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/var/www/public_source/main.css'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>So, now when I load my website, I can do the following to load my source css:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p568code8'); return false;">View Code</a> HTML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p5688"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p568code8"><pre class="html" style="font-family:monospace;">&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;http://assets.example.com/css/dev.php&quot; /&gt;</pre></td></tr></table></div>

<p>Of course, when the website is built and deployed, we will be using a different URL.</p>
<p>Next, lets talk about compression of the CSS.  I use <a href="http://csstidy.sourceforge.net/">CSS Tidy</a> to compress my code.  The code to invoke this is pretty simple.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p568code9'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p5689"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code" id="p568code9"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">require</span> <span style="color: #0000ff;">'csstidy-1.3/class.csstidy.php'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$cssSource</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/var/www/public_source/main.css'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$css</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> csstidy<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$css</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load_template</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'highest_compression'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$css</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_cfg</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'remove_last_;'</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$css</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_cfg</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'sort_properties'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$css</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">parse</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cssSource</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$cssFinished</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$css</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">print</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">plain</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">file_put_contents</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/var/www/html/css/main.1.css'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$cssFinished</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>You&#8217;ll notice that I named the file <strong>main.1.css</strong>.  The number will be explained later (its used for caching).  </p>
<p>So, the CSS is read, compressed and cleaned, and outputted to a location that the webserver can serve it from.  Now, instead of using dev.php as the source, we&#8217;ll use main.1.css.  Congratulations &#8211; a smaller CSS file!</p>
<p>The final thing to do is adjust the caching of this script.  Whenever we change the CSS on the development platform, we&#8217;re reading it in new using dev.php.  However, when this is built and deployed, it should be a built version (or compressed) of the file.  This means every code deploy requires this build system.  And with release numbers on main software, we&#8217;re also going to increment our file name.  So our second deployment of the software package (if the CSS source has changed) will now be built using main.2.css &#8211; and the link statement will be pointed towards that.</p>
<p>The caching then can make the assumption that this file will never change.  The CSS may change but the file is a new name then.  And since we can&#8217;t just load portions of a file whenever there is a change, even a small change in a non-cached file will make the entire file load.  So with this in mind, I cache my CSS files for one year.  I put the following in my config:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p568code10'); return false;">View Code</a> APACHE</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p56810"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p568code10"><pre class="apache" style="font-family:monospace;"><span style="color: #00007f;">ExpiresActive</span> <span style="color: #0000ff;">On</span>
<span style="color: #adadad; font-style: italic;">#1 yr</span>
<span style="color: #00007f;">ExpiresByType</span> text/css A31536000</pre></td></tr></table></div>

<p>This means that the file will be cached one year from the first time it is accessed.  So, if the source HTML continues to point at the same CSS file (say&#8230; main</p>
<p><a href="http://aaronsaray.com/blog">Original Content - Aaron Saray</a></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/aaronsaray?a=-yFy9c40zR0:DLcq8tql7DM:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/aaronsaray?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/aaronsaray?a=-yFy9c40zR0:DLcq8tql7DM:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/aaronsaray?i=-yFy9c40zR0:DLcq8tql7DM:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/aaronsaray/~4/-yFy9c40zR0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://aaronsaray.com/blog/2010/02/25/javascript-and-css-compression-and-cache/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://aaronsaray.com/blog/2010/02/25/javascript-and-css-compression-and-cache/</feedburner:origLink></item>
		<item>
		<title>How about profiling your mysql queries… later?</title>
		<link>http://feedproxy.google.com/~r/aaronsaray/~3/4dA1n3HAWdU/</link>
		<comments>http://aaronsaray.com/blog/2010/02/19/how-about-profiling-your-mysql-queries-later/#comments</comments>
		<pubDate>Fri, 19 Feb 2010 17:21:31 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://aaronsaray.com/blog/?p=563</guid>
		<description><![CDATA[So the other night I was thinking about using xdebug on my PHP code.  I then totally had a brain explosion:  I&#8217;m always forgetting to profile my MySQL queries.  &#8216;Explain&#8217; is a great command for this.  However, as the lazy programmer I am, I don&#8217;t know if I&#8217;m always going to [...]<p><a href="http://aaronsaray.com/blog">Original Content - Aaron Saray</a></p>
]]></description>
			<content:encoded><![CDATA[<p>So the other night I was thinking about using xdebug on my PHP code.  I then totally had a brain explosion:  I&#8217;m always forgetting to profile my MySQL queries.  &#8216;Explain&#8217; is a great command for this.  However, as the lazy programmer I am, I don&#8217;t know if I&#8217;m always going to do this on all of my queries.  In an attempt to save myself time, I started brainstorming an idea.</p>
<p><strong>What if I extended my MySQL class to capture unique queries so I could run explain on them later?</strong></p>
<h3>You should profile your queries when you write them</h3>
<p>Well, you really should.  Check out the <a href="http://dev.mysql.com/doc/refman/5.0/en/using-explain.html">Explain Mysql Page</a> for more information on how to do this.  However, this is not always possible.</p>
<ol>
<li>You may be using a 3rd party or open source software application.  Then, you didn&#8217;t write the queries.</li>
<li>You FUBAR&#8217;d and forgot to do this &#8211; or got lazy &#8211; or blamed deadlines for being sloppy.</li>
</ol>
<p>Either way, you may not have been able to do the optimization ahead of time.</p>
<h3>Collect your queries</h3>
<p>So the next thought I had was to extend my database classes to capture these queries.  My goal is to grab all of the queries that are uniquely ran on my site and profile them.</p>
<p>Depending on the constants used in the query, however, each query may be different so you&#8217;ll just be logging all of your queries.  Prepared statements may help cut down on this &#8211; but you still need to capture some of the input.  So, your logging mechanism has now become more complex.</p>
<p>For those non-prepared statements, I think you could use tools like PHP&#8217;s <a href="http://us.php.net/manual/en/function.similar-text.php">Similar Text function</a> to determine if the query is indeed different enough to be logged.</p>
<h3>Automate it</h3>
<p>The last thought I had is to automate the process.  Wait until there is a significant amount of new queries (or queries you&#8217;ve marked to be re-analyzed) to be explained.  Then, have the process run during the middle of the night.  All of the explains are ran on the queries and the complete result is sent to your email address.  This way, the next morning, you can have your coffee while optimizing your statements! woo!</p>
<h3>Your thoughts</h3>
<p>Does something like this already exist?  Is this a good way to retroactively deal with the situation? I&#8217;m curious what you think.</p>
<p><a href="http://aaronsaray.com/blog">Original Content - Aaron Saray</a></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/aaronsaray?a=4dA1n3HAWdU:jMbAeCxCg4U:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/aaronsaray?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/aaronsaray?a=4dA1n3HAWdU:jMbAeCxCg4U:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/aaronsaray?i=4dA1n3HAWdU:jMbAeCxCg4U:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/aaronsaray/~4/4dA1n3HAWdU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://aaronsaray.com/blog/2010/02/19/how-about-profiling-your-mysql-queries-later/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://aaronsaray.com/blog/2010/02/19/how-about-profiling-your-mysql-queries-later/</feedburner:origLink></item>
		<item>
		<title>Exploring MySQL in Eclipse PDT</title>
		<link>http://feedproxy.google.com/~r/aaronsaray/~3/bKy9D5XuVPE/</link>
		<comments>http://aaronsaray.com/blog/2010/02/15/exploring-mysql-in-eclipse-pdt/#comments</comments>
		<pubDate>Mon, 15 Feb 2010 16:08:38 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[Eclipse PDT]]></category>
		<category><![CDATA[IDE and Web Dev Tools]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://aaronsaray.com/blog/?p=554</guid>
		<description><![CDATA[As you probably know by now, I&#8217;m a huge fan of Eclipse PDT.  Well, I wanted to stop using MySQL GUI tools for a bit and explore Eclipse tools.
Get the SQL Explorer Plugin

The first thing to do is to get the Eclipse SQL Explorer plugin.  You can get that at the update URL:
http://eclipsesql.sourceforge.net/
Install [...]<p><a href="http://aaronsaray.com/blog">Original Content - Aaron Saray</a></p>
]]></description>
			<content:encoded><![CDATA[<p>As you probably know by now, I&#8217;m a huge fan of Eclipse PDT.  Well, I wanted to stop using MySQL GUI tools for a bit and explore Eclipse tools.</p>
<h2>Get the SQL Explorer Plugin</h2>
<p><a href="http://aaronsaray.com/blog/wp-content/uploads/2010/01/1.jpg"><img src="http://aaronsaray.com/blog/wp-content/uploads/2010/01/1-150x56.jpg" alt="" title="Use the Update Site" width="150" height="56" class="alignright size-thumbnail wp-image-555" /></a><br />
The first thing to do is to get the Eclipse SQL Explorer plugin.  You can get that at the update URL:<br />
<a href="http://eclipsesql.sourceforge.net/">http://eclipsesql.sourceforge.net/</a></p>
<p>Install this software like you normally would.  Accept the license and you&#8217;re ready to go with the plugin.  I would recommend letting Eclipse restart after the installation.<br />
<a href="http://aaronsaray.com/blog/wp-content/uploads/2010/01/2.jpg"><img src="http://aaronsaray.com/blog/wp-content/uploads/2010/01/2-300x33.jpg" alt="" title="Select the proper package" width="300" height="33" class="alignright size-medium wp-image-556" /></a></p>
<h2>Eclipse Uses JDBC</h2>
<p>Eclipse uses JDBC connections to connect to MySQL.  You can get this on the MySQL connectors page:<br />
<a href="http://www.mysql.com/products/connector/">Connector</a></p>
<p>Simply unzip the connector into your Eclipse program directory and move on.</p>
<h2>Open Eclipse</h2>
<p><a href="http://aaronsaray.com/blog/wp-content/uploads/2010/01/3.jpg"><img src="http://aaronsaray.com/blog/wp-content/uploads/2010/01/3-125x150.jpg" alt="" title="Select the Perspective" width="125" height="150" class="alignright size-thumbnail wp-image-557" /></a>Next, Open eclipse (if its not already open.)  First step is to choose the SQL Explorer perspective.  This can be done by going to the Window menu, clicking Open Perspective and choosing Other.  Then, select the perspective from the list.</p>
<p>Now, create a connection profile.  This is done by clicking on the Create New Connection Profile link.  From here, name your connection, choose your adapter and fill in the proper credentials.  (If you&#8217;re not familiar with this style credentials, you can visit this website:  <a href="http://www.connectionstrings.com/">http://www.connectionstrings.com</a></p>
<h3>What if I can&#8217;t find my Driver in the list?</h3>
<p>There is a good chance that the driver may not be in the list by default.<br />
Follow the following steps.</p>
<p><a href="http://aaronsaray.com/blog/wp-content/uploads/2010/01/5.jpg"><img src="http://aaronsaray.com/blog/wp-content/uploads/2010/01/5-150x122.jpg" alt="" title="Java Class Path" width="150" height="122" class="alignright size-thumbnail wp-image-558" /></a>1) On the connection profile screen, click the &#8216;Add/Edit&#8217; button<br />
2) Select the MysQL driver in the list.<br />
3) Click the Edit button on the right hand side.<br />
4) If you do not see your driver in the list of Java Class Paths, click on the Extra Class Path tab.<br />
5) Browse to find your most recent driver download and select that jar file.<br />
6) Click on the list drivers button.  com.mysql.jdbc.Driver should appear in the Driver Class Name box.  If not, select it.<br />
7) Click OK and then OK again to return to the connection profile box</p>
<p>Now you should be able to use the MySQL driver from the list.</p>
<h2>Browsing the Database</h2>
<p><a href="http://aaronsaray.com/blog/wp-content/uploads/2010/01/6.jpg"><img src="http://aaronsaray.com/blog/wp-content/uploads/2010/01/6-150x37.jpg" alt="" title="6" width="150" height="37" class="alignright size-thumbnail wp-image-559" /></a>After configuring the connection profile, you should see it in your list of connections.  Once you expand it and double click the user, you will be prompted to enter your password (as well as choose some other connection profile options).  </p>
<p><a href="http://aaronsaray.com/blog/wp-content/uploads/2010/01/7.jpg"><img src="http://aaronsaray.com/blog/wp-content/uploads/2010/01/7-300x213.jpg" alt="" title="7" width="300" height="213" class="alignnone size-medium wp-image-560" /></a></p>
<p>From here, you&#8217;re good to go!  You can browse the databases in the Database Structure tab, you can edit SQL in the SQL Editor tab, etc.</p>
<p><a href="http://aaronsaray.com/blog">Original Content - Aaron Saray</a></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/aaronsaray?a=bKy9D5XuVPE:K3976gSnQhA:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/aaronsaray?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/aaronsaray?a=bKy9D5XuVPE:K3976gSnQhA:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/aaronsaray?i=bKy9D5XuVPE:K3976gSnQhA:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/aaronsaray/~4/bKy9D5XuVPE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://aaronsaray.com/blog/2010/02/15/exploring-mysql-in-eclipse-pdt/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://aaronsaray.com/blog/2010/02/15/exploring-mysql-in-eclipse-pdt/</feedburner:origLink></item>
		<item>
		<title>Milwaukee PHP Users Group</title>
		<link>http://feedproxy.google.com/~r/aaronsaray/~3/C5gEQbEpxwo/</link>
		<comments>http://aaronsaray.com/blog/2010/02/09/milwaukee-php-users-group/#comments</comments>
		<pubDate>Tue, 09 Feb 2010 15:28:20 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[Milwaukee PHP Users Group]]></category>

		<guid isPermaLink="false">http://aaronsaray.com/blog/?p=550</guid>
		<description><![CDATA[I started the Milwaukee PHP Users group a few weeks ago.  Unfortunately, today we had to cancel a meeting because of the outpouring of snow&#8230; but it&#8217;s on for the 4th tuesday of the month.  
You can find more details at http://mkepug.org/ or stop by bucketworks every 2nd and 4th tuesday of the [...]<p><a href="http://aaronsaray.com/blog">Original Content - Aaron Saray</a></p>
]]></description>
			<content:encoded><![CDATA[<p>I started the Milwaukee PHP Users group a few weeks ago.  Unfortunately, today we had to cancel a meeting because of the outpouring of snow&#8230; but it&#8217;s on for the 4th tuesday of the month.  </p>
<p>You can find more details at <a href="http://mkepug.org/">http://mkepug.org/</a> or stop by bucketworks every 2nd and 4th tuesday of the month.</p>
<p><a href="http://aaronsaray.com/blog">Original Content - Aaron Saray</a></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/aaronsaray?a=C5gEQbEpxwo:y5FQ8aSwfi4:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/aaronsaray?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/aaronsaray?a=C5gEQbEpxwo:y5FQ8aSwfi4:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/aaronsaray?i=C5gEQbEpxwo:y5FQ8aSwfi4:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/aaronsaray/~4/C5gEQbEpxwo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://aaronsaray.com/blog/2010/02/09/milwaukee-php-users-group/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://aaronsaray.com/blog/2010/02/09/milwaukee-php-users-group/</feedburner:origLink></item>
		<item>
		<title>XFN – XHTML Friends Network</title>
		<link>http://feedproxy.google.com/~r/aaronsaray/~3/WjJUWEFWp5s/</link>
		<comments>http://aaronsaray.com/blog/2010/02/05/xfn/#comments</comments>
		<pubDate>Fri, 05 Feb 2010 20:24:12 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[semantic web]]></category>

		<guid isPermaLink="false">http://aaronsaray.com/blog/?p=552</guid>
		<description><![CDATA[While I continue to look at the semantic web, I can&#8217;t help but scratch my head and say &#8220;why&#8221; about some of these technologies.  I feel like its still sadly lacking&#8230; with that, let me introduce&#8230;
XHTML Friends Network
XFN (website here) aims to build relationships between people on the internet using specific attribute values in [...]<p><a href="http://aaronsaray.com/blog">Original Content - Aaron Saray</a></p>
]]></description>
			<content:encoded><![CDATA[<p>While I continue to look at the semantic web, I can&#8217;t help but scratch my head and say &#8220;why&#8221; about some of these technologies.  I feel like its still sadly lacking&#8230; with that, let me introduce&#8230;</p>
<h2>XHTML Friends Network</h2>
<p>XFN (<a href="http://gmpg.org/xfn/">website here</a>) aims to build relationships between people on the internet using specific attribute values in the link tags.  Once again, this particular method has a list of types of relationships that can be applied to build an N-N relationship.</p>
<h3>Should I use it?</h3>
<p>I myself am not planning on using it (well&#8230; yet).  Most of my websites are not strongly &#8216;friend&#8217; oriented.  Instead, they are content based.  There are some relationships built on pages like the <a href="http://jemdiary.com">JEMDiary</a> friends page&#8230; but nothing too extreme.  </p>
<p>Should you use it?  Well&#8230; maybe.  </p>
<h3>Its kind of niche</h3>
<p>One of the biggest &#8216;arguments&#8217; for the implementation of XFN has been the &#8216;blog-roll&#8217; instances on the sides of blogs.  Blogs themselves are not niche &#8211; but this &#8216;friends list&#8217; kind of is.  I think only a small portion of users actually keep an updated blog-roll.  Blogs are so widespread &#8211; especially now with media company based and editorial blogs &#8211; that keeping a &#8216;friends list&#8217; would be nearly impossible.  So that niche is dying.</p>
<p>Another large portion of the web is social networking.  However, I still believe the implementation of XFN in a social networking site is a niche possibility.  One of the biggest debates right now centers around the security changes on facebook.  They have decided to push more information to the public internet which is causing quite a ruckus.  The main point of XFN is to provide relationships to the public.  So, if this protocol must be consumed, this information must be public, and must be implemented in a way that the user who is demonstrating their relationships agrees with.  A questionable niche.</p>
<p>So, should you implement it?  Hrm&#8230;</p>
<h3>Users Must Be Disciplined</h3>
<p>If you&#8217;re not the author of the XFN, your users may be.  This means that they have to share the same discipline and understanding of the concept as you do.  Take these three specific values for the attribute: &#8220;friend, met, colleague.&#8221;  When you finally study the specification, it makes sense.  However, the likeliness of some user specifying their relationship incorrectly with XFN without having read the instructions is great.</p>
<h3>It probably doesn&#8217;t hurt</h3>
<p>Except for the reason stated above (users may mis-label their relationships), there is only one scenario that I can see where I can see a problem: the potential for two sources to list different information about a relationship.  But besides that, I look at XFN as sort of an after thought.  I may implement it on some of my social network based sites &#8211; but very sparsely. </p>
<p>Your thoughts?</p>
<p><a href="http://aaronsaray.com/blog">Original Content - Aaron Saray</a></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/aaronsaray?a=WjJUWEFWp5s:p9D7Xd--B4A:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/aaronsaray?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/aaronsaray?a=WjJUWEFWp5s:p9D7Xd--B4A:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/aaronsaray?i=WjJUWEFWp5s:p9D7Xd--B4A:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/aaronsaray/~4/WjJUWEFWp5s" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://aaronsaray.com/blog/2010/02/05/xfn/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://aaronsaray.com/blog/2010/02/05/xfn/</feedburner:origLink></item>
		<item>
		<title>hCard – should I care?</title>
		<link>http://feedproxy.google.com/~r/aaronsaray/~3/U_vd9TlL8Q0/</link>
		<comments>http://aaronsaray.com/blog/2010/01/23/hcard-should-i-care/#comments</comments>
		<pubDate>Sat, 23 Jan 2010 20:52:19 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[Misc Web Design]]></category>

		<guid isPermaLink="false">http://aaronsaray.com/blog/?p=547</guid>
		<description><![CDATA[So lately, I&#8217;ve been looking into the semantic tools available on the web.  I want to make sure that my online identity is easily searchable and undeniably accurate.  Using semantic tools such as XFN, FOAF and hCard may help me.  
I can&#8217;t help but seeing some of these and thinking &#8216;flash in [...]<p><a href="http://aaronsaray.com/blog">Original Content - Aaron Saray</a></p>
]]></description>
			<content:encoded><![CDATA[<p>So lately, I&#8217;ve been looking into the semantic tools available on the web.  I want to make sure that my online identity is easily searchable and undeniably accurate.  Using semantic tools such as XFN, FOAF and hCard may help me.  </p>
<p>I can&#8217;t help but seeing some of these and thinking &#8216;flash in the pan&#8217; though.  What I really want to see is a big &#8211; or a giant &#8211; company come through and make use of these.  For example, LiveJournal is exporting FOAF information &#8211; but who cares?  Where can I actually find value out of that information that was previously consumed?  If I search &#8216;Aaron Saray&#8217; on Google, will my friends show up along the sidebar?</p>
<p>At any rate, I did implement a very basic FOAF RDF file on my home page.  I am reluctant to do anything further, however.  Like I said, I&#8217;m not seeing much value as of yet.  However, I did want to look at another alternative, hCard.</p>
<h3>What is hCard</h3>
<p><a href="http://microformats.org/wiki/hcard">hCard</a> is just an expansion on the vCard standard.  The website says it has a 1:1 representation of the vCard properties.  Plus, it goes further by allowing itself to be embedded into web properties.  So basically, its a vCard that I show on my website, right?  Isn&#8217;t this already what my contact page does?  (Yes &#8211; but the argument is this is a standardized form so that it can be machine readable &#8211; I get it I get it).</p>
<h3>Who is using hCard</h3>
<p>More and more libraries are using hCard.  The number one thing that caught my eye was the possible implementation by drupal (see <a href="http://groups.drupal.org/node/1898">http://groups.drupal.org/node/1898</a>.  Yet, I&#8217;m seeing many people put out the information to be consumed, but I&#8217;m not seeing many groups actually doing the consuming.</p>
<h3>How can I use it?</h3>
<p>Well besides looking at the specs, you can use the following two libraries in PHP:<br />
<a href="http://enarion.net/phpmicroformats/">phpMicroformats</a><br />
<a href="http://www.phpclasses.org/browse/package/3597.html">Microformats Parser</a></p>
<h3>So what did you do?</h3>
<p>Ok so after all this complaining, I have to admit &#8211; I&#8217;m still guilty&#8230; I implemented it on my contact page <img src='http://aaronsaray.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><a href="http://aaronsaray.com/blog">Original Content - Aaron Saray</a></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/aaronsaray?a=U_vd9TlL8Q0:3q0fhv9Gkxg:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/aaronsaray?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/aaronsaray?a=U_vd9TlL8Q0:3q0fhv9Gkxg:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/aaronsaray?i=U_vd9TlL8Q0:3q0fhv9Gkxg:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/aaronsaray/~4/U_vd9TlL8Q0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://aaronsaray.com/blog/2010/01/23/hcard-should-i-care/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://aaronsaray.com/blog/2010/01/23/hcard-should-i-care/</feedburner:origLink></item>
		<item>
		<title>Friend of a Friend: FOAF</title>
		<link>http://feedproxy.google.com/~r/aaronsaray/~3/NwfFS3epFec/</link>
		<comments>http://aaronsaray.com/blog/2010/01/20/friend-of-a-friend-foaf/#comments</comments>
		<pubDate>Wed, 20 Jan 2010 16:13:48 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[Misc Web Design]]></category>

		<guid isPermaLink="false">http://aaronsaray.com/blog/?p=545</guid>
		<description><![CDATA[So I added my own FOAF link on my home page.  The RDF file is here:
http://assets.aaronsaray.com/assets/foaf.rdf
For those who aren&#8217;t familiar, Friend of a Friend is a protocol defined to help machines read relationships between entities (persons) on the internet.  The relationships are set up in RDF file.  (Mine is severely limited &#8211; [...]<p><a href="http://aaronsaray.com/blog">Original Content - Aaron Saray</a></p>
]]></description>
			<content:encoded><![CDATA[<p>So I added my own FOAF link on my home page.  The RDF file is here:<br />
<a href="http://assets.aaronsaray.com/assets/foaf.rdf">http://assets.aaronsaray.com/assets/foaf.rdf</a></p>
<p>For those who aren&#8217;t familiar, Friend of a Friend is a protocol defined to help machines read relationships between entities (persons) on the internet.  The relationships are set up in RDF file.  (Mine is severely limited &#8211; either I have no friends &#8211; or am just lazy &#8211; you tell me!)  For more info, check out <a href="http://www.foaf-project.org/">http://www.foaf-project.org/</a>.</p>
<p>By far, the best library I&#8217;ve found for parsing FOAF files is located here: <a href="http://gna.org/projects/phoaf">http://gna.org/projects/phoaf</a></p>
<p><a href="http://aaronsaray.com/blog">Original Content - Aaron Saray</a></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/aaronsaray?a=NwfFS3epFec:Guk6QJB9nfk:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/aaronsaray?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/aaronsaray?a=NwfFS3epFec:Guk6QJB9nfk:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/aaronsaray?i=NwfFS3epFec:Guk6QJB9nfk:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/aaronsaray/~4/NwfFS3epFec" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://aaronsaray.com/blog/2010/01/20/friend-of-a-friend-foaf/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://aaronsaray.com/blog/2010/01/20/friend-of-a-friend-foaf/</feedburner:origLink></item>
		<item>
		<title>Making Friendly Javascript Errors – Client and Server</title>
		<link>http://feedproxy.google.com/~r/aaronsaray/~3/GQLpU6KDBcc/</link>
		<comments>http://aaronsaray.com/blog/2010/01/14/making-friendly-javascript-errors-client-and-server/#comments</comments>
		<pubDate>Thu, 14 Jan 2010 16:30:15 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://aaronsaray.com/blog/?p=539</guid>
		<description><![CDATA[The more I look at my code I wrote in my earlier posts about the unknown _popupControl() function and the Javascript Error Handler, I see opportunities to leverage these errors into useful user interactions.
Doing a service for your visitor
After your javascript is tried and tested and error free, there are still chances that errors can [...]<p><a href="http://aaronsaray.com/blog">Original Content - Aaron Saray</a></p>
]]></description>
			<content:encoded><![CDATA[<p>The more I look at my code I wrote in my earlier posts about the <a href="http://aaronsaray.com/blog/2009/09/29/unknown-function-_popupcontrol/">unknown _popupControl() function</a> and the <a href="http://aaronsaray.com/blog/2009/09/23/javascript-error-handler/">Javascript Error Handler</a>, I see opportunities to leverage these errors into useful user interactions.</p>
<h2>Doing a service for your visitor</h2>
<p>After your javascript is tried and tested and error free, there are still chances that errors can be logged using my utility.  These usually are the result of Spyware that is left on the user&#8217;s machine.  Sometimes some removal processes don&#8217;t capture all of it.  The _popupControl() method was one such remnant.  </p>
<p>I thought that instead of just ignoring these issues, I could gently alert the user to the issue.  Perhaps, I could even get affiliate commissions for a product that I know for sure removes these threats.</p>
<p>There are two ways to go about handling these javascript errors: client side and server side.</p>
<h2>Client Side</h2>
<p>Client side javascript error handling requires a bit more front-end programming.  It also shows a lot of your cards to the outside world.  By looking at the code in the javascript portion of your page, visitors could see all types of errors that you&#8217;re trying to detect.  While I don&#8217;t think this is a deterrent to using this method, you may feel otherwise.</p>
<p>First things first &#8211; if you can&#8217;t remember, check out my <a href="http://aaronsaray.com/blog/2009/09/23/javascript-error-handler/">Javascript Error Handler and Logger</a> entry to see the code I&#8217;ll be expanding on.</p>
<p>My new code is going to look something like this:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p539code14'); return false;">View Code</a> JAVASCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p53914"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code" id="p539code14"><pre class="javascript" style="font-family:monospace;">            window.<span style="color: #000066;">onerror</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>message<span style="color: #339933;">,</span> url<span style="color: #339933;">,</span> line<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #009966; font-style: italic;">/** log message **/</span>
                <span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Image<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                i.<span style="color: #660066;">src</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'error.php?url='</span> <span style="color: #339933;">+</span> escape<span style="color: #009900;">&#40;</span>url<span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&amp;message='</span> <span style="color: #339933;">+</span> escape<span style="color: #009900;">&#40;</span>message<span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&amp;line='</span> <span style="color: #339933;">+</span> line<span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>message.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'spywareWindowGenerator'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    <span style="color: #003366; font-weight: bold;">var</span> d <span style="color: #339933;">=</span> document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    d.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'Sounds like you got spyware'</span><span style="color: #339933;">;</span>
                    document.<span style="color: #660066;">body</span>.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>d<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
                <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>message.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'otherbaddie'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    <span style="color: #003366; font-weight: bold;">var</span> d <span style="color: #339933;">=</span> document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    d.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'Sounds like you got some other baddie'</span><span style="color: #339933;">;</span>
                    document.<span style="color: #660066;">body</span>.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>d<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>I&#8217;ll break it down:</p>
<p>First, the standard logging service is initiated on error.  The error.php file will log the javascript error for further research later.</p>
<p>Next, I evaluate the actual message that was sent to the error handler.  In this example, I&#8217;m looking for two possible issues, a reference to the function _spywareWindowGenerator() and a reference to someOtherBaddie().  Both of these functions are not defined in my code and can be considered to be remnants of the spyware infestation.</p>
<p>The first &#8216;if&#8217; statement checks for the existence of &#8217;spywareWindowGenerator&#8217; in the message.  If it exists, it creates a new DIV HTML element.  Then, it populates it with a message regarding this error.  (Note, you could also load an image, create link, etc.).  Finally, just for demonstration purpose, that DIV is added to the end of the body and is displayed.</p>
<p>The second if statement is simply checking for the case of &#8216;otherBaddie&#8217; &#8211; and will do a similar process.</p>
<p>Like I mentioned before, this lays all of your cards out on the table &#8211; could potentially make your page load longer (especially if you have a lot of spyware you&#8217;re tracking), but be most versatile.</p>
<h2>Server Side</h2>
<p>With server side, I&#8217;m going to rely on the image that the javascript error handler is loading.  If this image is populated by my error.php file, then I&#8217;ll show it.</p>
<p>First, the modified javascript for our error handler now looks like this:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p539code15'); return false;">View Code</a> JAVASCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p53915"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code" id="p539code15"><pre class="javascript" style="font-family:monospace;">            window.<span style="color: #000066;">onerror</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>message<span style="color: #339933;">,</span> url<span style="color: #339933;">,</span> line<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #009966; font-style: italic;">/** log message **/</span>
                <span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Image<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                i.<span style="color: #660066;">src</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'error.php?url='</span> <span style="color: #339933;">+</span> escape<span style="color: #009900;">&#40;</span>url<span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&amp;message='</span> <span style="color: #339933;">+</span> escape<span style="color: #009900;">&#40;</span>message<span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&amp;line='</span> <span style="color: #339933;">+</span> line<span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #009966; font-style: italic;">/** now check to see if we have something to show **/</span>
                <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>i.<span style="color: #660066;">height</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    <span style="color: #009966; font-style: italic;">/** add it to the page **/</span>
                    document.<span style="color: #660066;">body</span>.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>The first part is the standard logging mechanism that we&#8217;re used to.  However, after that, I check for a height of the image that was requested.  If no image was generated by the PHP GET request, then the height will be 0.  Otherwise, the image object will return a height.  Then, just for demonstration, I append that image to the bottom of the body of the document.</p>
<p>This means that we put a little bit more of the responsibility for determining the message to display to the user on the back end.  At first it seems like it could be a little less verbose &#8211; as it is just an image.  However, we could expand the javascript error handler to detect what &#8216;link&#8217; it could display based on the image dimensions, etc.  (This is for a different entry if need be&#8230;)</p>
<p>Next, I had to edit my error.php file.  It now contains this code:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p539code16'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p53916"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
</pre></td><td class="code" id="p539code16"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$keys</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: #000088;">$keys</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'_spywareWindowGenerator'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'badSypware.png'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$keys</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'otherBadGuy'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'otherBadGuy.png'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * check for an image to show
 */</span>
&nbsp;
<span style="color: #000088;">$imageToShow</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$keys</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$substring</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$image</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;">stripos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</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: #000088;">$substring</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!==</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$imageToShow</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$image</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$imageToShow</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-Type: image/png'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">readfile</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$imageToShow</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">die</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: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #990000;">error_log</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">{$_GET['message']}</span> occured on line <span style="color: #006699; font-weight: bold;">{$_GET['line']}</span> of URL <span style="color: #006699; font-weight: bold;">{$_GET['url']}</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>The first step is to determine all of the key words that could appear in javascript error messages.  Then, associate them with an image that conveys our message.</p>
<p>The next bit of code looks through and searches the message for any of the possibilities.  If it finds one, it sets the image to be the associated value for that key.</p>
<p>Finally, the PHP code checks to see if there is an image to show.  If so, it sends the proper header and reads the file to the output buffer.  Otherwise, it assumes it is an error that we&#8217;re not familiar with and logs it.</p>
<p>In this example, I used the following two images just for testing. </p>

<a href='http://aaronsaray.com/blog/2010/01/14/making-friendly-javascript-errors-client-and-server/badspyware/' title='badSpyware'><img width="150" height="75" src="http://aaronsaray.com/blog/wp-content/uploads/2010/01/badSpyware.png" class="attachment-thumbnail" alt="" title="badSpyware" /></a>
<a href='http://aaronsaray.com/blog/2010/01/14/making-friendly-javascript-errors-client-and-server/otherbadguy/' title='otherBadGuy'><img width="150" height="75" src="http://aaronsaray.com/blog/wp-content/uploads/2010/01/otherBadGuy.png" class="attachment-thumbnail" alt="" title="otherBadGuy" /></a>

<p><a href="http://aaronsaray.com/blog">Original Content - Aaron Saray</a></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/aaronsaray?a=GQLpU6KDBcc:Dnp-pcZfKbs:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/aaronsaray?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/aaronsaray?a=GQLpU6KDBcc:Dnp-pcZfKbs:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/aaronsaray?i=GQLpU6KDBcc:Dnp-pcZfKbs:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/aaronsaray/~4/GQLpU6KDBcc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://aaronsaray.com/blog/2010/01/14/making-friendly-javascript-errors-client-and-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://aaronsaray.com/blog/2010/01/14/making-friendly-javascript-errors-client-and-server/</feedburner:origLink></item>
		<item>
		<title>Using Google Analytics Asynchronously</title>
		<link>http://feedproxy.google.com/~r/aaronsaray/~3/N-P92C2HvZ4/</link>
		<comments>http://aaronsaray.com/blog/2010/01/11/using-google-analytics-asynchronously/#comments</comments>
		<pubDate>Tue, 12 Jan 2010 00:35:07 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[google]]></category>

		<guid isPermaLink="false">http://aaronsaray.com/blog/?p=537</guid>
		<description><![CDATA[I came across the following link on google&#8217;s code pages:
http://code.google.com/apis/analytics/docs/tracking/asyncTracking.html
It basically details the asynchronous loading of google analytics.  I found this to be a very cool addition to an already powerful package that I rely on.
However, one thing that I haven&#8217;t been able to successfully figure out.  What happens when you want to [...]<p><a href="http://aaronsaray.com/blog">Original Content - Aaron Saray</a></p>
]]></description>
			<content:encoded><![CDATA[<p>I came across the following link on google&#8217;s code pages:<br />
<a href="http://code.google.com/apis/analytics/docs/tracking/asyncTracking.html">http://code.google.com/apis/analytics/docs/tracking/asyncTracking.html</a></p>
<p>It basically details the asynchronous loading of google analytics.  I found this to be a very cool addition to an already powerful package that I rely on.</p>
<p>However, one thing that I haven&#8217;t been able to successfully figure out.  What happens when you want to load in two instances or two different accounts?  On one of my sites, I use my own google analytics account plus the clients.  This tracks the traffic fine with the non-asynchronous method.  You simply make a new instance of the ga object and assign a new ID to it.  However, can I do the same thing with this asynch method?  I&#8217;m kind of wary to try it because I don&#8217;t want to lose any data.</p>
<p>Anyone have any experience or have any links to where I can find this detail?</p>
<p><a href="http://aaronsaray.com/blog">Original Content - Aaron Saray</a></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/aaronsaray?a=N-P92C2HvZ4:JYMKUVGXhIw:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/aaronsaray?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/aaronsaray?a=N-P92C2HvZ4:JYMKUVGXhIw:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/aaronsaray?i=N-P92C2HvZ4:JYMKUVGXhIw:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/aaronsaray/~4/N-P92C2HvZ4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://aaronsaray.com/blog/2010/01/11/using-google-analytics-asynchronously/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://aaronsaray.com/blog/2010/01/11/using-google-analytics-asynchronously/</feedburner:origLink></item>
	</channel>
</rss><!-- Dynamic page generated in 2.612 seconds. --><!-- Cached page generated by WP-Super-Cache on 2010-03-12 12:49:54 -->
