<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/atom10full.xsl" type="text/xsl" media="screen"?><?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/itemcontent.css" type="text/css" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-US">
  <title>thoughtsatsix - Home</title>
  <id>tag:www.thoughtsatsix.com,2008:mephisto/</id>
  <generator uri="http://mephistoblog.com" version="0.8.0">Mephisto Drax</generator>
  
  <link href="http://www.thoughtsatsix.com/" rel="alternate" type="text/html" />
  <updated>2008-06-17T15:21:21Z</updated>
  <link rel="self" href="http://feeds.feedburner.com/thoughtsatsix" type="application/atom+xml" /><entry xml:base="http://www.thoughtsatsix.com/">
    <author>
      <name>min</name>
    </author>
    <id>tag:www.thoughtsatsix.com,2008-06-17:16</id>
    <published>2008-06-17T15:04:00Z</published>
    <updated>2008-06-17T15:21:21Z</updated>
    <category term="curb" />
    <category term="ruby" />
    <category term="tinurl" />
    <link href="http://www.thoughtsatsix.com/2008/6/17/curb-your-tinyurls" rel="alternate" type="text/html" />
    <title>Curb your tinyurls</title>
<content type="html">
            URL shortening services such as tinyurl and snipurl have become popular lately.  Sometimes it's necessary to programmatically determine the original URL.  Here is a simple ruby method that uses curb (ruby bindings for libcurl) to expand the shortened URLs.

&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;
&lt;code class="ruby"&gt;
require 'curb'

def expand(url)
  request = Curl::Easy.perform(url) do |curl|
    curl.follow_location = true
  end

  request.last_effective_url
end

&gt;&gt; expand('http://tinyurl.com/2tx')
=&gt; "http://www.google.com"
&lt;/code&gt;
&lt;/pre&gt;
          &lt;img src="http://feeds.feedburner.com/~r/thoughtsatsix/~4/314215545" height="1" width="1"/&gt;</content>  </entry>
  <entry xml:base="http://www.thoughtsatsix.com/">
    <author>
      <name>min</name>
    </author>
    <id>tag:www.thoughtsatsix.com,2008-05-29:15</id>
    <published>2008-05-29T18:57:00Z</published>
    <updated>2008-05-29T18:57:49Z</updated>
    <category term="amazon" />
    <category term="summize" />
    <category term="twitter" />
    <link href="http://www.thoughtsatsix.com/2008/5/29/twizon-com" rel="alternate" type="text/html" />
    <title>Twizon.com</title>
<content type="html">
            Introducing &lt;a href="http://twizon.com"&gt;twizon.com&lt;/a&gt;.  A simple rails app that tracks what amazon products people are sharing on twitter.
          &lt;img src="http://feeds.feedburner.com/~r/thoughtsatsix/~4/314215547" height="1" width="1"/&gt;</content>  </entry>
  <entry xml:base="http://www.thoughtsatsix.com/">
    <author>
      <name>min</name>
    </author>
    <id>tag:www.thoughtsatsix.com,2007-12-18:10</id>
    <published>2007-12-18T17:20:00Z</published>
    <updated>2008-05-29T18:38:07Z</updated>
    <category term="javascript" />
    <category term="nan" />
    <category term="prototype" />
    <category term="yui" />
    <link href="http://www.thoughtsatsix.com/2007/12/18/when-a-number-is-nan-not-a-number" rel="alternate" type="text/html" />
    <title>When a number is NaN (Not a Number)</title>
<content type="html">
            I found something interesting with the NaN property in javascript.  The NaN property in javascript indicates that a value is "Not a Number".  Take a look at the example below:
&lt;br /&gt;&lt;br /&gt;


&lt;br /&gt;
So is the 'value' variable a number or not a number?
          &lt;img src="http://feeds.feedburner.com/~r/thoughtsatsix/~4/202321802" height="1" width="1"/&gt;</content>  </entry>
  <entry xml:base="http://www.thoughtsatsix.com/">
    <author>
      <name>min</name>
    </author>
    <id>tag:www.thoughtsatsix.com,2007-11-26:9</id>
    <published>2007-11-26T15:31:00Z</published>
    <updated>2007-11-26T15:31:28Z</updated>
    <category term="javascript equality" />
    <link href="http://www.thoughtsatsix.com/2007/11/26/javascript-equal-vs-strict-equal" rel="alternate" type="text/html" />
    <title>Strict equality in JavaScript</title>
