<?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>Ambition Lab</title>
	<atom:link href="http://www.ambitionlab.com/feed" rel="self" type="application/rss+xml" />
	<link>http://www.ambitionlab.com</link>
	<description>Rajeev Singh</description>
	<lastBuildDate>Tue, 25 May 2010 21:28:12 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to Find &amp; Delete a Specified Value From an Array in JavaScript</title>
		<link>http://www.ambitionlab.com/how-to-find-delete-a-specified-value-from-an-array-in-javascript-2010-04-21</link>
		<comments>http://www.ambitionlab.com/how-to-find-delete-a-specified-value-from-an-array-in-javascript-2010-04-21#comments</comments>
		<pubDate>Wed, 21 Apr 2010 13:00:35 +0000</pubDate>
		<dc:creator>Raj</dc:creator>
				<category><![CDATA[Web Dev]]></category>

		<guid isPermaLink="false">http://www.ambitionlab.com/?p=251</guid>
		<description><![CDATA[You would think that this would be part of JavaScript&#8217;s core functionality, but&#8230; no. It&#8217;s delete function leaves a value of &#8220;undefined&#8221; in place of the original. Using splice is the solution, but first you have to know the index of the element. These two simple functions make easy work of the task.
Object-oriented folk may [...]]]></description>
			<content:encoded><![CDATA[<p>You would think that this would be part of JavaScript&#8217;s core functionality, but&#8230; no. It&#8217;s <strong>delete</strong> function leaves a value of &#8220;undefined&#8221; in place of the original. Using<strong> splice</strong> is the solution, but first you have to know the index of the element. These two simple functions make easy work of the task.</p>
<p>Object-oriented folk may want to enclose these functions within an extended array object (or extend the Array object, if that&#8217;s your style):</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> getArrayIndex <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>array<span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> array.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</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>array<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">===</span> <span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> i<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</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> deleteArrayItem <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>array<span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> index <span style="color: #339933;">=</span> getArrayIndex<span style="color: #009900;">&#40;</span>array<span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>index <span style="color: #339933;">&gt;</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>        
        <span style="color: #000066; font-weight: bold;">return</span> array.<span style="color: #660066;">splice</span><span style="color: #009900;">&#40;</span>index<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: #009900;">&#125;</span>
    <span style="color: #000066; font-weight: bold;">return</span> array<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Using Array.indexOf might seem logical, but it&#8217;s mildly cross-browser problematic at the moment. Rather than using the <a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/indexOf">common Array.indexOf workaround</a>, I&#8217;m using a custom function because it&#8217;s less code and can be tweaked to suit any unique needs I might have.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ambitionlab.com/how-to-find-delete-a-specified-value-from-an-array-in-javascript-2010-04-21/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Typeface.js :hover workaround</title>
		<link>http://www.ambitionlab.com/typeface-js-hover-workaround-2010-04-19</link>
		<comments>http://www.ambitionlab.com/typeface-js-hover-workaround-2010-04-19#comments</comments>
		<pubDate>Mon, 19 Apr 2010 13:00:01 +0000</pubDate>
		<dc:creator>Raj</dc:creator>
				<category><![CDATA[Web Dev]]></category>

		<guid isPermaLink="false">http://www.ambitionlab.com/?p=243</guid>
		<description><![CDATA[A while ago I wrote a sIFR vs Typeface.js article, and ever since then I&#8217;ve seen hits to my site from people searching for a :hover workaround for Typeface. Here&#8217;s a limited solution. It&#8217;s using jQuery, but you could easily adapt this method to use another library (or none at all). I&#8217;ll admit this isn&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>A while ago I wrote a <a href="http://www.ambitionlab.com/sifr-vs-typeface-js-the-verdict-2010-01-08">sIFR vs Typeface.js article</a>, and ever since then I&#8217;ve seen hits to my site from people searching for a :hover workaround for Typeface. Here&#8217;s a limited solution. It&#8217;s using jQuery, but you could easily adapt this method to use another library (or none at all). I&#8217;ll admit this isn&#8217;t the most eloquent solution in the world, but this proved to be functional, so I thought I&#8217;d share.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> typefacehover <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;">&#40;</span><span style="color: #3366CC;">&quot;.typeface-js&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</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;">//Get all the classes for an element. </span>
    <span style="color: #003366; font-weight: bold;">var</span> elementStyles <span style="color: #339933;">=</span> $<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;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'class'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    elementStyles <span style="color: #339933;">=</span> elementStyles.<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: #339933;">;</span>
    <span style="color: #006600; font-style: italic;">//Run through them and check for a :hover color property.</span>
    <span style="color: #003366; font-weight: bold;">var</span> hoverColor<span style="color: #339933;">;</span>                                
    <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #000066; font-weight: bold;">in</span> elementStyles<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>                                        
      <span style="color: #003366; font-weight: bold;">var</span> temp <span style="color: #339933;">=</span> getCSSColor<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.'</span><span style="color: #339933;">+</span>elementStyles<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">':hover'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>                           
      <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>temp<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        hoverColor <span style="color: #339933;">=</span> temp<span style="color: #339933;">;</span>                                        
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>hoverColor<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      <span style="color: #003366; font-weight: bold;">var</span> element <span style="color: #339933;">=</span> $<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;">html</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #006600; font-style: italic;">//Duplicate the element, create a new hover version of the element (hidden) and add a container to each one so that we can distinguish between the two.</span>
      <span style="color: #003366; font-weight: bold;">var</span> hoverElement <span style="color: #339933;">=</span> <span style="color: #3366CC;">'&lt;div class=&quot;typeface-js-hover&quot; style=&quot;color:'</span><span style="color: #339933;">+</span>hoverColor<span style="color: #339933;">+</span><span style="color: #3366CC;">';display:none&quot;&gt;'</span><span style="color: #339933;">+</span>element<span style="color: #339933;">+</span><span style="color: #3366CC;">'&lt;/div&gt;'</span><span style="color: #339933;">;</span>
      element <span style="color: #339933;">=</span> <span style="color: #3366CC;">'&lt;div class=&quot;typeface-js-nohover&quot;&gt;'</span><span style="color: #339933;">+</span>element<span style="color: #339933;">+</span><span style="color: #3366CC;">'&lt;/div&gt;'</span><span style="color: #339933;">;</span>
      <span style="color: #003366; font-weight: bold;">var</span> newElement <span style="color: #339933;">=</span> element <span style="color: #339933;">+</span> hoverElement<span style="color: #339933;">;</span>
      $<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;">html</span><span style="color: #009900;">&#40;</span>newElement<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #006600; font-style: italic;">//Add the event listener. You could do fade transitions here if you wanted to be fancy.</span>
      $<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;">hover</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: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.typeface-js-nohover&quot;</span><span style="color: #339933;">,</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<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;">&#40;</span><span style="color: #3366CC;">&quot;.typeface-js-hover&quot;</span><span style="color: #339933;">,</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</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: #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;">&#40;</span><span style="color: #3366CC;">&quot;.typeface-js-nohover&quot;</span><span style="color: #339933;">,</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.typeface-js-hover&quot;</span><span style="color: #339933;">,</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<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: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #006600; font-style: italic;">//Kudos: http://www.mail-archive.com/jquery-dev@googlegroups.com/msg03390.html</span>
<span style="color: #003366; font-weight: bold;">var</span> getCSSColor <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>selector<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>                            
  <span style="color: #003366; font-weight: bold;">var</span> re <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> RegExp<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'(^|,)<span style="color: #000099; font-weight: bold;">\\</span>s*'</span><span style="color: #339933;">+</span>selector.<span style="color: #660066;">toLowerCase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">'<span style="color: #000099; font-weight: bold;">\\</span>s*(,|$)'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #003366; font-weight: bold;">var</span> color<span style="color: #339933;">;</span>                            
  $.<span style="color: #660066;">each</span> <span style="color: #009900;">&#40;</span>$.<span style="color: #660066;">makeArray</span><span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">styleSheets</span><span style="color: #009900;">&#41;</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: #660066;">each</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">cssRules</span> <span style="color: #339933;">||</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">rules</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>re.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">selectorText</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>                                        
        color <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">style</span>.<span style="color: #660066;">color</span><span style="color: #339933;">;</span>                                        
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</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: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">return</span> color<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>I hope to find the time to develop a more robust solution in the future. Let me know if this was helpful!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ambitionlab.com/typeface-js-hover-workaround-2010-04-19/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Playing with CSS3 Transformations</title>
		<link>http://www.ambitionlab.com/playing-with-css3-transformations-2010-04-15</link>
		<comments>http://www.ambitionlab.com/playing-with-css3-transformations-2010-04-15#comments</comments>
		<pubDate>Thu, 15 Apr 2010 20:50:58 +0000</pubDate>
		<dc:creator>Raj</dc:creator>
				<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://www.ambitionlab.com/?p=238</guid>
		<description><![CDATA[Firefox &#38; Chrome users, check out my latest little tech demo. It&#8217;s the beginnings of a purely javascript game that makes use of early implementations of CSS3 rotation. I love it!
]]></description>
			<content:encoded><![CDATA[<p>Firefox &amp; Chrome users, check out my latest <a href="http://www.ambitionlab.com/games/nebulus/">little tech demo</a>. It&#8217;s the beginnings of a purely javascript game that makes use of early implementations of CSS3 rotation. I love it!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ambitionlab.com/playing-with-css3-transformations-2010-04-15/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>sIFR vs Typeface.js: The Verdict</title>
		<link>http://www.ambitionlab.com/sifr-vs-typeface-js-the-verdict-2010-01-08</link>
		<comments>http://www.ambitionlab.com/sifr-vs-typeface-js-the-verdict-2010-01-08#comments</comments>
		<pubDate>Fri, 08 Jan 2010 20:44:45 +0000</pubDate>
		<dc:creator>Raj</dc:creator>
				<category><![CDATA[Web Dev]]></category>

		<guid isPermaLink="false">http://www.ambitionlab.com/?p=215</guid>
		<description><![CDATA[[Update: If you're looking for the typeface.js :hover workaround, it's here]
Months ago, in my mission to find a good solution for using fancy fonts on the web, I had a choice between sIFR and typeface.js. sIFR uses Flash to render text, and typeface uses the &#60;canvas&#62; element (or VML in IE). Other than the difference [...]]]></description>
			<content:encoded><![CDATA[<p><strong>[Update: If you're looking for the typeface.js :hover workaround, it's <a href="http://www.ambitionlab.com/typeface-js-hover-workaround-2010-04-19">here</a>]</strong></p>
<p>Months ago, in my mission to find a good solution for using fancy fonts on the web, I had a choice between <a href="http://wiki.novemberborn.net/sifr/">sIFR</a> and <a href="http://typeface.neocracy.org/">typeface.js</a>. sIFR uses Flash to render text, and typeface uses the &lt;canvas&gt; element (or VML in IE). Other than the difference in implementation, however, their feature-set looked about the same, at least for my simple purposes: they were both javascript driven, both allowed text to be selected, and they both looked damn good.</p>
<p>But typeface.js had one crippling debilitation. It didn&#8217;t have :hover support. <em>Weak.</em> So I went with sIFR.</p>
<p>First, I found sIFR&#8217;s configuration to be a pain. <em>Well, that&#8217;s OK. I only have to learn the setup once, then I can copy+paste my code. </em></p>
<p>Then I found that it had z-index issues in IE, particularly when using them as links and tying the :hover directive together with an image change. <em>Annoying, but it&#8217;s flash based and IE is always a pain. Fine.</em></p>
<p>Then I noticed that my jQuery animations (slide effects) were slowed down when sIFR elements were included in the animated element. <em>Hmmm.</em></p>
<p>Then I started using <span style="text-decoration: underline;">a lot</span> of sIFR elements on one page&#8230; significant loading delay. <em>Hrmph.</em></p>
<p>Then it came to my attention that every once in a while the sIFR elements would fail to load altogether in IE on those sIFR-heavy pages. <em>Uh&#8230;. sIFR, we&#8217;re through. This just isn&#8217;t going to work out. It&#8217;s not me, it&#8217;s you. It was great while it lasted (wait, no.. not really). Ciao.</em></p>
<p>And then I said hello to typeface.js. Configuration? <em>Piece of cake.</em> Speed? <em>Fast!</em> Reliability? <em>Hasn&#8217;t failed me yet.</em> Z-index issues? <em>None.</em> Lack of :hover support?</p>
<p>I can live with that.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ambitionlab.com/sifr-vs-typeface-js-the-verdict-2010-01-08/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to check if a file exists using JQuery</title>
		<link>http://www.ambitionlab.com/how-to-check-if-a-file-exists-using-jquery-2010-01-06</link>
		<comments>http://www.ambitionlab.com/how-to-check-if-a-file-exists-using-jquery-2010-01-06#comments</comments>
		<pubDate>Wed, 06 Jan 2010 20:54:11 +0000</pubDate>
		<dc:creator>Raj</dc:creator>
				<category><![CDATA[Web Dev]]></category>
		<category><![CDATA[code snippet]]></category>

		<guid isPermaLink="false">http://www.ambitionlab.com/?p=205</guid>
		<description><![CDATA[The best way to do this is with an AJAX HEAD request. HEAD requests only ask for and return the header from the destination file, so they&#8217;re much faster than POST or GET requests. Perfect for a simple file check.
It&#8217;s also worth noting that a HEAD request also returns the content length and last modified [...]]]></description>
			<content:encoded><![CDATA[<p>The best way to do this is with an AJAX HEAD request. HEAD requests only ask for and return the header from the destination file, so they&#8217;re much faster than POST or GET requests. Perfect for a simple file check.</p>
<p>It&#8217;s also worth noting that a HEAD request also returns the content length and last modified date, and that jQuery has an &#8220;ifModified&#8221; option for the .ajax function that returns a boolean value.</p>
<p>Quick code snippet:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    url<span style="color: #339933;">:</span><span style="color: #3366CC;">'http://www.example.com/somefile.ext'</span><span style="color: #339933;">,</span>
    type<span style="color: #339933;">:</span><span style="color: #3366CC;">'HEAD'</span><span style="color: #339933;">,</span>
    error<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: #006600; font-style: italic;">//do something depressing</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    success<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: #006600; font-style: italic;">//do something cheerful :)</span>
        <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Couldn&#8217;t be easier!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ambitionlab.com/how-to-check-if-a-file-exists-using-jquery-2010-01-06/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Clean, Tidy and Flexible Function Variables</title>
		<link>http://www.ambitionlab.com/clean-tidy-and-flexible-function-variables-2009-12-14</link>
		<comments>http://www.ambitionlab.com/clean-tidy-and-flexible-function-variables-2009-12-14#comments</comments>
		<pubDate>Mon, 14 Dec 2009 13:00:12 +0000</pubDate>
		<dc:creator>Raj</dc:creator>
				<category><![CDATA[Web Dev]]></category>

		<guid isPermaLink="false">http://www.ambitionlab.com/?p=187</guid>
		<description><![CDATA[The thing about functions is&#8230; they grow. They start off small and cute and useful, but over time you start to notice their little shortcomings, so you make them bigger, better, and more flexible. Unfortunately, if you&#8217;re using PHP&#8217;s default method of passing functions, which is based on the sequence the functions are given (i.e. [...]]]></description>
			<content:encoded><![CDATA[<p>The thing about functions is&#8230; they grow. They start off small and cute and useful, but over time you start to notice their little shortcomings, so you make them bigger, better, and more flexible. Unfortunately, if you&#8217;re using PHP&#8217;s default method of passing functions, which is based on the sequence the functions are given (i.e. <strong>function </strong>example<span style="color: #339966;">(</span><span style="color: #ff9900;">$variable1</span>, <span style="color: #ff9900;">$variable2</span>, <span style="color: #ff9900;">$etc</span><span style="color: #339966;">)</span>) , things can get a little messy. The more variables a function can handle, the harder it is to remember the sequence they have to follow. Not to mention PHP 5 doesn&#8217;t facilitate a way to skip variables. For example, this doesn&#8217;t work: example<span style="color: #339966;">(</span><span style="color: #ff9900;">$variable1</span>, , <span style="color: #ff9900;">$variable3</span>, <span style="color: #ff9900;">$etc</span><span style="color: #339966;">)</span>.</p>
<p>The solution is to pass your variables on in an array. Here&#8217;s the template that I use whenever I code a new function:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> example<span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$variable1</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$args</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'variable1'</span><span style="color: #009900;">&#93;</span>? <span style="color: #000088;">$args</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'variable1'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">'default'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>And this is how you pass variables on to your function:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$args</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">'variable1'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000ff;">'value'</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'variable2'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'variable3'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #000088;">$etc</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
example<span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>And what&#8217;s more, if you have an existing function that you want to convert to taking an array, but don&#8217;t want to change all of your existing function calls, you can do something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> example<span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$variable2</span><span style="color: #339933;">,</span> <span style="color: #000088;">$variable3</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">is_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$variable1</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$args</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'variable1'</span><span style="color: #009900;">&#93;</span>? <span style="color: #000088;">$args</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'variable1'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">'default'</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$variable2</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$args</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'variable2'</span><span style="color: #009900;">&#93;</span>? <span style="color: #000088;">$args</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'variable2'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">'default'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$variable1</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$args</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Clean, tidy, and easy as pie. <img src='http://www.ambitionlab.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.ambitionlab.com/clean-tidy-and-flexible-function-variables-2009-12-14/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Code your own permalinks</title>
		<link>http://www.ambitionlab.com/code-your-own-permalinks-2009-12-09</link>
		<comments>http://www.ambitionlab.com/code-your-own-permalinks-2009-12-09#comments</comments>
		<pubDate>Thu, 10 Dec 2009 02:42:53 +0000</pubDate>
		<dc:creator>Raj</dc:creator>
				<category><![CDATA[Web Dev]]></category>

		<guid isPermaLink="false">http://www.ambitionlab.com/?p=173</guid>
		<description><![CDATA[Ever wondered how a CMS like WordPress creates those pretty URLs that resemble directory structures on the fly?Ever wondered if you could do the same thing with your own website or web app? Well you can, and it&#8217;s ridiculously simple.
Step 1: You need to edit your .htaccess file to incorporate some mod rewrite rules. This [...]]]></description>
			<content:encoded><![CDATA[<p>Ever wondered how a CMS like WordPress creates those pretty URLs that resemble directory structures on the fly?Ever wondered if you could do the same thing with your own website or web app? Well you can, and it&#8217;s ridiculously simple.</p>
<p>Step 1: You need to edit your .htaccess file to incorporate some mod rewrite rules. This is the code that we&#8217;re going to use (the same code that WordPress uses):</p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;"><span style="color: #00007f;">RewriteEngine</span> <span style="color: #0000ff;">On</span>
<span style="color: #00007f;">RewriteBase</span> /
<span style="color: #00007f;">RewriteCond</span> %{REQUEST_FILENAME} !-f
<span style="color: #00007f;">RewriteCond</span> %{REQUEST_FILENAME} !-d
<span style="color: #00007f;">RewriteRule</span> . /yourcode.php [L]</pre></div></div>

<p>What this does is capture the &#8220;filenames&#8221; (really just a URI string that comes after your site root), and pass them on in an array to the file of your choice, &#8220;yourcode.php&#8221; in this case. It does all this without changing the URL on the user&#8217;s end. So now all we have to do is pick up those variables in our PHP code. We&#8217;ll do that with this code in yourcode.php :</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$uri</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REQUEST_URI'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$vars</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$uri</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>So now we&#8217;ve captured the elements of the permalink in our array $vars, starting with the second array object, $vars[1]. The first array object, $vars[0] will return as blank. So let&#8217;s suppose the user is trying to go to this address:</p>
<p>http://www.yoursite.com/someuser/profile</p>
<p>$vars[1] will be &#8220;someuser&#8221;. $vars[2] will be &#8220;profile&#8221;. We can then use that information like so:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$user</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$vars</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$page</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$vars</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></pre></div></div>

<p>&#8230; and then use those variables to determine what data we output to the browser.</p>
<p>Easy as pie. <img src='http://www.ambitionlab.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.ambitionlab.com/code-your-own-permalinks-2009-12-09/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New Music Blog</title>
		<link>http://www.ambitionlab.com/new-music-blog-2009-10-18</link>
		<comments>http://www.ambitionlab.com/new-music-blog-2009-10-18#comments</comments>
		<pubDate>Sun, 18 Oct 2009 16:52:57 +0000</pubDate>
		<dc:creator>Raj</dc:creator>
				<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://www.ambitionlab.com/?p=168</guid>
		<description><![CDATA[I&#8217;ve started a music blog over at http://blog.rajeevsingh.com. I&#8217;ve noticed that most music blogs on the net are for sharing music that you like with the world.
Mine&#8217;s a little different. It&#8217;s a place for me to post my own music. Mostly just rough recordings of song ideas—I think of them as song seeds, since they&#8217;re [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve started a music blog over at <a title="Rajeev Singh's music blog" href="http://blog.rajeevsingh.com/">http://blog.rajeevsingh.com</a>. I&#8217;ve noticed that most music blogs on the net are for sharing music that you like with the world.</p>
<p>Mine&#8217;s a little different. It&#8217;s a place for me to post my own music. Mostly just rough recordings of song ideas—I think of them as song seeds, since they&#8217;re very short and I can flesh them out into more polished material at a later date (and hopefully in the future I&#8217;ll be posting that polished material as well).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ambitionlab.com/new-music-blog-2009-10-18/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ideas Are Lurking Inside Your Head. Want Them?</title>
		<link>http://www.ambitionlab.com/ideas-are-lurking-inside-your-head-want-them-2009-09-12</link>
		<comments>http://www.ambitionlab.com/ideas-are-lurking-inside-your-head-want-them-2009-09-12#comments</comments>
		<pubDate>Sat, 12 Sep 2009 05:34:34 +0000</pubDate>
		<dc:creator>Raj</dc:creator>
				<category><![CDATA[Articles]]></category>

		<guid isPermaLink="false">http://www.ambitionlab.com/?p=156</guid>
		<description><![CDATA[On August 29th, 2009, I had a bona fide epiphany.
The seed was planted one day earlier, on the 28th. I was talking with my friend Leah about a story she had written. It was short and simple, but it was built around a very unique and clever concept.
&#8220;How did you come up with that idea?&#8221; [...]]]></description>
			<content:encoded><![CDATA[<p>On August 29th, 2009, I had a bona fide epiphany.</p>
<p>The seed was planted one day earlier, on the 28th. I was talking with my friend Leah about a story she had written. It was short and simple, but it was built around a very unique and clever concept.</p>
<p>&#8220;How did you come up with that idea?&#8221; I asked her.</p>
<p>She said, &#8220;Well I was talking to a friend and he said something, and I thought, &#8216;hmm, that could be a story!&#8217;&#8221; We continued to chat and I didn&#8217;t think too much about those words at the time.</p>
<p>A day went by.</p>
<p>On the 29th, I was doing the dishes, and my brain was doing what it usually does when it&#8217;s on idle. It was replaying recent conversations. As I replayed that small snippet of my conversation with Leah, an idea struck me: Maybe all I have to do is say those words&#8230; so as I was scrubbing away at a particularly tough stain, I gave it a whirl. &#8220;Hmm, that could be a story!&#8221; I said.</p>
<p>Nothing happened.</p>
<p>Well, it can&#8217;t be that easy, can it? I was still convinced that I was on to something, though—I&#8217;m all about self-conditioning behavior by establishing and practicing routines—so I decided to get into the habit of reciting those words on a frequent basis. I said them in my head every chance I could.</p>
<p>Sure enough, later on that day, as my brain was once again recounting a conversation I&#8217;d had (this one was a little stale, being over a week old, but still tasty), I said those words to myself at just the right moment&#8230; and a story flooded into my head. It was like flipping on a light switch. One moment there was nothing. The next moment, I could see the whole thing. It worked! I was psyched.</p>
<p>Later on that day, as I was reading the news, I had another &#8220;hmm, that could be a story&#8221; moment&#8230; and then another an hour later. By the end of the day, I had a total of four story ideas, and each one of them struck me as genuinely interesting. To put this into context, that&#8217;s more story ideas than I had developed in the past year, much to my frustration.</p>
<p>It&#8217;s only been two weeks since then, but I&#8217;ve already had over twenty story ideas. At least one a day, as frequently as four times a day. Every one of them captivates me somehow. Most of them resonate with me in a very personal way.</p>
<p>While I don&#8217;t have the time to develop all of these ideas, that&#8217;s the least of my concerns. I&#8217;m one giant step ahead of where I was a few weeks ago. In terms of creative ideas, my mind went from being a barren wasteland to a healthy, slightly overgrown garden. Not too shabby.</p>
<p>But why did four and a half words make such a big difference for me? Here&#8217;s what I think happened: Those ideas were already there. But interesting ideas don&#8217;t lounge about waiting for you to notice them. They&#8217;re fleeting little things that hide in the nooks and crannies of your mind when you set out to look for them.</p>
<p>Want them? Then you have to catch them in the act. Find your weapon (mine are four and a half words, yours may be different), have it on hand at all times, and be ready to use it every chance you get.</p>
<p>Oh, and write them down. Ideas are slippery little things.</p>
<p><em>Note: This article was written for <a href="http://anotherguy.us/148/writing-experiment-3-where-do-you-get-your-inspiration/">Writing Experiment #3</a></em>. <em>Join us.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ambitionlab.com/ideas-are-lurking-inside-your-head-want-them-2009-09-12/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Moments of Indecision: A Mountain of Them</title>
		<link>http://www.ambitionlab.com/moments-of-indecision-a-mountain-of-them-2009-09-11</link>
		<comments>http://www.ambitionlab.com/moments-of-indecision-a-mountain-of-them-2009-09-11#comments</comments>
		<pubDate>Fri, 11 Sep 2009 06:47:42 +0000</pubDate>
		<dc:creator>Raj</dc:creator>
				<category><![CDATA[Articles]]></category>

		<guid isPermaLink="false">http://www.ambitionlab.com/?p=149</guid>
		<description><![CDATA[Has there ever been a moment in your life where you hesitated, and that brief moment cost you dearly? For some of you, I&#8217;m sure the answer is &#8220;yes&#8221;. But for most of you, I suspect the answer is &#8220;no&#8221;. I racked my brain for half an hour trying to think of single moments of [...]]]></description>
			<content:encoded><![CDATA[<p>Has there ever been a moment in your life where you hesitated, and that brief moment cost you dearly? For some of you, I&#8217;m sure the answer is &#8220;yes&#8221;. But for most of you, I suspect the answer is &#8220;no&#8221;. I racked my brain for half an hour trying to think of single moments of (in)decision that had a huge impact on my life. I drew a blank. Let&#8217;s face it, those moments are rare for most of us. Unless your job puts you in high-impact moments on a regular basis, your decision-making process probably includes the luxury of time.</p>
<p>Which begs the question: Why do we value decisiveness so much? Wouldn&#8217;t it seem logical to conclude that the best decisions are made with patience and consideration?</p>
<p>Well, yes&#8230; theoretically. But there&#8217;s a fatal flaw in that logic: It fails to consider fundamental human nature. Our minds are brilliant strategists. They play tricks on us constantly. My brain has tricked me out of  exercise, work, and opportunity a thousand times over&#8230; and masking indecision as &#8220;careful forethought and consideration&#8221; is one of its best weapons.</p>
<p>It works like this: I have to do something that involves making a decision. My brain says, &#8220;Hmm, let&#8217;s think about that first. How about we contemplate it while making a nice cup of tea?&#8221; I think to myself, <em>What a great idea, brain! </em> So I make the tea, and as I&#8217;m doing so, my brain whips out another trick. This one&#8217;s called, &#8220;A Quick Bite to Eat,&#8221; and it gets me every time. I cook. I eat. I get a phone call or an email. I get sidetracked.</p>
<p>Next thing I know, it&#8217;s tomorrow afternoon. Same time. Same place. Same decision sitting in front of me. And this time, my brain&#8217;s tricks are even more effective, because they&#8217;ve been re-enforced by my behavior from the previous day. So in the long run, that single moment of indecision had a huge impact on me.</p>
<p>Conclusion: Individual moments of indecision aren&#8217;t inherently bad. But when they become part of a pattern of procrastination, then you have a problem.</p>
<p>And I have a solution. It&#8217;s simple, really. Any time your brain sees a fork in the road and doesn&#8217;t want to choose one path or the other, you need to help it along. You need to have a procedure for making that decision. Just a few small steps that you know can be accomplished easily enough, without hesitation.</p>
<p>Let&#8217;s use a simple example: You&#8217;re asked whether you want Chinese pizza or Italian sushi for dinner. They both sound delicious to you and you could go either way. You don&#8217;t know what to say. Maybe you want to shrug and say, &#8220;Whatever, whichever.&#8221; But instead, you know that any time you&#8217;re faced with a decision and all options are equally good, your procedure is to first ask yourself which one is healthier. If there&#8217;s a clear-cut answer, then you choose that one. If not, you choose the first option that was mentioned.</p>
<p>That&#8217;s a procedure. All you have to do to employ them yourself is keep your eye out for moments of indecision in your own life, and then build your own procedures to prevent them from happening. Problem solved. Productivity improved. End of story.</p>
<p>P.S. Your brain will attempt to trick you out of your procedure initially. Mine is very good about making me forget things it finds inconvenient. Just keep trying, don&#8217;t give up, and it will eventually give in.</p>
<p><em>This article was in response to AnotherGuy&#8217;s <a href="http://anotherguy.us/140/writing-experiment-2-a-moment-of-indecision/">Writing Experiment #2</a>.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ambitionlab.com/moments-of-indecision-a-mountain-of-them-2009-09-11/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
