<?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>Brian Cray&#039;s Blog</title>
	<atom:link href="http://briancray.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://briancray.com</link>
	<description>User Experience Design, Web Development, and Internet Marketing</description>
	<lastBuildDate>Mon, 09 Apr 2012 16:54:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
<atom:link rel="hub" href="http://pubsubhubbub.appspot.com" />
	<atom:link rel="hub" href="http://superfeedr.com/hubbub" />
			<item>
		<title>An analogy to sell design iteration</title>
		<link>http://briancray.com/2012/04/09/an-analogy-to-sell-design-iteration/</link>
		<comments>http://briancray.com/2012/04/09/an-analogy-to-sell-design-iteration/#comments</comments>
		<pubDate>Mon, 09 Apr 2012 16:54:13 +0000</pubDate>
		<dc:creator>Brian Cray</dc:creator>
				<category><![CDATA[User experience]]></category>
		<category><![CDATA[product development]]></category>
		<category><![CDATA[usability]]></category>

		<guid isPermaLink="false">http://briancray.com/?p=1883</guid>
		<description><![CDATA[The beautiful thing about a car is that it&#8217;s an amazingly complex system that can be controlled with just a steering wheel and two peddles. Sure, race car drivers have many more controls at their disposal, but they&#8217;re advanced users. Let&#8217;s help our users learn to drive before we teach them to be race care [...]]]></description>
			<content:encoded><![CDATA[<p>The beautiful thing about a car is that it&#8217;s an amazingly complex system that can be controlled with just a steering wheel and two peddles. Sure, race car drivers have many more controls at their disposal, but they&#8217;re advanced users. Let&#8217;s help our users learn to drive before we teach them to be race care drivers.</p>


<p>Related posts:<ol><li><a href='http://briancray.com/2009/08/26/blog-design-information-overload-progressive-disclosure/' rel='bookmark' title='Permanent Link: Blog design best practice: Scrollbars not sidebars'>Blog design best practice: Scrollbars not sidebars</a></li>
<li><a href='http://briancray.com/2010/04/09/estimated-reading-time-web-design/' rel='bookmark' title='Permanent Link: Estimated reading time in web design'>Estimated reading time in web design</a></li>
<li><a href='http://briancray.com/2010/02/03/measuring-simplicity-in-web-design/' rel='bookmark' title='Permanent Link: The more I know, the less I need: Thoughts on web design'>The more I know, the less I need: Thoughts on web design</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://briancray.com/2012/04/09/an-analogy-to-sell-design-iteration/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Javascript module pattern: When to use it and why</title>
		<link>http://briancray.com/2012/02/23/javascript-module-pattern/</link>
		<comments>http://briancray.com/2012/02/23/javascript-module-pattern/#comments</comments>
		<pubDate>Thu, 23 Feb 2012 15:14:09 +0000</pubDate>
		<dc:creator>Brian Cray</dc:creator>
				<category><![CDATA[Web development]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://briancray.com/?p=1881</guid>
		<description><![CDATA[There have been a few criticisms of the javascript module pattern, despite its many advantages. Take for example Jonathon Snook&#8217;s &#8220;Why I don&#8217;t like javascript&#8217;s module pattern&#8221;. While everyone has their own style, my fear is that people, given Snook&#8217;s demanding presence, will take his word for gospel without understanding it. This article isn&#8217;t about [...]]]></description>
			<content:encoded><![CDATA[<p>There have been a few criticisms of the javascript module pattern, despite its many advantages. Take for example <a href="http://snook.ca/archives/javascript/no-love-for-module-pattern">Jonathon Snook&#8217;s &ldquo;Why I don&#8217;t like javascript&#8217;s module pattern&rdquo;</a>. While everyone has their own style, my fear is that people, given Snook&#8217;s demanding presence, will take his word for gospel without understanding it.</p>
<p>This article isn&#8217;t about teaching you the pattern, but more about when to use it and why&mdash;though I&#8217;ll start with a brief example of the pattern to get us all on the same page.</p>
<h3>A brief example in my favored flavor</h3>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> module <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">// private variables and functions</span>
    <span style="color: #003366; font-weight: bold;">var</span> foo <span style="color: #339933;">=</span> <span style="color: #3366CC;">'bar'</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// constructor</span>
    <span style="color: #003366; font-weight: bold;">var</span> module <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// prototype</span>
    module.<span style="color: #660066;">prototype</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
        constructor<span style="color: #339933;">:</span> module<span style="color: #339933;">,</span>
        something<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// return module</span>
    <span style="color: #000066; font-weight: bold;">return</span> module<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> my_module <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> module<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This appears to be a lot of unnecessary code at first glance, but each line is plays a key role in making the module pattern advantageous.</p>
<h3>The when &amp; why</h3>
<ul>
<li>
<p><strong>Scalable.</strong> Modules are isolated pieces of code that when well designed, work independently of other modules and therefore can be removed and added as necessary.</p>
</li>
<li>
<p><strong>Team-ready.</strong> Building a large-scale javascript application is simpler with the module pattern. Each developer on a team can be assigned a set of modules to develop and can work in parallel with minimal conflicts. Additionally, everyone can write in their own preferred style within the context of the pattern without preferences getting in the way of progress.</p>
</li>
<li>
<p><strong>Localized.</strong> Anonymous wrappers automatically create a new &#8220;namespace&#8221; for the whole module. This has performance advantages in garbage collection and scope chain walking. Furthermore, variables can be passed into the anonymous wrapper to localize commonly accessed global variables, such as <code>window</code>, <code>document</code>, and <code>jQuery</code>, like so:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> module <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>window<span style="color: #339933;">,</span> document<span style="color: #339933;">,</span> $<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">// module stuff</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>window<span style="color: #339933;">,</span> document<span style="color: #339933;">,</span> jQuery<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

</li>
<li>
<p><strong>Cross-instantiation private variables.</strong> Normally when you instantiate an object with something like <code>new module()</code>, a whole new clean object is created&ndash;and that&#8217;s still the case. But the private variables will retain their values across instantiations.</p>
</li>
<li>
<p><strong>Extensible.</strong> Want to dynamically add additional methods to a module? No problem.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// extend it with something_else();</span>
<span style="color: #003366; font-weight: bold;">var</span> module <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>module<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    module.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">something_else</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">return</span> module<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>module<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>With a few changes this same pattern can be used to &#8220;subclass&#8221; an existing module.</p>
</li>
<li>
<p><strong>Deferrable.</strong> Another advantage of its isolation and containment is that you can inject it on demand without worrying about its impact on other modules. Using the following code, for example:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> inject_module <span style="color: #009900;">&#40;</span>module_file<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> h <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'head'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> s <span style="color: #339933;">=</span> document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'script'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    s.<span style="color: #660066;">type</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'text/javascript'</span><span style="color: #339933;">;</span>
    s.<span style="color: #660066;">src</span> <span style="color: #339933;">=</span> module_file<span style="color: #339933;">;</span>
    h.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>s<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

</li>
<h3>Bonus: Tips for well-designed modules</h3>
<ul>
<li>Don&#8217;t make modules explicitly depend on each other. Everything each module needs to work should be confined into either the module or plugins that are shared among modules.</li>
<li>Have modules communicate to each other through event subscriptions, not through direct calls to each other. They call this a pubsub. If you&rsquo;re using jQuery, check out <a href="https://gist.github.com/661855">jQuery Tiny Pub/Sub</a>. If not, <a href="http://addyosmani.com/resources/essentialjsdesignpatterns/book/#observerpatternjavascript">here&rsquo;s a good vanilla pubsub.</a></li>
<li>Create a light integration layer that handles module injection and interaction.</lI>
</ul>
<h3>Conclusion</h3>
<p>The javascript module pattern has many benefits through isolation and localization. They shouldn&#8217;t be written off until you&#8217;ve given due thought into the design of your application and your team. I&#8217;m currently in the process of writing a large-scale javascript application based on this pattern, and I have to say, it&rsquo;s a delight.</p>


<p>Related posts:<ol><li><a href='http://briancray.com/2011/05/11/automatic-translator-javascript/' rel='bookmark' title='Permanent Link: Automatic translator built in javascript'>Automatic translator built in javascript</a></li>
<li><a href='http://briancray.com/2009/09/30/remove-value-javascript-array/' rel='bookmark' title='Permanent Link: How to remove a specific value from a javascript array'>How to remove a specific value from a javascript array</a></li>
<li><a href='http://briancray.com/2011/04/18/javascript-logical-operators/' rel='bookmark' title='Permanent Link: Diving deep into javascript logical operators'>Diving deep into javascript logical operators</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://briancray.com/2012/02/23/javascript-module-pattern/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Finding success as a web developer</title>
		<link>http://briancray.com/2011/05/19/finding-success-as-a-web-developer/</link>
		<comments>http://briancray.com/2011/05/19/finding-success-as-a-web-developer/#comments</comments>
		<pubDate>Thu, 19 May 2011 18:42:58 +0000</pubDate>
		<dc:creator>Brian Cray</dc:creator>
				<category><![CDATA[Web development]]></category>
		<category><![CDATA[commentary]]></category>
		<category><![CDATA[startups]]></category>

		<guid isPermaLink="false">http://briancray.com/?p=1880</guid>
		<description><![CDATA[Let me start by setting the record straight. I&#8217;m not going to tell you how to build a huge successful startup because I haven&#8217;t done it myself. But I have made a small name for myself, created a few minor successes, and hacked away a good path to follow (pun intended). Finding success as a [...]]]></description>
			<content:encoded><![CDATA[<p>Let me start by setting the record straight. <strong>I&#8217;m not going to tell you how to build a huge successful startup</strong> because I haven&#8217;t done it myself. But I <em>have</em> made a small name for myself, <a href="/portfolio/">created a few minor successes</a>, and hacked away a good path to follow (pun intended).</p>
<p>Finding success as a web developer means finding happiness and fulfillment&mdash;holistically just as much as monetarily. I&#8217;ll do my best to help you find your way. And hopefully, your next successful interview. So how should you start?</p>
<h3>Build <em>something</em>, then do it again</h3>
<p>I&#8217;ve been interviewing a lot of developers for <a href="http://topsy.com/">Topsy</a>. It&#8217;s amazing how many candidates don&#8217;t have a portfolio. After all, making something that people can publicly use is often their primary job description. I can tell you right now, the developer who has a portfolio is more likely to get a call than the one who doesn&#8217;t. Simple as that.</p>
<p>If you&#8217;re lacking ideas, pay attention to your daily work routine. When you find yourself thinking &#8220;This could be better&#8221; or &#8220;I wish I had ______,&#8221; you have your idea. An idea derived from this insight is likely a good one. Necessity is the mother of invention.</p>
<p>Do you have a good idea but you&#8217;re holding back for the right moment? <strong>Don&#8217;t wait for the right idea at the right time.</strong> Nobody is smart enough to solve that equation. Hell, who&#8217;d have thought that a photo taking app, Color, <a href="http://www.zdnet.com/blog/foremski/color-a-fascinating-41m-startup-with-an-app-that-tests-social-mores/1713">would raise $41 mil</a>? WTF. Stop thinking and start executing. <a href="http://www.paulgraham.com/startupmistakes.html">One of the biggest mistakes you can make is waiting too long</a>.</p>
<p><strong>And keep making stuff.</strong> Before you know it, you&#8217;ll have a few tasty examples of your prowess. Proven experience? Check. Broad understanding of web development and implementation? Check.</p>
<p>So why the <em>hell</em> aren&#8217;t you building something? Right this second? Shut up and build.</p>
<h3>Become a social developer</h3>
<p>No, I don&#8217;t mean you should go to more parties. I mean you should share your work, share your inspiration, and be involved in helping others make better stuff. Being a social developer builds your reputation and sharpens your skills <em>at the same time</em>.</p>
<p><strong>Absolutely the best medium for this is blogging.</strong> I hear a lot of people hesitant to start a blog because they don&#8217;t have stuff to write about. But here&#8217;s a simple place to start: if you&#8217;ve come up with a solution to a problem you&#8217;re working on, blog it. Chances are others are having a similar problem. <a href="http://briancray.com/2009/04/16/target-ie6-and-ie7-with-only-1-extra-character-in-your-css/">Even the simplest of solutions</a> may result in <a href="http://www.reddit.com/r/web_design/comments/8nlb2/target_ie6_and_ie7_with_only_1_extra_character_in">a lot of exposure</a>.</p>
<p>Another great social development opportunity is <a href="http://github.com/">GitHub</a>. Other than the <em>huge</em> benefit of having hosted version control, GitHub gives developers the opportunity to build solutions <em>together</em>. Others can follow your repositories and even fork them into new versions.</p>
<p>Combine your efforts by hosting the source code you blog on GitHub, providing exposure for your GitHub repositories and nurturing a deeper relationship with your readers. At the end of the day, discuss it on <a href="http://twitter.com/briancray">Twitter</a>.</p>
<h3>Keep learning</h3>
<p>I have the privilege to work with people who make me feel like I know nothing. Why? Because it inspires me to keep learning. The world we call our profession is constantly in a state of change. Hell, as a front-end engineer I don&#8217;t know half of what I should.</p>
<p>If you only have a hammer, everything looks like a nail. Learning not only makes us more resourceful and valuable, but it helps us approach problems with a much broader knowledge base for making informed, sustainable solutions.  A <a href="http://lwn.net/Articles/441790/">great article about scaling from the perspective of a database architect</a> starts with <strong>&#8220;Let me tell you a secret. I don&#8217;t fix databases. I fix applications.&#8221;</strong> To me this means designing the best solution to a problem requires more than applying your field of study. It requires the ability to look at a problem from a number of angles. <em>Expand your toolbox.</em></p>
<p>And if you&#8217;ve managed to conquer all the languages of the programming world, pick up a few books on psychology, marketing, and social behavior. Learn, learn, learn.</p>
<h3>Befriend failure</h3>
<p>Failure is inevitable, and likely to happen more often than you&#8217;d like. Don&#8217;t quit if you fail at first. <strong>The only chance you have of winning is by fighting.</strong> Failures are hidden morsels of life&#8217;s greatest opportunities to learn. They give us the arsenal to fight the better fight. In the business world that translates to more success however you define it. But don&#8217;t take it from me.</p>
<ul>
<li><a href="http://www.entrepreneur.com/magazine/entrepreneur/2008/december/198516.html">Entrepreneur.com says</a> &#8220;You&#8217;re fortunate to have failed. You now have the opportunity to learn how to turn bad luck into good luck. If you can do that, you&#8217;ll have a life of more and more good luck.&#8221;</li>
<li><a href="http://onstartups.com/tabid/3339/bid/47646/Insight-From-Dropbox-Failure-Is-Not-The-Worst-Outcome-Mediocrity-Is.aspx">Dropbox says</a> &#8220;Failure is not the worst outcome, mediocrity is.&#8221;</li>
<li><a href="http://steveblank.com/2009/11/12/%E2%80%9Clessons-learned%E2%80%9D-%E2%80%93-a-new-type-of-vc-pitch/">CafePress says</a> &#8220;Fail fast and cheap. And learn from it.&#8221;</li>
</ul>
<h3>Love what you do</h3>
<p>The last but most important aspect of finding success as a web developer is to love what you do. Ask yourself this simple question: If you weren&#8217;t being paid for web development, would you still be doing it? If the answer is yes, you&#8217;re almost certainly bound for success.</p>


<p>Related posts:<ol><li><a href='http://briancray.com/2010/01/28/innovative-web-team/' rel='bookmark' title='Permanent Link: How to promote innovation from your web team'>How to promote innovation from your web team</a></li>
<li><a href='http://briancray.com/2010/11/10/surviving-silicon-valley/' rel='bookmark' title='Permanent Link: Surviving Silicon Valley'>Surviving Silicon Valley</a></li>
<li><a href='http://briancray.com/2009/07/09/best-long-tail-seo-keywords-web-analytics/' rel='bookmark' title='Permanent Link: My secret to finding the best long-tail SEO keywords with web analytics'>My secret to finding the best long-tail SEO keywords with web analytics</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://briancray.com/2011/05/19/finding-success-as-a-web-developer/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Automatic translator built in javascript</title>
		<link>http://briancray.com/2011/05/11/automatic-translator-javascript/</link>
		<comments>http://briancray.com/2011/05/11/automatic-translator-javascript/#comments</comments>
		<pubDate>Wed, 11 May 2011 16:39:39 +0000</pubDate>
		<dc:creator>Brian Cray</dc:creator>
				<category><![CDATA[User experience]]></category>
		<category><![CDATA[Web development]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://briancray.com/?p=1878</guid>
		<description><![CDATA[When it comes to my blog, I&#8217;m always asking myself the same question: How can I make my content more engaging? I try to avoid so called &#8220;enhancements&#8221; like arbitrary visual embellishments or every-which-way navigation that distracts users from what they came for: a good read. I do my best to focus solely on making [...]]]></description>
			<content:encoded><![CDATA[<p>When it comes to my blog, I&#8217;m always asking myself the same question: How can I make my content more engaging? I try to avoid so called &#8220;enhancements&#8221; like arbitrary visual embellishments or every-which-way navigation that distracts users from what they came for: a good read. I do my best to focus solely on making the content great.</p>
<p>I&#8217;ve done some playing in this area in the past, including <a href="http://briancray.com/2010/04/09/estimated-reading-time-web-design/">estimated reading time</a> and <a href="http://briancray.com/2010/02/03/measuring-simplicity-in-web-design/">measuring simplicity</a>. The other day, I thought I&#8217;d try something new. This is what I ended up with.</p>
<h3>Javascript translation: How does it work?</h3>
<ol>
<li>Detect the user&#8217;s Country Code using google.loader.ClientLocation (I&#8217;ve written about this <a href="http://briancray.com/2009/05/29/find-web-visitors-location-javascript-google-api/">here</a>)</li>
<li>Translates the Country Code into a two digit language code</li>
<li>If the user has a different native language, redirect the browser to a translated version of the page</li>
</ol>
<h3>A look at the source</h3>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> loaded <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
    test_cc <span style="color: #339933;">=</span> window.<span style="color: #660066;">test_cc</span> <span style="color: #339933;">?</span> test_cc <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
    test_url <span style="color: #339933;">=</span> window.<span style="color: #660066;">test_url</span> <span style="color: #339933;">?</span> test_url <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #003366; font-weight: bold;">var</span> inject_jsapi <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">var</span> h <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'head'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #003366; font-weight: bold;">var</span> s <span style="color: #339933;">=</span> document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'script'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        s.<span style="color: #660066;">type</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'text/javascript'</span><span style="color: #339933;">;</span>
        s.<span style="color: #660066;">onreadystatechange</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">readyState</span> <span style="color: #339933;">===</span> <span style="color: #3366CC;">'loaded'</span> <span style="color: #339933;">||</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">readyState</span> <span style="color: #339933;">===</span> <span style="color: #3366CC;">'complete'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                translate<span style="color: #009900;">&#40;</span>test_cc <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span>google.<span style="color: #660066;">loader</span>.<span style="color: #660066;">ClientLocation</span> <span style="color: #339933;">&amp;&amp;</span> google.<span style="color: #660066;">loader</span>.<span style="color: #660066;">ClientLocation</span>.<span style="color: #660066;">address</span>.<span style="color: #660066;">country_code</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'en'</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: #339933;">;</span>
        s.<span style="color: #000066;">onload</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            translate<span style="color: #009900;">&#40;</span>test_cc <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span>google.<span style="color: #660066;">loader</span>.<span style="color: #660066;">ClientLocation</span> <span style="color: #339933;">&amp;&amp;</span> google.<span style="color: #660066;">loader</span>.<span style="color: #660066;">ClientLocation</span>.<span style="color: #660066;">address</span>.<span style="color: #660066;">country_code</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'en'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
        s.<span style="color: #660066;">src</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'http://www.google.com/jsapi'</span><span style="color: #339933;">;</span>
        h.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>s<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #003366; font-weight: bold;">var</span> translate <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>cc<span style="color: #339933;">,</span> lang<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>cc <span style="color: #339933;">||</span> loaded<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        loaded <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
&nbsp;
        cc <span style="color: #339933;">=</span> cc.<span style="color: #660066;">toLowerCase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #006600; font-style: italic;">// http://www.mobilefish.com/tutorials/country_language_codes/countrylanguagecodes.html</span>
        <span style="color: #003366; font-weight: bold;">var</span> cc2lang <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
            af<span style="color: #339933;">:</span> <span style="color: #3366CC;">'fa'</span><span style="color: #339933;">,</span> ax<span style="color: #339933;">:</span> <span style="color: #3366CC;">'sv'</span><span style="color: #339933;">,</span> al<span style="color: #339933;">:</span> <span style="color: #3366CC;">'sq'</span><span style="color: #339933;">,</span> dz<span style="color: #339933;">:</span> <span style="color: #3366CC;">'ar'</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">as</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'sm'</span><span style="color: #339933;">,</span> ad<span style="color: #339933;">:</span> <span style="color: #3366CC;">'ca'</span><span style="color: #339933;">,</span>
            ao<span style="color: #339933;">:</span> <span style="color: #3366CC;">'pt'</span><span style="color: #339933;">,</span> ai<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span> aq<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span> ag<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span> ar<span style="color: #339933;">:</span> <span style="color: #3366CC;">'es'</span><span style="color: #339933;">,</span> am<span style="color: #339933;">:</span> <span style="color: #3366CC;">'hy'</span><span style="color: #339933;">,</span>
            aw<span style="color: #339933;">:</span> <span style="color: #3366CC;">'nl'</span><span style="color: #339933;">,</span> ac<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span> au<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span> at<span style="color: #339933;">:</span> <span style="color: #3366CC;">'de'</span><span style="color: #339933;">,</span> az<span style="color: #339933;">:</span> <span style="color: #3366CC;">'az'</span><span style="color: #339933;">,</span> bs<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span>
            bh<span style="color: #339933;">:</span> <span style="color: #3366CC;">'ar'</span><span style="color: #339933;">,</span> bd<span style="color: #339933;">:</span> <span style="color: #3366CC;">'bn'</span><span style="color: #339933;">,</span> bb<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span> by<span style="color: #339933;">:</span> <span style="color: #3366CC;">'be'</span><span style="color: #339933;">,</span> be<span style="color: #339933;">:</span> <span style="color: #3366CC;">'de'</span><span style="color: #339933;">,</span> bz<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span>
            bj<span style="color: #339933;">:</span> <span style="color: #3366CC;">'fr'</span><span style="color: #339933;">,</span> bm<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span> bt<span style="color: #339933;">:</span> <span style="color: #3366CC;">'dz'</span><span style="color: #339933;">,</span> bo<span style="color: #339933;">:</span> <span style="color: #3366CC;">'es'</span><span style="color: #339933;">,</span> ba<span style="color: #339933;">:</span> <span style="color: #3366CC;">'bs'</span><span style="color: #339933;">,</span> bw<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span>
            br<span style="color: #339933;">:</span> <span style="color: #3366CC;">'pt'</span><span style="color: #339933;">,</span> io<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span> bn<span style="color: #339933;">:</span> <span style="color: #3366CC;">'ms'</span><span style="color: #339933;">,</span> bg<span style="color: #339933;">:</span> <span style="color: #3366CC;">'bg'</span><span style="color: #339933;">,</span> bf<span style="color: #339933;">:</span> <span style="color: #3366CC;">'fr'</span><span style="color: #339933;">,</span> bi<span style="color: #339933;">:</span> <span style="color: #3366CC;">'fr'</span><span style="color: #339933;">,</span>
            kh<span style="color: #339933;">:</span> <span style="color: #3366CC;">'km'</span><span style="color: #339933;">,</span> cm<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span> ca<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span> cv<span style="color: #339933;">:</span> <span style="color: #3366CC;">'pt'</span><span style="color: #339933;">,</span> ky<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span> cf<span style="color: #339933;">:</span> <span style="color: #3366CC;">'fr'</span><span style="color: #339933;">,</span>
            td<span style="color: #339933;">:</span> <span style="color: #3366CC;">'fr'</span><span style="color: #339933;">,</span> cl<span style="color: #339933;">:</span> <span style="color: #3366CC;">'es'</span><span style="color: #339933;">,</span> cn<span style="color: #339933;">:</span> <span style="color: #3366CC;">'zh'</span><span style="color: #339933;">,</span> cx<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span> cc<span style="color: #339933;">:</span> <span style="color: #3366CC;">'ms'</span><span style="color: #339933;">,</span> co<span style="color: #339933;">:</span> <span style="color: #3366CC;">'es'</span><span style="color: #339933;">,</span>
            km<span style="color: #339933;">:</span> <span style="color: #3366CC;">'ar'</span><span style="color: #339933;">,</span> cg<span style="color: #339933;">:</span> <span style="color: #3366CC;">'fr'</span><span style="color: #339933;">,</span> cd<span style="color: #339933;">:</span> <span style="color: #3366CC;">'fr'</span><span style="color: #339933;">,</span> ck<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span> cr<span style="color: #339933;">:</span> <span style="color: #3366CC;">'es'</span><span style="color: #339933;">,</span> ci<span style="color: #339933;">:</span> <span style="color: #3366CC;">'fr'</span><span style="color: #339933;">,</span>
            hr<span style="color: #339933;">:</span> <span style="color: #3366CC;">'hr'</span><span style="color: #339933;">,</span> cu<span style="color: #339933;">:</span> <span style="color: #3366CC;">'es'</span><span style="color: #339933;">,</span> cy<span style="color: #339933;">:</span> <span style="color: #3366CC;">'el'</span><span style="color: #339933;">,</span> cz<span style="color: #339933;">:</span> <span style="color: #3366CC;">'cs'</span><span style="color: #339933;">,</span> dk<span style="color: #339933;">:</span> <span style="color: #3366CC;">'da'</span><span style="color: #339933;">,</span> dj<span style="color: #339933;">:</span> <span style="color: #3366CC;">'fr'</span><span style="color: #339933;">,</span>
            dm<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'do'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'es'</span><span style="color: #339933;">,</span> ec<span style="color: #339933;">:</span> <span style="color: #3366CC;">'es'</span><span style="color: #339933;">,</span> eg<span style="color: #339933;">:</span> <span style="color: #3366CC;">'ar'</span><span style="color: #339933;">,</span> sv<span style="color: #339933;">:</span> <span style="color: #3366CC;">'es'</span><span style="color: #339933;">,</span> gq<span style="color: #339933;">:</span> <span style="color: #3366CC;">'es'</span><span style="color: #339933;">,</span>
            er<span style="color: #339933;">:</span> <span style="color: #3366CC;">'ti'</span><span style="color: #339933;">,</span> ee<span style="color: #339933;">:</span> <span style="color: #3366CC;">'et'</span><span style="color: #339933;">,</span> et<span style="color: #339933;">:</span> <span style="color: #3366CC;">'am'</span><span style="color: #339933;">,</span> eu<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span> fk<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span> fo<span style="color: #339933;">:</span> <span style="color: #3366CC;">'fo'</span><span style="color: #339933;">,</span>
            fj<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span> fi<span style="color: #339933;">:</span> <span style="color: #3366CC;">'fi'</span><span style="color: #339933;">,</span> fr<span style="color: #339933;">:</span> <span style="color: #3366CC;">'fr'</span><span style="color: #339933;">,</span> gf<span style="color: #339933;">:</span> <span style="color: #3366CC;">'fr'</span><span style="color: #339933;">,</span> pf<span style="color: #339933;">:</span> <span style="color: #3366CC;">'fr'</span><span style="color: #339933;">,</span> tf<span style="color: #339933;">:</span> <span style="color: #3366CC;">'fr'</span><span style="color: #339933;">,</span>
            ga<span style="color: #339933;">:</span> <span style="color: #3366CC;">'fr'</span><span style="color: #339933;">,</span> gm<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span> ge<span style="color: #339933;">:</span> <span style="color: #3366CC;">'ka'</span><span style="color: #339933;">,</span> de<span style="color: #339933;">:</span> <span style="color: #3366CC;">'de'</span><span style="color: #339933;">,</span> gh<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span> gi<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span>
            gr<span style="color: #339933;">:</span> <span style="color: #3366CC;">'el'</span><span style="color: #339933;">,</span> gl<span style="color: #339933;">:</span> <span style="color: #3366CC;">'kl'</span><span style="color: #339933;">,</span> gd<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span> gp<span style="color: #339933;">:</span> <span style="color: #3366CC;">'fr'</span><span style="color: #339933;">,</span> gu<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span> gt<span style="color: #339933;">:</span> <span style="color: #3366CC;">'es'</span><span style="color: #339933;">,</span>
            gg<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span> gn<span style="color: #339933;">:</span> <span style="color: #3366CC;">'fr'</span><span style="color: #339933;">,</span> gw<span style="color: #339933;">:</span> <span style="color: #3366CC;">'pt'</span><span style="color: #339933;">,</span> gy<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span> ht<span style="color: #339933;">:</span> <span style="color: #3366CC;">'fr'</span><span style="color: #339933;">,</span> va<span style="color: #339933;">:</span> <span style="color: #3366CC;">'lt'</span><span style="color: #339933;">,</span>
            hn<span style="color: #339933;">:</span> <span style="color: #3366CC;">'es'</span><span style="color: #339933;">,</span> hk<span style="color: #339933;">:</span> <span style="color: #3366CC;">'zh'</span><span style="color: #339933;">,</span> hu<span style="color: #339933;">:</span> <span style="color: #3366CC;">'hu'</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">is</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'is'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'in'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'hi'</span><span style="color: #339933;">,</span> id<span style="color: #339933;">:</span> <span style="color: #3366CC;">'id'</span><span style="color: #339933;">,</span>
            ir<span style="color: #339933;">:</span> <span style="color: #3366CC;">'fa'</span><span style="color: #339933;">,</span> iq<span style="color: #339933;">:</span> <span style="color: #3366CC;">'ar'</span><span style="color: #339933;">,</span> ie<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span> im<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span> il<span style="color: #339933;">:</span> <span style="color: #3366CC;">'he'</span><span style="color: #339933;">,</span> it<span style="color: #339933;">:</span> <span style="color: #3366CC;">'it'</span><span style="color: #339933;">,</span>
            jm<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span> jp<span style="color: #339933;">:</span> <span style="color: #3366CC;">'ja'</span><span style="color: #339933;">,</span> je<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span> jo<span style="color: #339933;">:</span> <span style="color: #3366CC;">'ar'</span><span style="color: #339933;">,</span> kz<span style="color: #339933;">:</span> <span style="color: #3366CC;">'kk'</span><span style="color: #339933;">,</span> ke<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span>
            ki<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span> kp<span style="color: #339933;">:</span> <span style="color: #3366CC;">'ko'</span><span style="color: #339933;">,</span> kr<span style="color: #339933;">:</span> <span style="color: #3366CC;">'ko'</span><span style="color: #339933;">,</span> kw<span style="color: #339933;">:</span> <span style="color: #3366CC;">'ar'</span><span style="color: #339933;">,</span> kg<span style="color: #339933;">:</span> <span style="color: #3366CC;">'ky'</span><span style="color: #339933;">,</span> la<span style="color: #339933;">:</span> <span style="color: #3366CC;">'lo'</span><span style="color: #339933;">,</span>
            lv<span style="color: #339933;">:</span> <span style="color: #3366CC;">'lv'</span><span style="color: #339933;">,</span> lb<span style="color: #339933;">:</span> <span style="color: #3366CC;">'ar'</span><span style="color: #339933;">,</span> ls<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span> lr<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span> ly<span style="color: #339933;">:</span> <span style="color: #3366CC;">'ar'</span><span style="color: #339933;">,</span> li<span style="color: #339933;">:</span> <span style="color: #3366CC;">'de'</span><span style="color: #339933;">,</span>
            lt<span style="color: #339933;">:</span> <span style="color: #3366CC;">'lt'</span><span style="color: #339933;">,</span> lu<span style="color: #339933;">:</span> <span style="color: #3366CC;">'de'</span><span style="color: #339933;">,</span> mo<span style="color: #339933;">:</span> <span style="color: #3366CC;">'zh'</span><span style="color: #339933;">,</span> mk<span style="color: #339933;">:</span> <span style="color: #3366CC;">'mk'</span><span style="color: #339933;">,</span> mg<span style="color: #339933;">:</span> <span style="color: #3366CC;">'mg'</span><span style="color: #339933;">,</span> mw<span style="color: #339933;">:</span> <span style="color: #3366CC;">'ny'</span><span style="color: #339933;">,</span>
            my<span style="color: #339933;">:</span> <span style="color: #3366CC;">'ms'</span><span style="color: #339933;">,</span> mv<span style="color: #339933;">:</span> <span style="color: #3366CC;">'dv'</span><span style="color: #339933;">,</span> ml<span style="color: #339933;">:</span> <span style="color: #3366CC;">'fr'</span><span style="color: #339933;">,</span> mt<span style="color: #339933;">:</span> <span style="color: #3366CC;">'mt'</span><span style="color: #339933;">,</span> mh<span style="color: #339933;">:</span> <span style="color: #3366CC;">'mh'</span><span style="color: #339933;">,</span> mq<span style="color: #339933;">:</span> <span style="color: #3366CC;">'fr'</span><span style="color: #339933;">,</span>
            mr<span style="color: #339933;">:</span> <span style="color: #3366CC;">'ar'</span><span style="color: #339933;">,</span> mu<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span> yt<span style="color: #339933;">:</span> <span style="color: #3366CC;">'fr'</span><span style="color: #339933;">,</span> mx<span style="color: #339933;">:</span> <span style="color: #3366CC;">'es'</span><span style="color: #339933;">,</span> fm<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span> md<span style="color: #339933;">:</span> <span style="color: #3366CC;">'mo'</span><span style="color: #339933;">,</span>
            mc<span style="color: #339933;">:</span> <span style="color: #3366CC;">'fr'</span><span style="color: #339933;">,</span> mn<span style="color: #339933;">:</span> <span style="color: #3366CC;">'mn'</span><span style="color: #339933;">,</span> me<span style="color: #339933;">:</span> <span style="color: #3366CC;">'sr'</span><span style="color: #339933;">,</span> ms<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span> ma<span style="color: #339933;">:</span> <span style="color: #3366CC;">'ar'</span><span style="color: #339933;">,</span> mz<span style="color: #339933;">:</span> <span style="color: #3366CC;">'pt'</span><span style="color: #339933;">,</span>
            mm<span style="color: #339933;">:</span> <span style="color: #3366CC;">'my'</span><span style="color: #339933;">,</span> na<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span> nr<span style="color: #339933;">:</span> <span style="color: #3366CC;">'na'</span><span style="color: #339933;">,</span> np<span style="color: #339933;">:</span> <span style="color: #3366CC;">'ne'</span><span style="color: #339933;">,</span> nl<span style="color: #339933;">:</span> <span style="color: #3366CC;">'nl'</span><span style="color: #339933;">,</span> an<span style="color: #339933;">:</span> <span style="color: #3366CC;">'nl'</span><span style="color: #339933;">,</span>
            nc<span style="color: #339933;">:</span> <span style="color: #3366CC;">'fr'</span><span style="color: #339933;">,</span> nz<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span> ni<span style="color: #339933;">:</span> <span style="color: #3366CC;">'es'</span><span style="color: #339933;">,</span> ne<span style="color: #339933;">:</span> <span style="color: #3366CC;">'fr'</span><span style="color: #339933;">,</span> ng<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span> nu<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span>
            nf<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span> mp<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span> no<span style="color: #339933;">:</span> <span style="color: #3366CC;">'no'</span><span style="color: #339933;">,</span> om<span style="color: #339933;">:</span> <span style="color: #3366CC;">'ar'</span><span style="color: #339933;">,</span> pk<span style="color: #339933;">:</span> <span style="color: #3366CC;">'ur'</span><span style="color: #339933;">,</span> pw<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span>
            ps<span style="color: #339933;">:</span> <span style="color: #3366CC;">'ar'</span><span style="color: #339933;">,</span> pa<span style="color: #339933;">:</span> <span style="color: #3366CC;">'es'</span><span style="color: #339933;">,</span> pg<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span> py<span style="color: #339933;">:</span> <span style="color: #3366CC;">'es'</span><span style="color: #339933;">,</span> pe<span style="color: #339933;">:</span> <span style="color: #3366CC;">'es'</span><span style="color: #339933;">,</span> ph<span style="color: #339933;">:</span> <span style="color: #3366CC;">'tl'</span><span style="color: #339933;">,</span>
            pn<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span> pl<span style="color: #339933;">:</span> <span style="color: #3366CC;">'pl'</span><span style="color: #339933;">,</span> pt<span style="color: #339933;">:</span> <span style="color: #3366CC;">'pt'</span><span style="color: #339933;">,</span> pr<span style="color: #339933;">:</span> <span style="color: #3366CC;">'es'</span><span style="color: #339933;">,</span> qa<span style="color: #339933;">:</span> <span style="color: #3366CC;">'ar'</span><span style="color: #339933;">,</span> re<span style="color: #339933;">:</span> <span style="color: #3366CC;">'fr'</span><span style="color: #339933;">,</span>
            ro<span style="color: #339933;">:</span> <span style="color: #3366CC;">'ro'</span><span style="color: #339933;">,</span> ru<span style="color: #339933;">:</span> <span style="color: #3366CC;">'ru'</span><span style="color: #339933;">,</span> rw<span style="color: #339933;">:</span> <span style="color: #3366CC;">'rw'</span><span style="color: #339933;">,</span> bl<span style="color: #339933;">:</span> <span style="color: #3366CC;">'fr'</span><span style="color: #339933;">,</span> sh<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span> kn<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span>
            lc<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span> pm<span style="color: #339933;">:</span> <span style="color: #3366CC;">'fr'</span><span style="color: #339933;">,</span> vc<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span> ws<span style="color: #339933;">:</span> <span style="color: #3366CC;">'sm'</span><span style="color: #339933;">,</span> sm<span style="color: #339933;">:</span> <span style="color: #3366CC;">'it'</span><span style="color: #339933;">,</span> st<span style="color: #339933;">:</span> <span style="color: #3366CC;">'pt'</span><span style="color: #339933;">,</span>
            sa<span style="color: #339933;">:</span> <span style="color: #3366CC;">'ar'</span><span style="color: #339933;">,</span> sn<span style="color: #339933;">:</span> <span style="color: #3366CC;">'fr'</span><span style="color: #339933;">,</span> rs<span style="color: #339933;">:</span> <span style="color: #3366CC;">'sr'</span><span style="color: #339933;">,</span> sc<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span> sl<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span> sg<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span>
            sk<span style="color: #339933;">:</span> <span style="color: #3366CC;">'sk'</span><span style="color: #339933;">,</span> si<span style="color: #339933;">:</span> <span style="color: #3366CC;">'sl'</span><span style="color: #339933;">,</span> sb<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span> so<span style="color: #339933;">:</span> <span style="color: #3366CC;">'so'</span><span style="color: #339933;">,</span> za<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span> gs<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span>
            es<span style="color: #339933;">:</span> <span style="color: #3366CC;">'es'</span><span style="color: #339933;">,</span> lk<span style="color: #339933;">:</span> <span style="color: #3366CC;">'si'</span><span style="color: #339933;">,</span> sd<span style="color: #339933;">:</span> <span style="color: #3366CC;">'ar'</span><span style="color: #339933;">,</span> sr<span style="color: #339933;">:</span> <span style="color: #3366CC;">'nl'</span><span style="color: #339933;">,</span> sj<span style="color: #339933;">:</span> <span style="color: #3366CC;">'no'</span><span style="color: #339933;">,</span> sz<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span>
            se<span style="color: #339933;">:</span> <span style="color: #3366CC;">'sv'</span><span style="color: #339933;">,</span> ch<span style="color: #339933;">:</span> <span style="color: #3366CC;">'de'</span><span style="color: #339933;">,</span> sy<span style="color: #339933;">:</span> <span style="color: #3366CC;">'ar'</span><span style="color: #339933;">,</span> tw<span style="color: #339933;">:</span> <span style="color: #3366CC;">'zh'</span><span style="color: #339933;">,</span> tj<span style="color: #339933;">:</span> <span style="color: #3366CC;">'tg'</span><span style="color: #339933;">,</span> tz<span style="color: #339933;">:</span> <span style="color: #3366CC;">'sw'</span><span style="color: #339933;">,</span>
            th<span style="color: #339933;">:</span> <span style="color: #3366CC;">'th'</span><span style="color: #339933;">,</span> tl<span style="color: #339933;">:</span> <span style="color: #3366CC;">'pt'</span><span style="color: #339933;">,</span> tg<span style="color: #339933;">:</span> <span style="color: #3366CC;">'fr'</span><span style="color: #339933;">,</span> tk<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span> to<span style="color: #339933;">:</span> <span style="color: #3366CC;">'to'</span><span style="color: #339933;">,</span> tt<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span>
            tn<span style="color: #339933;">:</span> <span style="color: #3366CC;">'ar'</span><span style="color: #339933;">,</span> tr<span style="color: #339933;">:</span> <span style="color: #3366CC;">'tr'</span><span style="color: #339933;">,</span> tm<span style="color: #339933;">:</span> <span style="color: #3366CC;">'tk'</span><span style="color: #339933;">,</span> tc<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span> tv<span style="color: #339933;">:</span> <span style="color: #3366CC;">'tv'</span><span style="color: #339933;">,</span> ug<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span>
            ua<span style="color: #339933;">:</span> <span style="color: #3366CC;">'uk'</span><span style="color: #339933;">,</span> ae<span style="color: #339933;">:</span> <span style="color: #3366CC;">'ar'</span><span style="color: #339933;">,</span> gb<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span> us<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span> um<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span> uy<span style="color: #339933;">:</span> <span style="color: #3366CC;">'es'</span><span style="color: #339933;">,</span>
            vn<span style="color: #339933;">:</span> <span style="color: #3366CC;">'vi'</span><span style="color: #339933;">,</span> vg<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span> vi<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span> wf<span style="color: #339933;">:</span> <span style="color: #3366CC;">'fr'</span><span style="color: #339933;">,</span> eh<span style="color: #339933;">:</span> <span style="color: #3366CC;">'ar'</span><span style="color: #339933;">,</span> ye<span style="color: #339933;">:</span> <span style="color: #3366CC;">'ar'</span><span style="color: #339933;">,</span>
            yu<span style="color: #339933;">:</span> <span style="color: #3366CC;">'hr'</span><span style="color: #339933;">,</span> zm<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span><span style="color: #339933;">,</span> zw<span style="color: #339933;">:</span> <span style="color: #3366CC;">'en'</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>cc <span style="color: #339933;">&amp;&amp;</span> cc2lang<span style="color: #009900;">&#91;</span>cc<span style="color: #009900;">&#93;</span> <span style="color: #339933;">&amp;&amp;</span> cc2lang<span style="color: #009900;">&#91;</span>cc<span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> lang<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>uri<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                document.<span style="color: #660066;">location</span>.<span style="color: #660066;">href</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'http://translate.google.com/translate?langpair='</span> <span style="color: #339933;">+</span> lang <span style="color: #339933;">+</span> <span style="color: #3366CC;">'|'</span> <span style="color: #339933;">+</span> cc2lang<span style="color: #009900;">&#91;</span>cc<span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&amp;u='</span> <span style="color: #339933;">+</span> uri<span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>test_url <span style="color: #339933;">||</span> document.<span style="color: #660066;">location</span>.<span style="color: #660066;">href</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: #339933;">;</span>
&nbsp;
    inject_jsapi<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: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h3>More on GitHub</h3>
<p>If you&#8217;re a <a href="http://www.github.com/">GitHub</a> fan, feel free to <a href="https://github.com/briancray/Automatic-translator">follow, fork, or play with the source on GitHub</a>.</p>


<p>Related posts:<ol><li><a href='http://briancray.com/2009/05/29/find-web-visitors-location-javascript-google-api/' rel='bookmark' title='Permanent Link: Find web visitor&#8217;s location automatically with javascript and Google APIs'>Find web visitor&#8217;s location automatically with javascript and Google APIs</a></li>
<li><a href='http://briancray.com/2009/04/01/how-to-calculate-the-distance-between-two-addresses-with-javascript-and-google-maps-api/' rel='bookmark' title='Permanent Link: How to calculate distance with javascript and Google Maps API'>How to calculate distance with javascript and Google Maps API</a></li>
<li><a href='http://briancray.com/2009/12/07/javascript-find-value-string-key-multidimensional-array-object/' rel='bookmark' title='Permanent Link: Javascript snippet: Find the value of a string key in a multidimensional array or object'>Javascript snippet: Find the value of a string key in a multidimensional array or object</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://briancray.com/2011/05/11/automatic-translator-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Detect retina displays with javascript</title>
		<link>http://briancray.com/2011/05/05/detect-retina-displays-with-javascript/</link>
		<comments>http://briancray.com/2011/05/05/detect-retina-displays-with-javascript/#comments</comments>
		<pubDate>Thu, 05 May 2011 18:08:17 +0000</pubDate>
		<dc:creator>Brian Cray</dc:creator>
				<category><![CDATA[User experience]]></category>
		<category><![CDATA[Web development]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[mobile]]></category>

		<guid isPermaLink="false">http://briancray.com/?p=1876</guid>
		<description><![CDATA[I&#8217;ve been trying a way to detect a device&#8217;s DPI for mobile design. While I haven&#8217;t yet, I did at least find a way to detect whether the user is using a retina display. So without ado, here&#8217;s how: var retina = window.devicePixelRatio &#62; 1 ? true : false; Now the variable retina will be [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been trying a way to detect a device&#8217;s DPI for mobile design. While I haven&#8217;t yet, I did at least find a way to detect whether the user is using a retina display. So without ado, here&#8217;s how:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> retina <span style="color: #339933;">=</span> window.<span style="color: #660066;">devicePixelRatio</span> <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">1</span> <span style="color: #339933;">?</span> <span style="color: #003366; font-weight: bold;">true</span> <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span></pre></div></div>

<p>Now the variable <code>retina</code> will be set to <code>true</code> if the user has a retina display. A simple <code>if</code> statement can be used anywhere to execute code based on the user&#8217;s display.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>retina<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">// the user has a retina display</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">// the user has a non-retina display</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h3>Why?</h3>
<p>A good is example is if I have a 100&#215;100 image (or video), the above code will tell me to upscale the image to 200&#215;200 for it to look crisp on an iPhone 4 without forcing all users to unnecessarily download a 200&#215;200 image. Especially given bandwidth is a major concern for mobile users.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>retina<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> html <span style="color: #339933;">=</span> <span style="color: #3366CC;">'&lt;img src=&quot;my-high-res-image.jpg&quot;&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> html <span style="color: #339933;">=</span> <span style="color: #3366CC;">'&lt;img src=&quot;my-low-res-image.jpg&quot;&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>



<p>Related posts:<ol><li><a href='http://briancray.com/2011/04/18/javascript-logical-operators/' rel='bookmark' title='Permanent Link: Diving deep into javascript logical operators'>Diving deep into javascript logical operators</a></li>
<li><a href='http://briancray.com/2009/04/01/how-to-calculate-the-distance-between-two-addresses-with-javascript-and-google-maps-api/' rel='bookmark' title='Permanent Link: How to calculate distance with javascript and Google Maps API'>How to calculate distance with javascript and Google Maps API</a></li>
<li><a href='http://briancray.com/2009/05/29/find-web-visitors-location-javascript-google-api/' rel='bookmark' title='Permanent Link: Find web visitor&#8217;s location automatically with javascript and Google APIs'>Find web visitor&#8217;s location automatically with javascript and Google APIs</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://briancray.com/2011/05/05/detect-retina-displays-with-javascript/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Diving deep into javascript logical operators</title>
		<link>http://briancray.com/2011/04/18/javascript-logical-operators/</link>
		<comments>http://briancray.com/2011/04/18/javascript-logical-operators/#comments</comments>
		<pubDate>Mon, 18 Apr 2011 16:49:39 +0000</pubDate>
		<dc:creator>Brian Cray</dc:creator>
				<category><![CDATA[Web development]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://briancray.com/?p=1875</guid>
		<description><![CDATA[I have lots of fun finding shortcuts in javascript, and logical operators can make for some interesting ways to act on a condition. In this article we&#8217;ll look at the logical operators &#038;&#038; (read: AND) and &#124;&#124; (read: OR). A few things to keep in mind: Although some of these examples can also be accomplished [...]]]></description>
			<content:encoded><![CDATA[<p>I have lots of fun finding shortcuts in javascript, and logical operators can make for some interesting ways to act on a condition. In this article we&#8217;ll look at the logical operators <code>&#038;&#038;</code> (read: AND) and <code>||</code> (read: OR).</p>
<p>A few things to keep in mind:</p>
<ul>
<li>Although some of these examples can also be accomplished with a conditional operator (<code>condition ? expr1 : expr2</code>), the point of this article is to explore the potential of logical operators.</li>
<li>Javascript evaluates logical operators from left-to-right, which means it evaluates what&#8217;s on the left of a logical operator before evaluating what&#8217;s on the right. So in <code>a &#038;&#038; b</code>, <code>a</code> is evaluated before <code>b</code>.</li>
<li>In the examples below, <code>true</code> and <code>false</code> simply represent anything (variable, function, etc) that evaluates to <code>true</code> or <code>false</code> respectively.</li>
<li>Don&#8217;t let shortcuts break code readability and maintainability. If your use of logical operators as a shortcut becomes to cryptic/complex, you may find yourself losing your mind.</p>
</ul>
<h3>If else, without the if else</h3>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// traditional</span>
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	do_this<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: #006600; font-style: italic;">// alternative method with &amp;&amp;</span>
<span style="color: #003366; font-weight: bold;">true</span> <span style="color: #339933;">&amp;&amp;</span> do_this<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// traditional</span>
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	do_this<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: #006600; font-style: italic;">// alternative method with ||</span>
<span style="color: #003366; font-weight: bold;">false</span> <span style="color: #339933;">||</span> dont_do_this<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// do multiple things via anonymous wrapper</span>
<span style="color: #003366; font-weight: bold;">true</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	do_this<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	and_this<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: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// real example - test if DOM object exists before acting on it</span>
jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#alert'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">length</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> el <span style="color: #339933;">=</span> jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#alert'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	el.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	window.<span style="color: #660066;">setTimeout</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		el.<span style="color: #660066;">hide</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: #339933;">,</span> <span style="color: #CC0000;">5000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h3>Conditional assignment</h3>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// setting defaults with ||</span>
<span style="color: #003366; font-weight: bold;">var</span> my_setting <span style="color: #339933;">=</span> optional_setting <span style="color: #339933;">||</span> <span style="color: #003366; font-weight: bold;">default</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// real example - if input#email is blank, defaults to none@none.com with ||</span>
<span style="color: #003366; font-weight: bold;">var</span> email <span style="color: #339933;">=</span> jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#email'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #3366CC;">'none@none.com'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// setting value only if something else is true with &amp;&amp;</span>
<span style="color: #003366; font-weight: bold;">var</span> my_setting <span style="color: #339933;">=</span> test_me <span style="color: #339933;">&amp;&amp;</span> setting<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// real example - setting email if valid with &amp;&amp;</span>
<span style="color: #003366; font-weight: bold;">var</span> email <span style="color: #339933;">=</span> jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#email'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">search</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'/[<span style="color: #000099; font-weight: bold;">\d</span><span style="color: #000099; font-weight: bold;">\w</span><span style="color: #000099; font-weight: bold;">\.</span><span style="color: #000099; font-weight: bold;">\-</span><span style="color: #000099; font-weight: bold;">\_</span>]+@[<span style="color: #000099; font-weight: bold;">\d</span><span style="color: #000099; font-weight: bold;">\w</span><span style="color: #000099; font-weight: bold;">\.</span>]/'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span> <span style="color: #339933;">&amp;&amp;</span> jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#email'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// complex usage (mimic conditional operators)</span>
<span style="color: #003366; font-weight: bold;">var</span> my_setting <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>test_me <span style="color: #339933;">&amp;&amp;</span> optional_setting<span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #003366; font-weight: bold;">default</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// real example - setting email if valid, with default</span>
<span style="color: #003366; font-weight: bold;">var</span> email <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#email'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">search</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'/[<span style="color: #000099; font-weight: bold;">\d</span><span style="color: #000099; font-weight: bold;">\w</span><span style="color: #000099; font-weight: bold;">\.</span><span style="color: #000099; font-weight: bold;">\-</span><span style="color: #000099; font-weight: bold;">\_</span>]+@[<span style="color: #000099; font-weight: bold;">\d</span><span style="color: #000099; font-weight: bold;">\w</span><span style="color: #000099; font-weight: bold;">\.</span>]/'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span> <span style="color: #339933;">&amp;&amp;</span> jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#email'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #3366CC;">'none@none.com;</span></pre></div></div>

<h3>Method calls on conditional variables</h3>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// use parenthesis to act on a condition</span>
<span style="color: #009900;">&#40;</span>check_if_true <span style="color: #339933;">&amp;&amp;</span> use_this_if_true<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">method</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#40;</span>use_if_true <span style="color: #339933;">||</span> else_use_this<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">method</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// real example - Add form field error above itself if it's not wrapped in a &lt;form&gt; with ||</span>
<span style="color: #009900;">&#40;</span>jQuery<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">closest</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'form'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> jQuery<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">insertBefore</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;p&gt;Error!&lt;/p&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// real example - Add form field error only if it's a &lt;form&gt; with &amp;&amp;</span>
<span style="color: #006600; font-style: italic;">// note: this will error if not in a form and not in a try...catch</span>
<span style="color: #009900;">&#40;</span>jQuery<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">closest</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'form'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> jQuery<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">insertBefore</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;p&gt;Error!&lt;/p&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h3>Conclusion</h3>
<p>Javascript&#8217;s conditional operators allow us to do some neat tricks. We looked at how to use them to bypass <code>if...else</code>, make variable assignments based on conditions, and call methods depending on conditions. But with all shortcuts, use caution. Knowing how javascript works will help you use conditional operators to their full potential while keeping you safe from unexpected results.</p>


<p>Related posts:<ol><li><a href='http://briancray.com/2009/12/29/understanding-user-behavior-google-analytics-event-tracking-jquery/' rel='bookmark' title='Permanent Link: Diving deep into user behavior with Google Analytics, Event Tracking, and jQuery'>Diving deep into user behavior with Google Analytics, Event Tracking, and jQuery</a></li>
<li><a href='http://briancray.com/2009/09/18/web-form-validation-php/' rel='bookmark' title='Permanent Link: Smart web form validation with PHP'>Smart web form validation with PHP</a></li>
<li><a href='http://briancray.com/2009/04/01/how-to-calculate-the-distance-between-two-addresses-with-javascript-and-google-maps-api/' rel='bookmark' title='Permanent Link: How to calculate distance with javascript and Google Maps API'>How to calculate distance with javascript and Google Maps API</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://briancray.com/2011/04/18/javascript-logical-operators/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Time On Site &amp; Bounce Rate: Get the real numbers in Google Analytics</title>
		<link>http://briancray.com/2011/04/12/time-on-site-bounce-rate-get-the-real-numbers-in-google-analytics/</link>
		<comments>http://briancray.com/2011/04/12/time-on-site-bounce-rate-get-the-real-numbers-in-google-analytics/#comments</comments>
		<pubDate>Tue, 12 Apr 2011 22:21:45 +0000</pubDate>
		<dc:creator>Brian Cray</dc:creator>
				<category><![CDATA[Internet marketing]]></category>
		<category><![CDATA[Web development]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[web analytics]]></category>

		<guid isPermaLink="false">http://briancray.com/?p=1871</guid>
		<description><![CDATA[Google Analytics has a major problem with the way it calculates its Time On Site metric: its based on the length of time between a user entering your site and their last page view. Can&#8217;t see the holes yet? Here are 2 scenarios where this becomes a major problem (Bob will be our user): Worst [...]]]></description>
			<content:encoded><![CDATA[<p>Google Analytics has a major problem with the way it calculates its Time On Site metric: its based on the length of time between a user entering your site and <strong>their last page view</strong>. Can&#8217;t see the holes yet? Here are 2 scenarios where this becomes a major problem (Bob will be our user):</p>
<h3>Worst case scenario</h3>
<p><img src="http://briancray.com/wp-content/uploads/2011/04/bounce.png" width="554" height="134"></p>
<p>In the above scenario Bob enters your site, loyally reads an article for 2 minutes and 13 seconds, saves it to his browser boomarks, then leaves. Can you see the problem? Bob never <em>interacted</em> with the webpage. <strong>To Google, this is a bounce.</strong> And bounced visits get marked with 0:00 Time On Site. In other words, your Bounce Rate just got inflated and your Avg. Time On Site just got its ass kicked.</p>
<h3>Another bad scenario</h3>
<p><img src="http://briancray.com/wp-content/uploads/2011/04/1page.png" width="554" height="134"></p>
<p>Let&#8217;s say Bob enters your site and even visits a second page, spending a total of 2 minutes and 13 seconds on your site before leaving. But Google messes this up too: since Bob never interacted with the 2nd page, Google doesn&#8217;t know how long he spent on the second page. Therefore, Time On Site = Visit to second page &#8211; Entrance time = 1 minute and 11 seconds, <strong>not 2 minutes and 13 seconds</strong>.</p>
<p>Google&#8217;s calculation of Time On Site and Bounce Rate is limited by its unit of measure: <strong>the Pageview</strong>. But Time On Site has very little to do with pageviews and Bounce Rates&mdash;defined as &#8220;the percentage of people who come to your website and leave instantly&#8221; by <a href="http://www.kaushik.net/avinash/2007/08/standard-metrics-revisited-3-bounce-rate.html">Avinash Kaushik</a>&mdash;has nothing to do with pageviews.</p>
<h3>Solution</h3>
<p>With Google&#8217;s <a href="http://code.google.com/apis/analytics/docs/gaJS/gaJSApiEventTracking.html">Event Tracking API</a>, we&#8217;ll tell Google Analytics that Bob is still on our site every 10 seconds. To make things <strong>even better</strong>, an event is an engagement equivalent to a pageview, so it too increases Time On Site <em>and</em> unbounces the visit. <strong>The result? A more accurate picture of user engagement.</strong></p>
<h4>Javascript magic</h4>
<p>Paste this javascript snippet right before <code>&lt;/body&gt;</code> in your HTML pages. It won&#8217;t matter if you&#8217;re using the <a href="http://code.google.com/apis/analytics/docs/tracking/asyncUsageGuide.html">new</a> or <a href="http://code.google.com/apis/analytics/docs/tracking/gaTrackingOverview.html">old</a> tracking code.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>tos<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  window.<span style="color: #660066;">setInterval</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    tos <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>t<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000066; font-weight: bold;">return</span> t<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">50</span> <span style="color: #339933;">?</span> <span style="color: #009900;">&#40;</span>parseInt<span style="color: #009900;">&#40;</span>t<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">':00'</span> <span style="color: #339933;">:</span> <span style="color: #009900;">&#40;</span>t<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">||</span> <span style="color: #3366CC;">'0'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">':'</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>parseInt<span style="color: #009900;">&#40;</span>t<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #CC0000;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>tos.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">':'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">reverse</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    window.<span style="color: #660066;">pageTracker</span> <span style="color: #339933;">?</span> pageTracker._trackEvent<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Time'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'Log'</span><span style="color: #339933;">,</span> tos<span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> _gaq.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'_trackEvent'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'Time'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'Log'</span><span style="color: #339933;">,</span> tos<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: #339933;">,</span> <span style="color: #CC0000;">10000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'00'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>Once this code is installed, your site will update Google Analytics every 10 seconds under the Event Category &#8220;Time&#8221;, the Event Action &#8220;Log&#8221;, and <strong>the Event Value will be based on the pattern of 0:10, 0:20, 0:30, 0:40, 0:50, 1:00, 1:10, etc</strong>.</p>
<h3>Conclusion</h3>
<p>Although Google Analytics has its flaws, it compensates in part with a powerful tracking API that keeps getting better. The snippet I&#8217;ve written above can more than solve its Time On Site and Bounce Rate reporting issues. Furthermore, if you&#8217;re a Google Analytics ninja (or ninja in training), break out the event values into a histogram that shows the distribution of site visit duration. Cheers!</p>


<p>Related posts:<ol><li><a href='http://briancray.com/2010/03/03/bounce-rate-measurement-relevance/' rel='bookmark' title='Permanent Link: Measure what is relevant: A critical look at bounce rates'>Measure what is relevant: A critical look at bounce rates</a></li>
<li><a href='http://briancray.com/2009/12/20/asynchronous-tracking-google-analytics/' rel='bookmark' title='Permanent Link: Is your Google Analytics missing page views? Introducing Asynchronous Tracking'>Is your Google Analytics missing page views? Introducing Asynchronous Tracking</a></li>
<li><a href='http://briancray.com/2009/12/29/understanding-user-behavior-google-analytics-event-tracking-jquery/' rel='bookmark' title='Permanent Link: Diving deep into user behavior with Google Analytics, Event Tracking, and jQuery'>Diving deep into user behavior with Google Analytics, Event Tracking, and jQuery</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://briancray.com/2011/04/12/time-on-site-bounce-rate-get-the-real-numbers-in-google-analytics/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Surviving Silicon Valley</title>
		<link>http://briancray.com/2010/11/10/surviving-silicon-valley/</link>
		<comments>http://briancray.com/2010/11/10/surviving-silicon-valley/#comments</comments>
		<pubDate>Wed, 10 Nov 2010 17:13:40 +0000</pubDate>
		<dc:creator>Brian Cray</dc:creator>
				<category><![CDATA[Web development]]></category>
		<category><![CDATA[freelancing]]></category>
		<category><![CDATA[me]]></category>
		<category><![CDATA[product development]]></category>
		<category><![CDATA[startups]]></category>

		<guid isPermaLink="false">http://briancray.com/?p=1866</guid>
		<description><![CDATA[The past 2 months have been more crazy than any other time in my professional web life. Why? I'm surviving Silicon Valley. Find out how you can too.]]></description>
			<content:encoded><![CDATA[<p>The past 2 months have been more crazy than any other time in my professional web life. Why? I&#8217;m surviving Silicon Valley.</p>
<p>Two months ago I joined <a href="http://topsy.com/">Topsy</a>, a <a href="http://corp.topsy.com/">real-time search engine powered by the social web</a>. We have the largest index of tweets in the world, and turning all of that data into something useful for people is complex. Moreover, real-time and social are synonymous with fast-paced. Put the two together and we&#8217;re talking <em>really</em> fast-paced.</p>
<p>But that&#8217;s just how Silicon Valley rolls. The stakes are high as are the demands from the people expected to make things happen. So what does &#8220;making things happen&#8221; in Silicon Valley mean? Without further ado, here&#8217;s a high-level view of what&#8217;s happened during my first two months there.</p>
<h3>Two months in Silicon Valley</h3>
<ul>
<li>Thrown into a highly complex search environment trying to keep up with some of the smartest search engineers in the world</li>
<li>Released a completely redesigned corporate blog</li>
<li>Designed a complete product using Django/Python, both of which I&#8217;ve never had past experience</li>
<li>Built an powerful copy &#038; paste widget (coming soon to publishers near you)</li>
<li>All while moving from GUI editors with FTP access to VIM over SSH with Git version control</li>
</ul>
<p>Wow. That&#8217;s a lot. And I&#8217;m just getting warmed up.</p>
<p>I reflect on all of this often. Although I&#8217;ve seen myself as a strong developer having developed many popular web apps, I appreciate the developer I&#8217;m becoming … <em>in just two months</em> mind you.</p>
<p>But the real goal of this article is to prepare other smart developers around the world that are considering Silicon Valley for their next employment opportunity.</p>
<h3>Tips for preparing to work in Silicon Valley</h3>
<h4>Treat everyone like they&#8217;re your boss</h4>
<p>Silicon Valley hires people because they&#8217;re the cream of the crop&mdash;the best at what they do. The culture is very egalitarian in that a co-worker&#8217;s advice is just as valuable as your boss&#8217; or their boss&#8217; advice when given in the context of their expertise. Unless obviously untrue, never should you doubt or underestimate their knowledge. It may be the best advice you&#8217;ve ever received.</p>
<p>When you&#8217;re working with someone, think of your role in terms of how to make their jobs easier. If you do that, you&#8217;ll likely to receive the same treatment back, because everybody respects co-workers who get shit done.</p>
<h4>Get shit done</h4>
<p>Silicon Valley startups represent a high performance culture. Shareholders, the nature of Silicon Valley, and the economics of technology all make things move fast. The <em>only</em> way to keep up is to simply get &#8216;er done.</p>
<p>Additionally, the level of expertise required to work there means you&#8217;re highly accountable to your output for two primary reasons. First, everyone is solving their own problems that help the business grow. Your problems are your own to the extent that you&#8217;re ultimately accountable for solving them. Second, because everyone is a strong performer and the unforgiving nature of startups means the company is running lean. Your role is yours. Do it or say screw it and bounce out of Silicon Valley.</p>
<h4>Burst your bubble</h4>
<p>Over 50% of the tools I use to get my job done are new to me. I wasn&#8217;t hired only because I knew the primary tools that were required for the role. I was hired because I had the capacity and the desire to learn and grow professionally and personally.</p>
<p>If you&#8217;re working in a bubble (mine was LAMP) and thinking about working in Silicon Valley, make sure that you&#8217;re comfortable with learning new tools even as you&#8217;re expected to perform with them. Silicon Valley is no place for people unwilling to break their barriers, even drastically.</p>
<h3>Conclusion</h3>
<p>Surviving Silicon Valley is about capacity to perform. Do you have the capacity to perform?</p>
<p>On a related note, Topsy is a great place to work, and <a href="http://corp.topsy.com/about/jobs/">Topsy is always hiring</a>. (And no, Topsy did <strong>not</strong> ask me write that)</p>


<p>Related posts:<ol><li><a href='http://briancray.com/2009/05/01/9-reasons-single-purpose-website-app/' rel='bookmark' title='Permanent Link: 9 compelling reasons to build a single-purpose website'>9 compelling reasons to build a single-purpose website</a></li>
<li><a href='http://briancray.com/2009/06/18/why-web-based-products-successful/' rel='bookmark' title='Permanent Link: Why some web apps are successful and others aren&#8217;t'>Why some web apps are successful and others aren&#8217;t</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://briancray.com/2010/11/10/surviving-silicon-valley/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Metadata design pattern for the web</title>
		<link>http://briancray.com/2010/10/01/metadata-design-pattern-for-the-web/</link>
		<comments>http://briancray.com/2010/10/01/metadata-design-pattern-for-the-web/#comments</comments>
		<pubDate>Fri, 01 Oct 2010 16:01:09 +0000</pubDate>
		<dc:creator>Brian Cray</dc:creator>
				<category><![CDATA[User experience]]></category>

		<guid isPermaLink="false">http://briancray.com/?p=1863</guid>
		<description><![CDATA[A design pattern for using the web's vast content to provide context without leaving a website.]]></description>
			<content:encoded><![CDATA[<p>The Web is shifting. Web pages are no longer silos of information. <a href="http://twitter.com/">Twitter</a>, <a href="http://facebook.com">Facebook</a>, and blogs are adding conversations to the web, and those conversations are context for web content that can potentially provide an amazing amount of value to users.</p>
<p>The major shift began when people could begin commenting on diaries with <a href="http://en.wikipedia.org/wiki/Open_Diary">Open Diary</a> in 1998 and growing quickly in popularity when Google bought <a href="http://www.blogger.com/">Blogger</a> in 2003. Today, conversations are happening everywhere, and more people are joining in every day.</p>
<h3>New problem: Conversations are silos</h3>
<p>But now conversations are falling into silos. Commenting on a blog about an linked-to-article isn&#8217;t the same as commenting directly on that article. If I&#8217;m looking at web content, I should be able to see what people everywhere are saying about that article. Instead, I have to become my own search engine robot&mdash;crawling the web to see what others are saying.</p>
<p>But why do I care what others are saying? Because it&#8217;s <a href="http://en.wikipedia.org/wiki/Social_proof">social proof</a>. Because it provides context. Information in context is infinitely more valuable.</p>
<h3>Twitter redesign is tearing down the silos</h3>
<p><a href="http://twitter.com/newtwitter">Twitter&#8217;s redesign</a> is beginning to unlock this potential. Before the redesign, tweets were silos. I only knew that this person made such and such comment, and possibly that they tweeted such and such. But what exactly were they responding to? Who? Why?</p>
<p>After the redesign I instantly see what others are saying, who said it first, and even a peak at what&#8217;s being discussed when I click on a tweet. Suddenly, a wealth of information is at my fingertips with each new tweet coming in.</p>
<h3>Others want to demolish the walls, too</h3>
<p>Recently InformationArchitects.com (<a href="http://twitter.com/ia">@iA</a>) posted <a href="http://www.informationarchitects.jp/en/ias-2006-facebook-designs-redesigned/">their own redesign of Facebook</a>, which shares many similarities with Twitter&#8217;s redesign. Click on something posted on your wall, and a panel opens revealing context for the post.</p>
<h3>Building a design pattern for metadata</h3>
<p>In Twitter and iA&#8217;s Facebook designs you&#8217;ll see that on the left is the main content, and on the right is metadata, unlocked by clicking on the main content. I believe this should become more commonplace for content on the web.</p>
<p><img src="http://briancray.com/wp-content/uploads/2010/10/metadata-pattern.png"></p>
<h3>Applications</h3>
<h4>Search engines</h4>
<p>Imagine clicking on a result in Google and viewing discussions about a link, other pages that link to the page, and other popular pages on the site.</p>
<h4>Content feeds</h4>
<p>Twitter is already doing it. iA&#8217;s Facebook redesign shows it. What about <a href="http://www.google.com/reader/">Google Reader</a> or other aggregators? Aggregating content is not as powerful as aggregating content with context.</p>
<h4>Websites</h4>
<p>I&#8217;m thinking about this for my own blog: Imagine clicking on a link and getting context about it without leaving the article? Or when I visit a page it automatically pulls in conversations and metadata from the web to supplement my own content.</p>
<h4>Web browser plugins</h4>
<p>Same as above, but the UI is built into the navigator. Some of Safari&#8217;s extensions are already doing this, including <a href="https://extensions.apple.com/#twitter">Twitter for Safari</a> and <a href="http://www.macosxtips.co.uk/extensions/redditcomments.safariextz">Reddit Comments</a>.</p>
<h3>What do you think?</h3>
<p>Where could you see this pattern applied? Where else have you seen this pattern used? Is there a need for this pattern?</p>


<p>Related posts:<ol><li><a href='http://briancray.com/2009/09/08/track-inbound-link-referrals-social-media-profiles-twitter-facebook/' rel='bookmark' title='Permanent Link: How to track inbound links from your social media profiles (Twitter, Facebook, etc)'>How to track inbound links from your social media profiles (Twitter, Facebook, etc)</a></li>
<li><a href='http://briancray.com/2009/08/26/blog-design-information-overload-progressive-disclosure/' rel='bookmark' title='Permanent Link: Blog design best practice: Scrollbars not sidebars'>Blog design best practice: Scrollbars not sidebars</a></li>
<li><a href='http://briancray.com/2009/04/28/10-signs-professional-web-design/' rel='bookmark' title='Permanent Link: 10 signs of professional web design (Or why you should drop your amateur web designer)'>10 signs of professional web design (Or why you should drop your amateur web designer)</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://briancray.com/2010/10/01/metadata-design-pattern-for-the-web/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>HTML5 Microdata: Why isn&#8217;t anyone talking about it?</title>
		<link>http://briancray.com/2010/09/08/html5-microdata/</link>
		<comments>http://briancray.com/2010/09/08/html5-microdata/#comments</comments>
		<pubDate>Wed, 08 Sep 2010 19:49:44 +0000</pubDate>
		<dc:creator>Brian Cray</dc:creator>
				<category><![CDATA[User experience]]></category>
		<category><![CDATA[Web development]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[microdata]]></category>
		<category><![CDATA[seo]]></category>

		<guid isPermaLink="false">http://briancray.com/?p=1861</guid>
		<description><![CDATA[HTML5 Microdata could mark the beginning of a practical, realistic approach to a truly semantic web. If so, why isn't anyone talking about it!?]]></description>
			<content:encoded><![CDATA[<p>Many big web design blogs are raving about HTML5, as they should be. But if you read many of them, [<a href="http://www.smashingmagazine.com/2009/07/16/html5-and-the-future-of-the-web/">1</a>, <a href="http://www.alistapart.com/articles/previewofhtml5">2</a>, <a href="http://net.tutsplus.com/tutorials/html-css-techniques/html-5-and-css-3-the-techniques-youll-soon-be-using/">3</a>], you&#8217;ll be bombarded with an over-publicizing of <a href="http://www.w3schools.com/html5/tag_header.asp"><code>header</code></a>, <a href="http://www.w3schools.com/html5/tag_article.asp"><code>article</code></a>, <a href="http://www.w3schools.com/html5/tag_footer.asp"><code>footer</code></a>, et. al tags, which reminds me of <a href="http://www.alistapart.com/articles/betterliving/">circa 2002</a> when we were all jumping onto the XHTML bandwagon.</p>
<p>But 8 years later where&#8217;d XHTML get us? Suddenly we&#8217;re moving back to HTML. Why? <strong>XHTML provided no <em>actual</em> benefits</strong>. It just meant we had to add meaningless bytes to our user&#8217;s downloads.</p>
<p>HTML5 on the other hand is bringing with it a ton of actually <em>useful</em> technologies, including <a href="http://diveintohtml5.org/forms.html">much needed advances in HTML forms</a>, <a href="http://diveintohtml5.org/video.html">native video support</a>, and <a href="http://diveintohtml5.org/canvas.html">a vector API/<code>canvas</code></a>.</p>
<p>But back to circa 2010/2002-wannabe. Here we are again bandwagoning (is that a word?) some futile tags of HTML5. Why get so excited about those tags? Look how flexible this is: <code>div id="<em>ANYTHING</em>"</code>. Wow.</p>
<p>So my fellow web design bloggers: let&#8217;s shift our focus to something that&#8217;s a part of the HTML5 definition, changes the way we write tags, <em>and</em> has actual benefits: <strong><a href="http://www.w3.org/TR/html5/microdata.html">Microdata</a></strong>.</p>
<p>A few web design blogs, including one of my favorites, <a href="http://net.tutsplus.com/">NETTUTS</a>, has <a href="http://net.tutsplus.com/tutorials/html-css-techniques/html5-microdata-welcome-to-the-machine/">covered Microdata briefly</a>, and I want to add some more fuel to the conversation.</p>
<h3>What is HTML5 Microdata?</h3>
<p>Old schoolies may remember this little thing called the <a href="http://en.wikipedia.org/wiki/Semantic_Web">Semantic Web</a>. No I&#8217;m not talking about <a href="http://en.wikipedia.org/wiki/Semantic_HTML">Semantic HTML</a>, a fancy bit of jargon that by its mere mentioning can give web design newbies a glint of crazed evangelism in their eyes. No. I&#8217;m talking about <em>actual</em> ways to make the web more useful to users.</p>
<p>The Semantic Web would ideally help users find and use information because computers would know, for example, that an event is an event rather than a bunch of text. If a computer knows an event is an event, it could potentially add a mechanism to allow the user to add the event to his or her calendar. Otherwise, in what has been the norm, the computer arbitrarily displays the information putting the burden in the hands of the user.</p>
<p>While there have been many approaches to a semantic web, including <a href="http://en.wikipedia.org/wiki/XML">XML</a>, none of them have really taken off beyond APIs because Internet users don&#8217;t read XML code. Users look at web pages. Additionally writing <a href="http://www.w3schools.com/schema/default.asp">XML schemas</a> was impractical and ill-adopted by web designers and search engines alike.</p>
<p>But &#8220;the times they are a-changin&#8217;.&#8221; HTML5 is introducing Microdata, which is an API for adding semantic data to plain ol&#8217; HTML tags. This means that using plain ol&#8217; HTML tags, you can tell the a web browser or search engine that an event is an event, a person is a person, and so on.</p>
<h3>How does Microdata markup look?</h3>
<p>Using Microdata is simple, because unlike XML, you do the same thing you&#8217;ve been doing since you built your first website. The only difference is you add an extra attribute to your HTML tags, like so:</p>
<h4>Before adding Microdata</h4>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h1</span>&gt;</span>My big event<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h1</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>My big event is going to be fun. You should come.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>When: July 4th, 2022 at 6:00pm to July 4th, 2022 at 10:00pm.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>Where: Fun Times Bar<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></div></div>

<h4>After adding Microdata</h4>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> itemscope itemtype<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://data-vocabulary.org/Event&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h1</span> itemprop<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;summary&quot;</span>&gt;</span>My big event<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h1</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span> itemprop<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;description&quot;</span>&gt;</span>My big event is going to be fun. You should come.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>When: <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">span</span> itemprop<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;startDate&quot;</span> <span style="color: #000066;">datetime</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;2022-07-04T18:00&quot;</span>&gt;</span>July 4th, 2022 at 6:00pm<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;</span> to <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">span</span> itemprop<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;endDate&quot;</span> <span style="color: #000066;">datetime</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;2022-07-04T22:00&quot;</span>&gt;</span>July 4th, 2022 at 10:00pm<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;</span>.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span> itemprop<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;location&quot;</span> itemscope</span>
<span style="color: #009900;">           itemtype<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://data-vocabulary.org/Organization&quot;</span>&gt;</span>Where: <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">span</span> itemprop<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;name&quot;</span>&gt;</span>Fun Times Bar<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></div></div>

<p>As you&#8217;ll see from the example above, we&#8217;re still using plain old HTML tags, just adding some additional attributes.</p>
<p>Although completely going over all Microdata attributes is being the scope of this article, you can check out a <a href="http://diveintohtml5.org/extensibility.html">a fantastic documentation on using Microdata at Dive into HTML5</a></p>
<h3>Use Microdata for immediate benefits</h3>
<p>Unlike all the ideology surrounding XML that never came to fruition, <strong><a href="http://googlewebmastercentral.blogspot.com/2010/03/microdata-support-for-rich-snippets.html">Microdata is already being adopted by Google</a></strong> as part of their <a href="http://googlewebmastercentral.blogspot.com/2009/05/introducing-rich-snippets.html">rich snippets</a> to aid in providing richer search results.</p>
<h4>Google using Microdata events</h4>
<p><img src="//www.google.com/help/hc/images/webmasters_164506_rsevents.png" alt="image of a Google rich snippet for an events listing page"></p>
<h4>Google using Microdata people</h4>
<p><img src="//www.googel.com//help/hc/images/webmasters_146676_rspeople.png" alt="image of a Google search rich snippet representing a person"></p>
<h4>Google using Microdata reviews</h4>
<p><img alt="image of a Google rich snippet for an aggregate review of a restaurant" src="//www.google.com/help/hc/images/webmasters_99170_rsreview.png"></p>
<p>Google has a <a href="http://www.google.com/support/webmasters/bin/topic.py?topic=21997">list of rich snippets</a> for more examples of how you can use Microdata to product richer search results for your own web pages.</p>
<h3>Taking Microdata even further tomorrow</h3>
<p>Google&#8217;s adoption of Microdata is taking us a step closer to a semantic web, and there are still big steps to make. However, I believe Microdata may be practical enough to get us really rolling on the semantic web train. Here are a few things I believe would help:</p>
<h4>Microdata adoption by browsers</h4>
<p>What if a user rolled over a person&#8217;s name and could add them as a contact, or roll over an event and add it to your calendar, all within the native web browser UI? That&#8217;d be something, and it doesn&#8217;t seem like it would be that hard to accomplish. How about it <a href="http://www.mozilla.org/">Mozilla</a>, <a href="http://www.apple.com/safari/">Safari</a>?</p>
<h4>Microdata adoption by web developers</h4>
<p>Web browsers and Google have little reason to support Microdata if us web developers aren&#8217;t marking up our webpages with it. Plain and simple. Take a few moments to learn the Microdata API a little, and the semantic web will be right at our doorstep.</p>
<h3>What are your thoughts about Microdata?</h3>
<p>Finally, I want to hear your thoughts on Microdata. Have you had any experience with it? What are some potential uses for Microdata that I haven&#8217;t discussed?</p>


<p>Related posts:<ol><li><a href='http://briancray.com/2009/12/29/understanding-user-behavior-google-analytics-event-tracking-jquery/' rel='bookmark' title='Permanent Link: Diving deep into user behavior with Google Analytics, Event Tracking, and jQuery'>Diving deep into user behavior with Google Analytics, Event Tracking, and jQuery</a></li>
<li><a href='http://briancray.com/2009/09/04/wordpress-tag-cloud-php-function/' rel='bookmark' title='Permanent Link: A better WordPress tag cloud'>A better WordPress tag cloud</a></li>
<li><a href='http://briancray.com/2010/02/03/measuring-simplicity-in-web-design/' rel='bookmark' title='Permanent Link: The more I know, the less I need: Thoughts on web design'>The more I know, the less I need: Thoughts on web design</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://briancray.com/2010/09/08/html5-microdata/feed/</wfw:commentRss>
		<slash:comments>40</slash:comments>
		</item>
	</channel>
</rss>