<content type="html">
            This is probably a known fact to most people, but I decided to blog about it for those who aren't aware.  Two new comparison operators have been introduced since JavaScript 1.3, strict equal (===) and strict not equal (!==).  Strict equal (===) returns true if the operands are equal and of the same type.  Sounds pretty straightforward, then what's the difference between (==) and (===) ?.  Well, when you use the normal equality (==), JavaScript tries to convert both operands to be of the same type, before doing the comparison. 
&lt;br /&gt;&lt;br /&gt;
Let's look at some examples:  &lt;br /&gt;
&lt;pre&gt;&lt;code class="javascript"&gt;var one = 1;
one == '1';
&amp;gt;&amp;gt;&amp;gt; true
one === '1';
&amp;gt;&amp;gt;&amp;gt; false

var two;
two === undefined;
&amp;gt;&amp;gt;&amp;gt; true
two == undefined;
&amp;gt;&amp;gt;&amp;gt; true
two === null;
&amp;gt;&amp;gt;&amp;gt; false
two == null;
&amp;gt;&amp;gt;&amp;gt; true&lt;/code&gt;&lt;/pre&gt;
          &lt;img src="http://feeds.feedburner.com/~r/thoughtsatsix/~4/190784820" height="1" width="1"/&gt;</content>  </entry>
  <entry xml:base="http://www.thoughtsatsix.com/">
    <author>
      <name>min</name>
    </author>
    <id>tag:www.thoughtsatsix.com,2007-11-14:6</id>
    <published>2007-11-14T19:21:00Z</published>
    <updated>2007-11-14T23:08:50Z</updated>
    <category term="blueprint air css grid" />
    <link href="http://www.thoughtsatsix.com/2007/11/14/blueprintair-0-1" rel="alternate" type="text/html" />
    <title>BlueprintAIR 0.1 - Blueprint grid CSS generator</title>
<content type="html">
            &lt;br /&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;

I developed a simple Adobe AIR app that allows you to generate customized versions of &lt;a href="http://code.google.com/p/blueprintcss/"&gt;Blueprint's&lt;/a&gt; grid.css.  This app is just a desktop version of the online tool: &lt;a href="http://kematzy.com/blueprint-generator/"&gt;Blueprint Grid CSS Generator&lt;/a&gt;.

&lt;div&gt;&amp;nbsp;&lt;/div&gt;


          &lt;img src="http://feeds.feedburner.com/~r/thoughtsatsix/~4/184958280" height="1" width="1"/&gt;</content>  </entry>
  <entry xml:base="http://www.thoughtsatsix.com/">
    <author>
      <name>min</name>
    </author>
    <id>tag:www.thoughtsatsix.com,2007-10-12:5</id>
    <published>2007-10-12T16:55:00Z</published>
    <updated>2007-11-16T21:11:28Z</updated>
    <category term="ActionScript" />
    <category term="actionscript as3 string array" />
    <link href="http://www.thoughtsatsix.com/2007/10/12/prototype-js-like-functions-for-as3" rel="alternate" type="text/html" />
    <title>Prototype.js like functions for ActionScript 3</title>
<content type="html">
            One of the nice things about javascript is that there are now so many libraries that make our lives easier.  I've especially come to love some of the rubyesque string, enumerable helpers that &lt;a href="http://www.prototypejs.org/"&gt;prototype.js&lt;/a&gt; has to offer for javascript.&lt;br /&gt;
When recently started to program in ActionScript 3, it brought me back to the pre-prototype, pre-jquery, pre-dojo, etc, days of javascript.  So, at least for my benefit I started to port many of the prototype.js string/enumerable functions for actionscript 3.  The result can be found &lt;a href="http://code.google.com/p/as3extensions/"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;

Array helpers:&lt;br /&gt;
&lt;pre&gt;&lt;code class="javascript"&gt;import com.as3extensions.helpers.EnumerableHelper;

var array:Array = ['foo', 'bar'];

// Calls the method 'toUpperCase()' on each element 
// of the array
EnumerableHelper.invoke(array, 'toUpperCase');
&amp;gt;&amp;gt;&amp;gt; ['FOO', 'BAR']&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
String helpers:&lt;br /&gt;
&lt;pre&gt;&lt;code class="javascript"&gt;import com.as3extensions.helpers.StringHelper;

StringHelper.interpolate('My name is #{firstname} #{lastname}', 
                         {firstname: 'Foo', lastname: 'Bar'})
&amp;gt;&amp;gt;&amp;gt; My name is Foo Bar&lt;/code&gt;&lt;/pre&gt;
          &lt;img src="http://feeds.feedburner.com/~r/thoughtsatsix/~4/184958281" height="1" width="1"/&gt;</content>  </entry>
  <entry xml:base="http://www.thoughtsatsix.com/">
    <author>
      <name>min</name>
    </author>
    <id>tag:www.thoughtsatsix.com,2007-09-27:2</id>
    <published>2007-09-27T21:52:00Z</published>
    <updated>2007-09-28T20:19:44Z</updated>
    <category term="javascript prototype behavior" />
    <link href="http://www.thoughtsatsix.com/2007/9/27/reducing-the-number-of-prototype-observers" rel="alternate" type="text/html" />
    <title>Reducing the number of Prototype observers</title>
<content type="html">
            Let's say you have a list of elements, and you want to apply some javascript behaviors to each element.

&lt;pre&gt;&lt;code class="html"&gt;&amp;lt;ul id=&amp;quot;parent&amp;quot;&amp;gt;
  &amp;lt;li class=&amp;quot;child-1&amp;quot;&amp;gt;One&amp;lt;/li&amp;gt;
  &amp;lt;li class=&amp;quot;child-2&amp;quot;&amp;gt;Two&amp;lt;/li&amp;gt;
  &amp;lt;li class=&amp;quot;child-3&amp;quot;&amp;gt;Three&amp;lt;/li&amp;gt;
&amp;lt;/ul&amp;gt;&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
One way of doing this is to use prototype's built-in DOM selector to retrieve the list of elements and apply the appropriate function to each element.

&lt;pre&gt;&lt;code class="javascript"&gt;var children = $('parent').getElementsBySelector('li');

  children.invoke('observe', 'click', function(e){
 e.observe('click', function(event) { alert(e.innerHTML); }
});&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;

This is ok if you have one, two or maybe three elements in the list, but what if there are 20, or even 200 elements.  And better yet, what if the list was dynamic.  You would have to constantly add an observer for new elements, and cleanup observers for deleted elements.
&lt;br /&gt;&lt;br /&gt;
A better approach is to add a single behavior to the parent.  By observing the parent, you're able to capture events triggered by all of it's children as well.  Then we can add conditional logic to apply a function to only the child elements we care about.
&lt;br /&gt;

&lt;pre&gt;&lt;code class="javascript"&gt;$('parent').observe('click', function(event) {
  var e = Event.element(event);
  if(e.tagName != 'LI') return;
  alert(e.innerHTML);
});&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;

We can also call differentiate function calls based on the child.
&lt;br /&gt;

&lt;pre&gt;&lt;code class="javascript"&gt;$('parent').observe('click', function(event) {
  var e = Event.element(event);
  if(e.tagName != 'LI') return;

  switch(e.className) {
    case 'child-1':
      alert(&amp;quot;it's a boy!&amp;quot;);
      break;
    case 'child-2':
      alert(&amp;quot;it's a girl!&amp;quot;);
      break;
    case 'child-3'
      alert(&amp;quot;this one's a mistake!&amp;quot;);
      break;
   }
});&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
          &lt;img src="http://feeds.feedburner.com/~r/thoughtsatsix/~4/184958282" height="1" width="1"/&gt;</content>  </entry>
</feed>
