<?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>Alagad Ally</title>
	<atom:link href="http://blog.alagad.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.alagad.com</link>
	<description>Web Development Task Force</description>
	<lastBuildDate>Tue, 29 Nov 2011 16:48:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>CoolBeans &#8211; an IOC container for Node.js</title>
		<link>http://blog.alagad.com/2011/11/29/coolbeans-an-ioc-container-for-node-js/</link>
		<comments>http://blog.alagad.com/2011/11/29/coolbeans-an-ioc-container-for-node-js/#comments</comments>
		<pubDate>Tue, 29 Nov 2011 16:47:42 +0000</pubDate>
		<dc:creator>Doug Hughes</dc:creator>
				<category><![CDATA[ColdSpring]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[node.js]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.alagad.com/?p=1895</guid>
		<description><![CDATA[I just finished writing my first publicly available module for Node.js.  If you&#8217;re not familiar with Node.js, well, I&#8217;m just sorry to hear that.  Go learn. The module I wrote is called CoolBeans. (Thanks for the name, Mr. Chris Peterson). CoolBeans is ...]]></description>
			<content:encoded><![CDATA[<p>I just finished writing my first publicly available module for Node.js.  If you&#8217;re not familiar with Node.js, well, I&#8217;m just sorry to hear that.  <a href="http://nodejs.org">Go learn.</a></p>
<p>The module I wrote is called CoolBeans. (Thanks for the name, Mr. Chris Peterson). CoolBeans is an Inversion of Control (IOC) / Dependency Injection (DI) library for Node.js. CoolBeans is loosely based on ColdSpring for ColdFusion and Spring IOC for Java. It&#8217;s a single js file and currently appears to be quick and easy.</p>
<p>To install:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">npm install CoolBeans</pre></div></div>

<p>To use CoolBeans you simply create an instance of the CoolBeans and load the configuration file like this:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> cb <span style="color: #339933;">=</span> require<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;CoolBeans&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
cb <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> cb<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;./config/dev.json&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The above code is the only require function you should need in your entire application. Once you&#8217;ve required CoolBeans you need to create a new instance and pass in the path to its&#8217; configuration. This is shown above.</p>
<p>Once you have the fully loaded CoolBeans you can use it to quickly create fully configured singleton objects based on its&#8217; configuration. The config file for CoolBeans is a JSON file so the entire thing is wrapped in {}.</p>
<p>Each element in the root of the configuration file is a bean (bean = Java for object) that CoolBeans can create. Here&#8217;s an example:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#123;</span>
     <span style="color: #3366CC;">&quot;fs&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;module&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;fs&quot;</span><span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This is essentially the same as:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> fs <span style="color: #339933;">=</span> require<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;fs&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>However, we now only need to define this one time for an application, rather than in each file that requires it.</p>
<p>You can also specify paths to modules that are not node_modules. For example:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#123;</span>
     <span style="color: #3366CC;">&quot;Recipient&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;module&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;./entities/recipient&quot;</span><span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>At the most basic, the above means that CoolBeans will call require for the module and cache the results in a variable named Recipient.</p>
<p>As a relative newb to Node.js, I think I&#8217;ve handled this correctly. CoolBeans is a node module which means that NPM will install into ./node_modues/CoolBeans. The actual CoolBeans script is in the lib directory. That means, that from the perspective of CoolBeans your components are three directories above it. For this reason, CoolBeans looks three directories above it for the module specified. So, the Recipient module above actually turns into ../../.././entities/recipient. This has the effect of making the paths to modules specified in the configuration file relative to the root of your module or application. So, if you make a module that depends on CoolBeans and later publish it via NPM I think it should work correctly when used in other projects.</p>
<p>You can get any of the configured beans by calling cb.get(&#8220;beanName&#8221;) where beanName is the name of the bean you want to get. For example:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">cb.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Recipient&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The above will lazily create the Recipient bean, cache it as a singleton, and return it.</p>
<p>You can get a lot more complex with configuration too. For example, you can specify if CoolBeans should call a constructor and what arguments to pass into the constructor. For example:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #3366CC;">&quot;codeGenerator&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
     <span style="color: #3366CC;">&quot;module&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;./util/codeGenerator&quot;</span><span style="color: #339933;">,</span>
     <span style="color: #3366CC;">&quot;constructorArgs&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>
         <span style="color: #3366CC;">&quot;foo&quot;</span><span style="color: #339933;">,</span>
         <span style="color: #CC0000;">123</span>
    <span style="color: #009900;">&#93;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>What the above is saying is that when we get the codeGenerator bean, we need to load the module specified then call new on the module and pass in the values specified in the constructorArgs section to the constructor. The above means:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">new</span> codeGenerator<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;foo&quot;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">123</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>You can also specify more complex values to pass into constructor arguments:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #3366CC;">&quot;codeGenerator&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #3366CC;">&quot;module&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;./util/codeGenerator&quot;</span><span style="color: #339933;">,</span>
    <span style="color: #3366CC;">&quot;constructorArgs&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>
        <span style="color: #3366CC;">&quot;foo&quot;</span><span style="color: #339933;">,</span>
        <span style="color: #CC0000;">123</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">3</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">:</span>
            <span style="color: #009900;">&#123;</span>
                <span style="color: #3366CC;">&quot;foo&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;bar&quot;</span><span style="color: #339933;">,</span>
                <span style="color: #3366CC;">&quot;bar&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;foo&quot;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
     <span style="color: #009900;">&#93;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Note that while you can specify a string without indicating explicitly it&#8217;s a &#8220;value&#8221;, for arrays and anonymous objects you need to provide an object with a property named &#8220;value&#8221; whose value is the value you&#8217;re trying to pass in. The above could be written more explicitly as:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #3366CC;">&quot;codeGenerator&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #3366CC;">&quot;module&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;./util/codeGenerator&quot;</span><span style="color: #339933;">,</span>
    <span style="color: #3366CC;">&quot;constructorArgs&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>
         <span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;foo&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
         <span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">:</span> <span style="color: #CC0000;">123</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
         <span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">3</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
         <span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">:</span>
             <span style="color: #009900;">&#123;</span>
                  <span style="color: #3366CC;">&quot;foo&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;bar&quot;</span><span style="color: #339933;">,</span>
                  <span style="color: #3366CC;">&quot;bar&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;foo&quot;</span>
              <span style="color: #009900;">&#125;</span>
         <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#93;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Strings, numbers, arrays, and anonymous objects are not the only things you can pass into constructors. You can also specify other beans that could be passed in. For example, let&#8217;s say we had a database configuration object you want to pass into any object that is used to access data you could do the following:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #3366CC;">&quot;mysql&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;module&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;mysql&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
<span style="color: #3366CC;">&quot;dbConfig&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #3366CC;">&quot;properties&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #3366CC;">&quot;host&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;server.hostname.com&quot;</span><span style="color: #339933;">,</span>
        <span style="color: #3366CC;">&quot;port&quot;</span><span style="color: #339933;">:</span> <span style="color: #CC0000;">3306</span><span style="color: #339933;">,</span>
        <span style="color: #3366CC;">&quot;user&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;mysqlUser&quot;</span><span style="color: #339933;">,</span>
        <span style="color: #3366CC;">&quot;password&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;password123&quot;</span><span style="color: #339933;">,</span>
        <span style="color: #3366CC;">&quot;database&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;foobar&quot;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
<span style="color: #3366CC;">&quot;recipientDao&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #3366CC;">&quot;module&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;./db/recipientDao&quot;</span><span style="color: #339933;">,</span>
    <span style="color: #3366CC;">&quot;constructorArgs&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>
        <span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;bean&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;dbConfig&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;bean&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;mysql&quot;</span><span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#93;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The mysql bean is simply the same as saying require(&#8220;mysql&#8221;). The dbConfig is an anonymous object with properties specified (more on this in a bit). When the recipientDao (dao = data access object) is created, CoolBeans will see the &#8220;bean&#8221; property and will create and pass into the constructor the fully-constructed dbConfig object and the mysql object. Here&#8217;s what that recipientDao might look like:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">module.<span style="color: #660066;">exports</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>dbConfig<span style="color: #339933;">,</span> mysql<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">listRecipients</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>userId<span style="color: #339933;">,</span> callback<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">var</span> client <span style="color: #339933;">=</span> mysql.<span style="color: #660066;">createClient</span><span style="color: #009900;">&#40;</span>dbConfig<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        client.<span style="color: #660066;">query</span><span style="color: #009900;">&#40;</span>
        <span style="color: #3366CC;">&quot;SELECT id, name, addressLine1, IfNull(addressLine2, '') as addressLine2, city, state, zip, taxDeductible, created, updated, 0 as netDonations &quot;</span> <span style="color: #339933;">+</span>
        <span style="color: #3366CC;">&quot;FROM recipient &quot;</span> <span style="color: #339933;">+</span>
        <span style="color: #3366CC;">&quot;WHERE userId = ? AND deleted = 0 &quot;</span><span style="color: #339933;">+</span>
        <span style="color: #3366CC;">&quot;ORDER BY name&quot;</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#91;</span>userId<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
        <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>err<span style="color: #339933;">,</span> results<span style="color: #339933;">,</span> fields<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            client.<span style="color: #660066;">end</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            callback<span style="color: #009900;">&#40;</span>results<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></pre></div></div>

<p>Note that there are no require statements. The object just gets its&#8217; dependencies when it&#8217;s instantiated and can immediately use them. These dependencies are also automatically singletons.</p>
<p>Also note that if you want to use a transient object you would still create an instance of it the way you always have.</p>
<p>I also mentioned above that CoolBeans can be used to create create and populate anonymous objects. For example:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #3366CC;">&quot;dbConfig&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #3366CC;">&quot;properties&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #3366CC;">&quot;host&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;server.hostname.com&quot;</span><span style="color: #339933;">,</span>
        <span style="color: #3366CC;">&quot;port&quot;</span><span style="color: #339933;">:</span> <span style="color: #CC0000;">3306</span><span style="color: #339933;">,</span>
        <span style="color: #3366CC;">&quot;user&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;mysqlUser&quot;</span><span style="color: #339933;">,</span>
        <span style="color: #3366CC;">&quot;password&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;password123&quot;</span><span style="color: #339933;">,</span>
        <span style="color: #3366CC;">&quot;database&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;foobar&quot;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This is a somewhat long-winded way of saying</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">dbConfig <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #3366CC;">&quot;host&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;server.hostname.com&quot;</span><span style="color: #339933;">,</span>
    <span style="color: #3366CC;">&quot;port&quot;</span><span style="color: #339933;">:</span> <span style="color: #CC0000;">3306</span><span style="color: #339933;">,</span>
    <span style="color: #3366CC;">&quot;user&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;mysqlUser&quot;</span><span style="color: #339933;">,</span>
    <span style="color: #3366CC;">&quot;password&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;password123&quot;</span><span style="color: #339933;">,</span>
    <span style="color: #3366CC;">&quot;database&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;foobar&quot;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<p>However, once this object is configured in CoolBeans you can easily pass it into other objects when they are created.</p>
<p>You can also specify properties for not-anonymous objects. You can also mix and match constructorArgs and properties.</p>
<p>For example:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #3366CC;">&quot;creditCardDao&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #3366CC;">&quot;module&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;./db/creditCardDao&quot;</span><span style="color: #339933;">,</span>
    <span style="color: #3366CC;">&quot;constructorArgs&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>
        <span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;bean&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;dbConfig&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;bean&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;authorize&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;bean&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;mysql&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;bean&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;CreditCard&quot;</span><span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
    <span style="color: #3366CC;">&quot;properties&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
         <span style="color: #3366CC;">&quot;service&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;bean&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;service&quot;</span><span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>When CoolBeans creates the creditCardDao it will first load all the beans specified in the constructorArgs. It will then create the creditCardDao and pass in the four already-created beans to the constructor. Once the object is constructed it will set the service property on the object to the specified service bean. Note, CoolBeans will look for a setter and use that if it can find it. For example, in the service property above, ColdBooks will first look for a function named setservice (note that this is case sensitive). If it can find it, it will pass in the service bean to that function. If not, it will simply set a public property on the object.</p>
<p>There are a few other interesting capabilities of CoolBeans:</p>
<p>Beans don&#8217;t have to be lazily loaded. You can set a bean to load when the container loads. For example:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #3366CC;">&quot;dateFormat&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #3366CC;">&quot;module&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;./util/dateFormat&quot;</span><span style="color: #339933;">,</span>
    <span style="color: #3366CC;">&quot;lazy&quot;</span><span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Also, if you have a factory that is used to construct other objects, you can specify this using the factoryBean and factoryMethod properties. For example:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #3366CC;">&quot;knox&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;module&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;knox&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
<span style="color: #3366CC;">&quot;s3client&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #3366CC;">&quot;factoryBean&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;knox&quot;</span><span style="color: #339933;">,</span>
    <span style="color: #3366CC;">&quot;factoryMethod&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;createClient&quot;</span><span style="color: #339933;">,</span>
    <span style="color: #3366CC;">&quot;constructorArgs&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>
        <span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">:</span>
            <span style="color: #009900;">&#123;</span>
                <span style="color: #3366CC;">&quot;key&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;myKey&quot;</span><span style="color: #339933;">,</span>
                <span style="color: #3366CC;">&quot;secret&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;mySecret&quot;</span><span style="color: #339933;">,</span>
                <span style="color: #3366CC;">&quot;bucket&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;myBucket&quot;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#93;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The above s3client bean is configured so CoolBeans uses Knox to create it. The constructor args are passed into the factoryMethod as if it were a constructor. The above essentially boils down to:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">s3client <span style="color: #339933;">=</span> knox.<span style="color: #660066;">createClient</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #3366CC;">&quot;key&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;myKey&quot;</span><span style="color: #339933;">,</span>
    <span style="color: #3366CC;">&quot;secret&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;mySecret&quot;</span><span style="color: #339933;">,</span>
    <span style="color: #3366CC;">&quot;bucket&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;myBucket&quot;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The really nice thing about CoolBeans is that it lets the objects in your system stay focused on what they do best. It shouldn&#8217;t be your object&#8217;s responsibility to know what they need to work. They should simply get what they need to work when they&#8217;re created. CoolBeans also helps avoid situations in complex apps where you have dozens of lines of code just getting dependencies created just to create one object that otherwise happens to have a lot of dependencies. Lastly, CoolBeans allows you to easily change how your application is configured in different environments.</p>
<p>If you&#8217;re a Node.js developer I&#8217;d love to hear your thoughts on CoolBeans!  Heck, I&#8217;d love to hear your thoughts even if you&#8217;re not.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.alagad.com/2011/11/29/coolbeans-an-ioc-container-for-node-js/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Starting a new project using node.js</title>
		<link>http://blog.alagad.com/2011/11/18/starting-a-new-project-using-node-js/</link>
		<comments>http://blog.alagad.com/2011/11/18/starting-a-new-project-using-node-js/#comments</comments>
		<pubDate>Fri, 18 Nov 2011 12:16:09 +0000</pubDate>
		<dc:creator>cpeterson</dc:creator>
				<category><![CDATA[node.js]]></category>

		<guid isPermaLink="false">http://blog.alagad.com/?p=1889</guid>
		<description><![CDATA[So this week I am starting a &#8216;super secret&#8217; application, and for various reasons we have decided to develop this with node.js. In no particular order, here are some of my impressions and thoughts as I get my feet ...]]></description>
			<content:encoded><![CDATA[<p>So this week I am starting a &#8216;super secret&#8217; application, and for various reasons we have decided to develop this with node.js. In no particular order, here are some of my impressions and thoughts as I get my feet wet with node.js and some of its various frameworks.</p>
<p>First of all, if you have not used node before, know this: node is FAST! I mean, blow your socks off fast. I&#8217;m used to a J2EE app running in a JRun / Tomcat style context, and waiting for the various application frameworks and entities to get loaded up usually takes some time. Well, when you type &#8216;node app.js&#8217;, the app is running, instantly. Making requests to the page from your browser, they load *instantly*. Stop / restart the server, seems only limited by how fast you can type. I was curious and made some simple page returns from node, and ran a load tester against it. With no delay in my jMeter test, on my local development system, I was retrieving the root page of this node app at approx. 180 page requests / second, regardless of how many simultaneous users I sent in.</p>
<p>Now, not having worked with node before, I spent some time gathering resources online. One of my favorite so far is <a href="http://howtonode.org/" target="_blank">http://howtonode.org/</a>. We have decided to use Express, an application development framework for node. You can get an express intro <a href="http://www.screenr.com/elL" target="_blank">http://www.screenr.com/elL</a>, and you can install using npm (the node package manager) with &#8216;npm install express&#8217;. Get more information about express from <a href="https://github.com/visionmedia/express/blob/master/Readme.md" target="_blank">https://github.com/visionmedia/express/blob/master/Readme.md</a>.</p>
<p>My favorite part so far for node (besides the insane speed and low server resource utilization) is that I am leveraging existing knowledge. I have been working with javascript many years, so in a lot of ways I feel like I&#8217;m just learning a new framework, rather than an entire new language. I like the level of control that I have over the request, and am enjoying using a whole new stack for app development (git, node, textmate as IDE). Watch this 2nd screencast about using route specific middleware <a href="http://www.screenr.com/mAL" target="_blank">http://www.screenr.com/mAL</a>, very exciting the capabilities of this framework, and I look forward to learning more as this project develops!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.alagad.com/2011/11/18/starting-a-new-project-using-node-js/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Soliciting Stack Suggestions</title>
		<link>http://blog.alagad.com/2011/07/27/soliciting-stack-suggestions/</link>
		<comments>http://blog.alagad.com/2011/07/27/soliciting-stack-suggestions/#comments</comments>
		<pubDate>Wed, 27 Jul 2011 15:42:03 +0000</pubDate>
		<dc:creator>Doug Hughes</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[ColdSpring]]></category>
		<category><![CDATA[Development Tools]]></category>
		<category><![CDATA[Farcry CMS]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Model-Glue]]></category>
		<category><![CDATA[Mura]]></category>
		<category><![CDATA[OO Development]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.alagad.com/?p=1877</guid>
		<description><![CDATA[I am part owner of another web company, which shall remain unnamed.  A few years ago I (and a couple others) wrote their current web application.  Initially the application was sufficient, but over time we’ve run into some limitations ...]]></description>
			<content:encoded><![CDATA[<p>I am part owner of another web company, which shall remain unnamed.  A few years ago I (and a couple others) wrote their current web application.  Initially the application was sufficient, but over time we’ve run into some limitations of the application’s architecture.</p>
<p>For example, this was written before I realized that writing fat controllers was a bad idea.  In fact, this is such an early project that it ran on a pre-1.0 version of Model-Glue.  There was no concept of ColdSpring at all.  It used a stand-alone tool to generate the data access layer (which eventually inspired me to write Reactor, which is now also defunct).</p>
<p>Furthermore, the business requirements have changed over time.  The site was initially built to satisfy one specific use case: selling a given product in one specific way.</p>
<p>Overtime the business team has requested new features that are difficult or impractical to implement in the existing architecture.  For example, they want to be able to edit and add content on the site without involving me or any other technical staff.  They also want to start selling other products in slightly different ways from their original plans.</p>
<p>Long story short, it’s time for a rewrite.  I now need to choose a stack of frameworks, languages, etc, that are appropriate for this project. I’m afraid that I’m over complicating things and was hoping that the general Internet might have some suggestions.</p>
<p>So here’s what I can say I think I need:</p>
<ul>
<li>I need a Content Management system that allows the business and marketing team to add pages to the site, edit content, and generally manage the Information Architecture of the site.  They need this because I am not as responsive to their requests as they would like.  I do have Alagad to run on a day-to-day basis.</li>
<li>I need to write custom code that integrates with the CMS to support the unique business requirements of this application.  This would include management of the product being sold, reporting, integration with other third party systems, and more.  There really are not any off the shelf tools that I could use to replace this custom work.  I really want to write this code to leverage IOC and OO.  One of the biggest challenges we’ve had with the existing site is that it is mostly pseudo-OO, which makes changes and enhancements more difficult to implement.  Hence, the rewrite we need to do!</li>
</ul>
<p>For a content-heavy site I’d typically use an off-the-shelf CMS like Mura or Farcry.  For a custom-code-heavy site I’d typically use Model-Glue and ColdSpring to help me structure clean maintainable code.</p>
<p>The problem comes in when I try to do both:  Use a CMS and write clean maintainable code.</p>
<p>My experiences (though dated) with Farcry pretty much suggest that you have to write code Farcry’s way if you want to do anything custom.  I honestly just don’t like Farcry’s approach.</p>
<p>I’ve also worked with Mura quite a bit over the last year on a different project. For that, we used Mura as the CMS and wrote a Mura plugin to run Model-Glue events based on how a content element is configured in Mura.  It’s <strong><em>my</em></strong> opinion that this was a reasonably good stack.</p>
<p>I’ve even considered writing my own CMS that integrates nicely with Model-Glue, but that’s really a non-starter.</p>
<p>For this rewrite I have been planning to use the following stack:</p>
<ul>
<li>Mura for content Management.</li>
<li>ColdSpring, Model-Glue and Hibernate for custom code that will be run within Mura via a Mura plugin.</li>
<li>JQuery</li>
<li>This would be run on Railo, which would run in Tomcat.</li>
<li>Eventually this would be deployed as a WAR to Amazon Elastic Beanstalk or another Java Platform-As-A-Service provider.</li>
</ul>
<p>And while that seems like a reasonable stack to me, I have a few concerns:</p>
<ul>
<li><strong>Overall performance:</strong> The Mura + Model-Glue project I mentioned earlier has been suffering general performance woes.   Many of these could be attributed to the sheer volume of custom code and the fact that it is not running the latest updates to Mura and Model-Glue. These have mostly been ironed out, but it’s still an area of concern to me.</li>
<li><strong>I might be crazy:</strong> To me, the stack above makes sense.  However, every other developer who has worked with me on this stack doesn’t like it.  At all.  Some developers dislike Mura.  Some developers dislike the Model-Glue integration.  Some developers think the stack is too deep.  Some dislike using unfamiliar platforms like Tomcat and Amazon EBS.  Lastly, very few developers have experience with the complete stack (even when you ignore Tomcat and Amazon).</li>
</ul>
<p>I know I could build this system using the stack I’ve outlined above and I’m reasonably sure I can get it to perform well.  However, I feel like I’m not seeing something that everyone else sees.  I’ve even had three contract developers quit in the early phases of this project.</p>
<p>I’m not sure if my stack should change.  Thinking pragmatically, can you think of an alternative approach to this problem?  One that lets the business and marketing teams have the flexibility they need and also allows developers to write clean, well structured code, using the latest best practices?</p>
<p>I’m open to all suggestions.  I’ve been considering other languages and platforms.  However, I also need to keep in mind my learning curve on any other tools or languages that might be used as well as unique business requirements that may make some choices impractical.</p>
<p>I’d greatly appreciate your suggestions.  What are your thoughts?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.alagad.com/2011/07/27/soliciting-stack-suggestions/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>I have an idea.</title>
		<link>http://blog.alagad.com/2011/06/06/i-have-an-idea/</link>
		<comments>http://blog.alagad.com/2011/06/06/i-have-an-idea/#comments</comments>
		<pubDate>Mon, 06 Jun 2011 14:53:48 +0000</pubDate>
		<dc:creator>Doug Hughes</dc:creator>
				<category><![CDATA[Alagad]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Ideas]]></category>

		<guid isPermaLink="false">http://blog.alagad.com/?p=1867</guid>
		<description><![CDATA[Actually, I have lots of ideas. I have so many ideas that I started a twitter account, @DougsIdeas, where I try to tweet one new idea a day.  Not all of my ideas are great, but I truly believe ...]]></description>
			<content:encoded><![CDATA[<p>Actually, I have lots of ideas.</p>
<p>I have so many ideas that I started a twitter account, <a href="http://twitter.com/#!/dougsideas" target="_blank">@DougsIdeas</a>, where I try to tweet one new idea a day.  Not all of my ideas are great, but I truly believe some have real potential.  This particular idea, the one I’m writing about right now, may or may not have legs.  But, its one of the simpler ideas for me to try and, if it works, it will be awesome!</p>
<p>But before I explain my idea, allow me to try to explain myself:</p>
<p>There is nothing I enjoy more than having an idea and bringing it to life.  I have worked on more than a hundred unique projects in my career.  These projects have been for past employers, clients in a plethora of industries, and myself.  The one thing that these projects all have in common is that they were all quite distinct.  Rarely have I done the same thing twice.</p>
<p>Because of this, I have become not just a reasonably talented programmer, but I’ve also very good at quickly understanding problem domains, finding solutions, and implementing those solutions.  Quite simply, this is what I excel at!</p>
<p>An interesting side effect of this is that I find myself subconsciously analyzing the world around me and finding problems or inefficiencies. I simply can’t help but think up ways I would solve these problems.  Ideas are always popping up into my head.  And some of these ideas I really, really, want to work on.</p>
<p>But I have a challenge: I have to pay my bills and the bills of my employees.  To pay my bills I have to do work for my clients.  (Which, by the way, I also really, really, enjoy!)  However, it has become increasingly difficult to do my “real” job to the best of my abilities, fulfill my familial roles of husband and father, and also work on any of these ideas.  Something has to give, and naturally it’s the idea work.</p>
<p>This challenge led me to today’s idea:</p>
<p>My idea is that there must be someone who will invest in… me.  Well, really, to invest in my ideas – to partner with me on bringing some of my better ideas to fruition.</p>
<p>Without getting into details, here are a few one-line summaries of some of the ideas I have in my head.  I have ideas on how to monetize all of the following concepts.  Take a look and see if any of these pique your interest:</p>
<ul>
<li>A social rating tool that lets anyone express their opinions about any given topic in real time. (This one is actually almost done and has huge potential.)</li>
</ul>
<ul>
<li>A unique tool to help people identify things in the world around them such as bugs, plants, and anything else.</li>
</ul>
<ul>
<li>A way to get rich from the lottery. (I know how this sounds.  It’s not what you’re thinking!)</li>
</ul>
<ul>
<li>A way for people who use social networks to share their lives to also share that same information with friends and family who aren’t on the social networking bandwagon, or even the internet.</li>
</ul>
<ul>
<li>A way for audiences of any size to provide input for the purposes of information gathering, education, entertainment, and more.</li>
</ul>
<ul>
<li>A tool that will very efficiently calculate cut plans for wood working projects based on the needs and what’s available. It’ll even create a shopping list for you. (This is pretty much done.)</li>
</ul>
<ul>
<li>A self-scooping cat litter box that would, believe it or not, actually work. (And I’ve owned just about all of the ones on the market.  They’re all terrible.)</li>
</ul>
<ul>
<li>A new drive mechanism for remote control cars that uses neither battery nor nitro fuel.</li>
</ul>
<ul>
<li>I even have a few philanthropic ideas related to health care and helping the world’s poor become less poor.</li>
</ul>
<ul>
<li>And much, much more.</li>
</ul>
<p>More ideas are listed over <a href="http://twitter.com/#!/dougsideas" target="_blank">@DougIdeas</a>.</p>
<p>I think some of my ideas have real potential.  Maybe not all of them are million or billion dollar ideas, but I believe there is some real potential.  Personally, I’d rather have 10 $100,000 per year streams of income than one $1,000,000 stream.</p>
<p>If I simply had time to work on these ideas sequentially, one at a time, I believe I could fail quickly.  What I mean is that many of these ideas would take only a few weeks or perhaps a couple of months to get working to a point where they could be released for general usage.  Those ideas that don’t grow quickly could be sold off or thrown out.  Those that do grow would be reinvested in.   Many of these projects will also yield potentially patentable or resalable intellectual property.</p>
<p>As it is now, I may get 10 or so hours per week to work on my concepts.  A project that should only take two months of concerted effort currently takes me eight months or more to complete.  I could be doing upwards of six or more projects a year where, right now, I’m doing perhaps one.  The inefficiency is taxing and very frustrating!</p>
<p>What I want to do is find a partner – someone with more money than sense, I suppose.  This person would invest in me – and my ideas.  I would work with them to identify and develop specific concepts, define a road map for these ideas, and build and market these ideas.  Our focus would be on growing (or failing) quickly with minimal investment.  Those ideas that succeed would be spun off into separate companies with their own management and staff and be self funded.  I suppose some of these ideas could even potentially go public some day.</p>
<p>I’m not sure what the final structure of this arrangement would be, but I’m definitely open to suggestions.  One option might be that the investor would get half of everything.  Another might be that we’d both get 33% with another 33% held to the side for additional future investments from third parties.  The more I think about this, the more I realize these details would need to be worked out in negotiations.  I hope that anyone who might consider this can see that I’m open to various ideas.</p>
<p>The only thing I’d be looking for out of this, aside from my portion of the companies that are created, is the funds I need, month to month, to pay for my current staff of four people and our minimal expenses.  The staff expenses may grow over time, but would ideally be paid for out of income earned.</p>
<p>So, there’s my big idea.  Yes, I realize it’s a long shot.  But I’ve always tried to live by the philosophy that it never hurts to ask.  I’ve got to believe that there’s someone out there who would be willing to take a chance on me – and my ideas.</p>
<p>If you know someone who might be interested in talking to me about this investment and partnership concept, please put them in contact with me.</p>
<p>If you’re interested in exploring this concept with me, you can always contact me using the following information:</p>
<p>Doug Hughes<br />
<a href="mailto:dhughes@alagad.com">dhughes@alagad.com<br />
</a>651-252-4234 (Office and Cell)</p>
<p>Or you can simply add a comment to this blog entry.</p>
<p>And there we have it, my idea for the day!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.alagad.com/2011/06/06/i-have-an-idea/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Remember to Contribute to OSS (or Tweet) to Get an Alagad Backpack</title>
		<link>http://blog.alagad.com/2010/12/23/remember-to-contribute-to-oss-or-tweet-to-get-an-alagad-backpack/</link>
		<comments>http://blog.alagad.com/2010/12/23/remember-to-contribute-to-oss-or-tweet-to-get-an-alagad-backpack/#comments</comments>
		<pubDate>Thu, 23 Dec 2010 14:45:44 +0000</pubDate>
		<dc:creator>Doug Hughes</dc:creator>
				<category><![CDATA[Alagad]]></category>
		<category><![CDATA[Contests]]></category>
		<category><![CDATA[Open Source]]></category>

		<guid isPermaLink="false">http://blog.alagad.com/?p=1854</guid>
		<description><![CDATA[Pardon the shortness of this post, I simply wanted to remind those out there who follow this blog that I&#8217;m holding a contest to give away a very nice Alagad Swiss Gear laptop backback.  To quote Vicky Rider of ...]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.alagad.com/wp-content/uploads/2010/10/backpack1.jpg"><img class="alignleft size-medium wp-image-1825" style="margin-right: 10px; margin-bottom: 10px;" title="Alagad Backpack" src="http://blog.alagad.com/wp-content/uploads/2010/10/backpack1-227x300.jpg" alt="Alagad Backpack" width="227" height="300" /></a>Pardon the shortness of this post, I simply wanted to remind those out there who follow this blog that I&#8217;m holding a contest to give away a very nice Alagad Swiss Gear laptop backback.  To quote Vicky Rider of <a href="http://codebass.net/" target="_blank">CodeBass</a> fame, they&#8217;re &#8220;legendary&#8221;.  All you need to do is make a first time contribution to an open source project and <a href="/2010/12/10/contest-best-first-time-open-source-contribution/">comment on it on this entry</a>.  The best first time contribution will be picked and that lucky person will get the backpack!  The contest is open through the end of the year and, as of now, I&#8217;ve received precisely zero submissions.</p>
<p>So, go forth and contribute.  Then report back!  It&#8217;s that simple.  You&#8217;ll be helping support the community of OSS developers and you just might get a really, really, nice backpack out of the deal!</p>
<p>Also, to try to drive a little interest in this contest, I&#8217;m holding a side contest for yet another Alagad bag.  Simply tweet the following to enter and I&#8217;ll pick a random tweet the same day that this OSS contest ends.  Here what you tweet:</p>
<blockquote><p>Now I wish I&#8217;d never contributed to open source! #AlagadBag http://bit.ly/eJvDfi</p></blockquote>
<p>Also &#8211; you may want to note that <a href="http://codebass.net" target="_blank">CodeBass</a> is holding a contest to give away some swag to commemorate their <a href="http://mediaslurp.com/" target="_blank">MediaSlurp</a> collaboration.  I&#8217;ve donated an Alagad bag to their swag set.  <a href="http://codebass.net/2010/12/21/codebassradio-shows-mediaslurp-and-swag/" target="_blank">Get more info</a> and learn how to <a href="http://codebass.net/2010/12/21/codebassradio-shows-mediaslurp-and-swag/" target="_blank">enter their contest here.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.alagad.com/2010/12/23/remember-to-contribute-to-oss-or-tweet-to-get-an-alagad-backpack/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Contest: Best First Time Open Source Contribution (Updated)</title>
		<link>http://blog.alagad.com/2010/12/10/contest-best-first-time-open-source-contribution/</link>
		<comments>http://blog.alagad.com/2010/12/10/contest-best-first-time-open-source-contribution/#comments</comments>
		<pubDate>Fri, 10 Dec 2010 15:31:27 +0000</pubDate>
		<dc:creator>Doug Hughes</dc:creator>
				<category><![CDATA[Alagad]]></category>
		<category><![CDATA[Contests]]></category>
		<category><![CDATA[Open Source]]></category>

		<guid isPermaLink="false">http://blog.alagad.com/?p=1852</guid>
		<description><![CDATA[A couple of days ago I asked for suggestions for contests so that I could give away a bunch of extra Swiss Gear Alagad laptop backpacks that are taking up my precious garage space.  I received a number of ...]]></description>
			<content:encoded><![CDATA[<p>A couple of days ago I asked for <a href="/2010/12/08/contest-help-alagad-give-away-swiss-gear-backpacks/">suggestions for contests</a> so that I could give away a bunch of extra Swiss Gear Alagad laptop backpacks that are taking up my precious garage space.  I received a number of good suggestions and, for my first contest, I&#8217;m going to go with Kurt Wiersma&#8217;s suggestion:  <strong>Best First Time Open Source Contribution! </strong> (Congrat&#8217;s Kurt &#8211; Send me your address and I&#8217;ll send you a backpack.)</p>
<p>The contest title is pretty self descriptive.  I want to encourage those of you who haven&#8217;t contributed to an open source project in the past to contribute.  So, go out, choose a project you deem worthy and contribute.  It doesn&#8217;t matter how you contribute. Obviously you could contribute code or bug fixes.  You could also write documentation.  There are probably other things you could do as well.  For example, maybe you could start a fundraising or publicity campaign for your designated project. The choice is yours &#8211; be creative!</p>
<p>As you make your contribution please put a summary into the comments on this blog entry.  Be sure to make a good sales pitch on why your contribution should be the winner.  When the contest ends I&#8217;ll post a survey and the community can choose which contribution is their favorite.  The winner will get a really nice laptop backpack. Everyone else will get the glowing sense of well being and pride in knowing you&#8217;ve done a good deed.</p>
<p>The contest starts now and runs through the end of 2010.</p>
<p><a style="margin-right: 15px; margin-bottom: 10px;" href="http://blog.alagad.com/wp-content/uploads/2010/10/backpack1.jpg"><img class="alignleft size-medium wp-image-1825" title="Alagad Backpack" src="http://blog.alagad.com/wp-content/uploads/2010/10/backpack1-227x300.jpg" alt="Alagad Backpack" width="227" height="300" /></a>I&#8217;ve given away several of these backpacks in the past, but, if you&#8217;ve never seen them in person, trust me, they&#8217;re very nice!  I&#8217;ve been using mine for about two years and it still looks brand new.  It&#8217;s very well constructed from very nice materials.  It&#8217;s well padded and won&#8217;t hurt your shoulders, no matter what you load into it. There are about a bazillion pockets on this beast &#8211; more than enough to securely store and organize just about anything you might want to cary with you.  Heck, it&#8217;s even got ventilation channels to keep your back cool!</p>
<p>So, please, go do a good deed and help out an open source project and report back!</p>
<p><strong>Update: </strong>I&#8217;ve added a side contest to this contest.  <a href="/2010/12/23/remember-to-contribute-to-oss-or-tweet-to-get-an-alagad-backpack/">More information can be found here.</a> In short, all you need to do is tweet the following to enter:</p>
<blockquote><p>Now I wish I’d never contributed to open source! #AlagadBag http://bit.ly/eJvDfi</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://blog.alagad.com/2010/12/10/contest-best-first-time-open-source-contribution/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Contest: Help Alagad Give Away Swiss Gear Backpacks</title>
		<link>http://blog.alagad.com/2010/12/08/contest-help-alagad-give-away-swiss-gear-backpacks/</link>
		<comments>http://blog.alagad.com/2010/12/08/contest-help-alagad-give-away-swiss-gear-backpacks/#comments</comments>
		<pubDate>Wed, 08 Dec 2010 14:17:31 +0000</pubDate>
		<dc:creator>Doug Hughes</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.alagad.com/?p=1833</guid>
		<description><![CDATA[I have a bunch of promotional laptop backpacks I purchased for Alagad taking up precious space in my garage.  These are very nice swiss gear backpacks with the Alagad logo tastefully embroidered on the back pocket.  They&#8217;ve got, I&#8217;d ...]]></description>
			<content:encoded><![CDATA[<p><a style="margin-right: 15px; margin-bottom: 10px;" href="http://blog.alagad.com/wp-content/uploads/2010/10/backpack1.jpg"><img class="alignleft size-medium wp-image-1825" title="Alagad Backpack" src="http://blog.alagad.com/wp-content/uploads/2010/10/backpack1-227x300.jpg" alt="Alagad Backpack" width="227" height="300" /></a>I have a bunch of promotional laptop backpacks I purchased for Alagad taking up precious space in my garage.  These are very nice swiss gear backpacks with the Alagad logo tastefully embroidered on the back pocket.  They&#8217;ve got, I&#8217;d guess, a zillion pockets, lots of storage space, can fit a 17&#8243; laptop, and are tough as heck.  I&#8217;ve been using mine for a couple years and it still looks like new!  I really want to give them away to good homes, but I&#8217;ve been struggling on how to best do this.  Maybe you can help?</p>
<p>A few weeks ago I posted a contest where entrants would make a word search generator in an unfamiliar language.  And, well, honestly, that went over like a lead balloon.  I had precisely zero entrants.  Maybe I made it a bit too complex?</p>
<p>I&#8217;d like to turn this into a game or a contest or something of the sort and have a little fun with it!  Furthermore, a little promotional activity can&#8217;t hurt since it looks like Alagad will be winding up their current contract in April.  (It&#8217;s never too early to be looking for the next gig.)  If possible, it&#8217;d be really nice to be able to help people learn something new or, perhaps, help out those who are less fortunate, especially durring this time of year.  Winners of these contests would get an Alagad backpack.</p>
<p>So, this time I&#8217;m having a contest to come up with ideas for contests, games, or whatever.  If you have an idea on what I should do to give away these backpacks post it in the comments below.  I&#8217;ll pick one or more of the ideas and run with them.  If your idea is picked, you&#8217;ll get a very nice backpack for your troubles!</p>
<p>So, how should I give away these backpacks?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.alagad.com/2010/12/08/contest-help-alagad-give-away-swiss-gear-backpacks/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Make a Word Search Puzzle Generator and Win an Alagad Backpack</title>
		<link>http://blog.alagad.com/2010/10/19/1824/</link>
		<comments>http://blog.alagad.com/2010/10/19/1824/#comments</comments>
		<pubDate>Tue, 19 Oct 2010 12:52:30 +0000</pubDate>
		<dc:creator>Doug Hughes</dc:creator>
				<category><![CDATA[Alagad]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Home]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.alagad.com/?p=1824</guid>
		<description><![CDATA[My family is in the midst of downsizing a bit and moving to a new house. While digging around in our attic I discovered a set of Alagad promotional backpacks. Personally, I love mine. It has about a bazillion ...]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.alagad.com/wp-content/uploads/2010/10/backpack1.jpg"><img class="alignleft size-medium wp-image-1825" style="margin-right: 10px; margin-bottom: 10px;" title="Alagad Backpack" src="http://blog.alagad.com/wp-content/uploads/2010/10/backpack1-227x300.jpg" alt="Alagad Backpack" width="159" height="210" /></a>My family is in the midst of downsizing a bit and moving to a new house.  While digging around in our attic I discovered a set of Alagad promotional backpacks. Personally, I love mine. It has about a bazillion pockets, is very well made, and can easily hold a 17” laptop.  Over the last few years I’ve given a number of these away and everyone who has one raves about them.</p>
<p>I don’t plan to sponsor any conferences any time soon and so I thought I should come up with a way to give these backpacks away.  (I’ve only got so many backs, myself.)  What better way to do this than to have a contest?</p>
<p><a href="http://blog.alagad.com/wp-content/uploads/2010/10/halloween-word-search.jpg"><img class="alignright size-thumbnail wp-image-1826" style="margin-right: 10px; margin-bottom: 10px;" title="Example Word Search" src="http://blog.alagad.com/wp-content/uploads/2010/10/halloween-word-search-150x150.jpg" alt="Example Word Search" width="150" height="150" /></a>My son loves word search puzzles.  He loves them enough that I’ve often considered writing a simple application to generate word search puzzles for him.  In my minds eye I see an application where I can provide various options I can choose from such as:</p>
<ul>
<li><span style="font-size: 13.3333px;">How many letters wide and tall a puzzle should be.<br />
</span></li>
<li><span style="font-size: 13.3333px;">A maximum length for and number of words to choose randomly from a dictionary.</span></li>
<li><span style="font-size: 13.3333px;">An option to provide your own words and title.</span></li>
<li><span style="font-size: 13.3333px;">Directionality settings.  Such as forward, down, down at an angle, backwards, backwards at an angle, up, etc.  These would control how words would be hidden in the puzzle.</span></li>
</ul>
<p>Clicking a button would spit out a word search that I could print out and do with a pen.  <span style="font-size: 13.3333px;">I’m sure you could come up with many of your own ideas for how a simple word search generator might work.</span></p>
<p>Of course there are already a wide number of word search puzzle generators on the web, but as a programmer I was interested in the challenge.  And so, here is my challenge to the community in general: Create a word search generating application.</p>
<p>And here’s the twist: Create the word search genrator in any language (or technology) you don’t already know.  If I were to write this right now I’d probably choose NodeJS since I’m interested in its capabilities and it’d be fun to do something more than just a hello world application in it.</p>
<p>Your application can be as complex or simple as you want.  Complexity doesn’t guarantee a win and neither does simplicity.  What I’m going to be looking for is the uniqueness of the language you choose and how well written the application is from my personal perspective.  For example, I’ll be more interested in a well-written Clojure application than a poorly written one in Ruby or C.  Yes, it’s entirely subjective, but I’m less familiar with Clojure (and bet most of my readers are too) and therefore would be more interested in seeing what can be learned.</p>
<p>Submissions are due a week from now.  I’ll start reviewing them on Tuesday the 26th.  Depending on how loudly people complain I may push this deadline back.</p>
<p>Once I’ve had a chance to review the entries I’ll pick three winners, each of whom will get one Alagad backpack.  I’ll then write a blog entry (or three) about the entries, the languages used, and the approaches taken in building the applications.  Assuming it’s practical, I’ll also host the applications so the whole world can play around with them.  Furthermore, I’ll publish a SVN or GIT repository where people can download the source code.</p>
<p>Every time I do one of these contests I forget something important.  So, if you have any questions or concerns please add them in the comments.  I’ll reply and clarify.</p>
<p>Good luck!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.alagad.com/2010/10/19/1824/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google Chrome Extensions are Crazy Easy</title>
		<link>http://blog.alagad.com/2010/08/11/google-chrome-extensions-are-crazy-easy/</link>
		<comments>http://blog.alagad.com/2010/08/11/google-chrome-extensions-are-crazy-easy/#comments</comments>
		<pubDate>Wed, 11 Aug 2010 16:39:42 +0000</pubDate>
		<dc:creator>Doug Hughes</dc:creator>
				<category><![CDATA[Browsers]]></category>
		<category><![CDATA[Extensions]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.alagad.com/?p=1796</guid>
		<description><![CDATA[Occasionally I have to work on web applications that are horribly slow.  Some complex applications can take several minutes to completely reload. I’m sure I’m not alone in this experience.  And so, when working on these sites, what do ...]]></description>
			<content:encoded><![CDATA[<p>Occasionally I have to work on web applications that are horribly slow.  Some complex applications can take several minutes to completely reload.  I’m sure I’m not alone in this experience.  And so, when working on these sites, what do you do while waiting for stuff to load?  If you&#8217;re like me, you go to another tab and work on something else while you wait for that tab to load (or you troll around Twitter, etc).</p>
<p>This isn’t really a problem except that more often than not I fail to notice when the other tab has finished loaded and end up wasting time.  Because of this, I’ve long wished that there were a tab extension that would could play a sound when a tab finishes loading.  However, look as I may, I never found anything that did what I wanted.</p>
<p>In the past I’ve considered writing a simple extension for this.  The thing is, until recently I’ve been a fairly diehard Firefox user.  Having written a now-defunct Firefox extension, I know what a flaming pain in the ass it is to write Firefox extensions.  There was no way I was going to write this extension for Firefox.</p>
<p>However, I recently decided to take Google Chrome for a real test drive and I’ve been using it exclusively for a few weeks.  During this period I also began working on a website that takes a very long time to reload.  So long, in fact, that I became frustrated enough to go and research what’s involved in making extensions for Chrome.  And, as it turns out, there’s not a whole lot involved!</p>
<p>In Firefox, when you write an extension you can change or override just about any feature of the browser.  For example, if you don’t like how bookmarks system works, you can pretty much replace it with something you do like.  The thing is, with all that power and flexibility comes a boatload of complexity.  I really don’t even have the patience to write about the hoops I had to jump through to get started.  Let it suffice to say that I had to run the browser in a different test user account and, if I recall correctly, reload the browser each time I made a chance to my extension.  Then there’s the fact that Firefox extensions are written using XUL (XML User Interface Language).  And there was more fun too.  In summary: It’s a pain and no fun at all.</p>
<p>Chrome, by contrast, is much more limiting in what you can do.  However, it’s API is a dream to work with.  In Chrome most extensions are either browser actions, which are browser-wide, or page actions, which only affect the current page.   Both of these are quite easy to write, but I’ll focus on browser actions since that’s what I wrote.</p>
<p>In addition to the two basic extension points, Chrome also provides a nice API for interacting with browser features such as bookmarks and tabs.  Like everything else in Chrome, these APIs are very simple and easy to use.</p>
<p>At a minimum, Chrome extensions are made up of HTML files and a manifest file written in JSON.  The manifest defines basic information like the name, version, description, icons, etc.</p>
<p>It also defines a “background page”.  A background page is a page that is loaded by the extension and runs constantly behind the scenes.  This is useful for storing state information and providing the core features of the plugin.</p>
<p>The manifest also allows you to define browser actions.  Browser actions define an image or button that appears to the right of the address bar and provides an entry point into your extension.  When you click on that icon a popup you create appears.</p>
<p>Here was the manifest for my plugin:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#123;</span>
  <span style="color: #3366CC;">&quot;name&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Tab Bing!&quot;</span><span style="color: #339933;">,</span>
  <span style="color: #3366CC;">&quot;version&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;1.1&quot;</span><span style="color: #339933;">,</span>
  <span style="color: #3366CC;">&quot;description&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;This extension produces a 'bing' when a tab finishes loading.&quot;</span><span style="color: #339933;">,</span>
  <span style="color: #3366CC;">&quot;icons&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span> <span style="color: #3366CC;">&quot;128&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;bell_128.png&quot;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
  <span style="color: #3366CC;">&quot;background_page&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;background.html&quot;</span><span style="color: #339933;">,</span>
  <span style="color: #3366CC;">&quot;browser_action&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #3366CC;">&quot;default_title&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">,</span>
    <span style="color: #3366CC;">&quot;default_icon&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;bell_19.png&quot;</span><span style="color: #339933;">,</span>
    <span style="color: #3366CC;">&quot;default_popup&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;popup.html&quot;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
  <span style="color: #3366CC;">&quot;permissions&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>
    <span style="color: #3366CC;">&quot;tabs&quot;</span>
  <span style="color: #009900;">&#93;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The manifest file above defines the name, etc, of my extension.  It also says that the background page, background.html, will be loaded and run behind the scenes at all times.  Additionally, there will be a button to the right of the nav menu.  Clicking this button will show the popup, popup.html.</p>
<p>At this point all I need to do is create the files referenced and load the extension into Chrome.  Just for an example, here is the directory structure of my extension:</p>
<p><a href="http://blog.alagad.com/wp-content/uploads/2010/08/files.jpg"><img class="size-full wp-image-1802 alignnone" style="padding-right: 10px; padding-bottom: 10px;" title="files" src="http://blog.alagad.com/wp-content/uploads/2010/08/files.jpg" alt="Files in Tab Bing!" width="200" height="284" /></a></p>
<p>You can ignore the mp3 files and play.png file as they’re my extension&#8217;s assets.  Really, what I have is three very simple: manifest.json, background.html, and popup.html.</p>
<p>If I wanted to load my extension into my browser how I can do so by putting the extension tab into developer mode.  I do this by opening the extensions tab and clicking on the Developer mode link.</p>
<p><a href="http://blog.alagad.com/wp-content/uploads/2010/08/devmode.jpg"><img class="alignnone size-full wp-image-1803" title="devmode" src="http://blog.alagad.com/wp-content/uploads/2010/08/devmode.jpg" alt="Developer Mode" width="650" height="438" /></a></p>
<p>After that I can click on Load Unpacked Extension and simply choose the directory my extension is in.   At this point I can see my button appear next to the tool bar.  Clicking the button shows a popup window containing the contents of my popup.html file.  It really doesn’t get much simpler than this!</p>
<p>Now that I have the basics of my Chrome extension in place I can start writing my extension’s features.</p>
<p>The way my extension works is to allow the user to indicate if they want the current tab to “bing” when done loading.  To support this I’ve created a simple popup that collects a few options from the user.  These options are stored by the background.html file that is persistent for the duration of the browser’s lifespan.</p>
<p>So, here’s my popup.html:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>html<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>head<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>style<span style="color: #339933;">&gt;</span>
body<span style="color: #009900;">&#123;</span>
	width<span style="color: #339933;">:</span> 300px<span style="color: #339933;">;</span>
	font<span style="color: #339933;">-</span>family<span style="color: #339933;">:</span> verdana<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;/</span>style<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>script<span style="color: #339933;">&gt;</span>
	<span style="color: #003366; font-weight: bold;">var</span> background <span style="color: #339933;">=</span> chrome.<span style="color: #660066;">extension</span>.<span style="color: #660066;">getBackgroundPage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> tab <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> tabSettings <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> previewedSound <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	<span style="color: #006600; font-style: italic;">// get the current tab</span>
	chrome.<span style="color: #660066;">tabs</span>.<span style="color: #660066;">getSelected</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>_tab<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		tab <span style="color: #339933;">=</span> _tab<span style="color: #339933;">;</span>
&nbsp;
		insureElementExists<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		tabSettings <span style="color: #339933;">=</span> background.<span style="color: #660066;">bingTabs</span><span style="color: #009900;">&#91;</span>tab.<span style="color: #660066;">id</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #006600; font-style: italic;">// check the bing box</span>
		document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;bing&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">checked</span> <span style="color: #339933;">=</span> tabSettings.<span style="color: #660066;">bing</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #006600; font-style: italic;">// select the sound</span>
		<span style="color: #003366; font-weight: bold;">var</span> sound <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;sound&quot;</span><span style="color: #009900;">&#41;</span><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: #339933;">=</span> <span style="color: #CC0000;">0</span> <span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> sound.<span style="color: #660066;">options</span>.<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: #003366; font-weight: bold;">var</span> option <span style="color: #339933;">=</span> sound.<span style="color: #660066;">options</span><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;">if</span><span style="color: #009900;">&#40;</span>option.<span style="color: #660066;">value</span> <span style="color: #339933;">==</span> tabSettings.<span style="color: #660066;">sound</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				sound.<span style="color: #660066;">selectedIndex</span> <span style="color: #339933;">=</span> i<span style="color: #339933;">;</span>
				<span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #006600; font-style: italic;">// check the repeat box</span>
		document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;repeat&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">checked</span> <span style="color: #339933;">=</span> tabSettings.<span style="color: #660066;">repeat</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">function</span> toggleBing<span style="color: #009900;">&#40;</span>bing<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		background.<span style="color: #660066;">bingTabs</span><span style="color: #009900;">&#91;</span>tab.<span style="color: #660066;">id</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">bing</span> <span style="color: #339933;">=</span> bing<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">function</span> selectSound<span style="color: #009900;">&#40;</span>sound<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		background.<span style="color: #660066;">bingTabs</span><span style="color: #009900;">&#91;</span>tab.<span style="color: #660066;">id</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">sound</span> <span style="color: #339933;">=</span> sound<span style="color: #339933;">;</span>
		preview<span style="color: #009900;">&#40;</span>sound<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">function</span> toggleRepeat<span style="color: #009900;">&#40;</span>repeat<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		background.<span style="color: #660066;">bingTabs</span><span style="color: #009900;">&#91;</span>tab.<span style="color: #660066;">id</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">repeat</span> <span style="color: #339933;">=</span> repeat<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">function</span> insureElementExists<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>background.<span style="color: #660066;">bingTabs</span><span style="color: #009900;">&#91;</span>tab.<span style="color: #660066;">id</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> undefined<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			background.<span style="color: #660066;">bingTabs</span><span style="color: #009900;">&#91;</span>tab.<span style="color: #660066;">id</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
				bing<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">,</span>
				sound<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Bing&quot;</span><span style="color: #339933;">,</span>
				repeat<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">,</span>
				playing<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">null</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">function</span> preview<span style="color: #009900;">&#40;</span>sound<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>previewedSound <span style="color: #339933;">!=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			background.<span style="color: #000066;">stop</span><span style="color: #009900;">&#40;</span>previewedSound<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		previewedSound <span style="color: #339933;">=</span> background.<span style="color: #660066;">play</span><span style="color: #009900;">&#40;</span>sound<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>head<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>p<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;checkbox&quot;</span> id<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;bing&quot;</span> onChange<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;toggleBing(this.checked)&quot;</span> <span style="color: #339933;">/&gt;</span> <span style="color: #339933;">&lt;</span>label <span style="color: #000066; font-weight: bold;">for</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;bing&quot;</span><span style="color: #339933;">&gt;</span>Make <span style="color: #000066; font-weight: bold;">this</span> tab bing when loaded.<span style="color: #339933;">&lt;/</span>label<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>p<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>p<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>label <span style="color: #000066; font-weight: bold;">for</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;sound&quot;</span><span style="color: #339933;">&gt;</span>Choose a sound<span style="color: #339933;">:&lt;/</span>label<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>select id<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;sound&quot;</span> onChange<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;selectSound(this[this.selectedIndex].value)&quot;</span><span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;</span>option value<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;Alarm&quot;</span><span style="color: #339933;">&gt;</span>Alarm<span style="color: #339933;">&lt;/</span>option<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;</span>option value<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;Bing&quot;</span><span style="color: #339933;">&gt;</span>Bing<span style="color: #339933;">&lt;/</span>option<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;</span>option value<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;Bleep&quot;</span><span style="color: #339933;">&gt;</span>Bleep<span style="color: #339933;">&lt;/</span>option<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;</span>option value<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;DoorBuzzer&quot;</span><span style="color: #339933;">&gt;</span>Door Buzzer<span style="color: #339933;">&lt;/</span>option<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;</span>option value<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;Rooster&quot;</span><span style="color: #339933;">&gt;</span>Rooster<span style="color: #339933;">&lt;/</span>option<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;</span>option value<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;Siren&quot;</span><span style="color: #339933;">&gt;</span>Siren<span style="color: #339933;">&lt;/</span>option<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;</span>option value<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;SmokeAlarm&quot;</span><span style="color: #339933;">&gt;</span>Smoke Alarm<span style="color: #339933;">&lt;/</span>option<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;</span>option value<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;Whoop&quot;</span><span style="color: #339933;">&gt;</span>Whoop<span style="color: #339933;">&lt;/</span>option<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;/</span>select<span style="color: #339933;">&gt;</span>
&nbsp;
	<span style="color: #339933;">&lt;</span>img src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;play.png&quot;</span> valign<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;middle&quot;</span> onClick<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;preview(document.getElementById('sound')[document.getElementById('sound').selectedIndex].value)&quot;</span> <span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;/</span>p<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>p<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;checkbox&quot;</span> id<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;repeat&quot;</span> onChange<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;toggleRepeat(this.checked)&quot;</span> <span style="color: #339933;">/&gt;</span> <span style="color: #339933;">&lt;</span>label <span style="color: #000066; font-weight: bold;">for</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;bing&quot;</span><span style="color: #339933;">&gt;</span>Repeat until the tab <span style="color: #000066; font-weight: bold;">is</span> selected.<span style="color: #339933;">&lt;/</span>label<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>p<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">&gt;</span></pre></div></div>

<p>The first thing you may note is that this looks pretty much like any HTML file.  That’s because it is!  Take a look at the body and note that I’m using HTML form elements to define my popup. Heck, I even use CSS to format the popup!</p>
<p>Here’s what it looks like in the browser:</p>
<p><a href="http://blog.alagad.com/wp-content/uploads/2010/08/example.jpg"><img class="alignnone size-full wp-image-1815" title="example" src="http://blog.alagad.com/wp-content/uploads/2010/08/example.jpg" alt="The Extension's Popup" width="712" height="504" /></a></p>
<p>Looking at the JavaScript in the popup you’ll see that I have this line of code first:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> background <span style="color: #339933;">=</span> chrome.<span style="color: #660066;">extension</span>.<span style="color: #660066;">getBackgroundPage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This returns a reference to the background.html page.  Once I have this reference I can call functions on it.  Before I show that though, let me show you the code for the background.html:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>html<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>script<span style="color: #339933;">&gt;</span>
	chrome.<span style="color: #660066;">tabs</span>.<span style="color: #660066;">onUpdated</span>.<span style="color: #660066;">addListener</span><span style="color: #009900;">&#40;</span>
		<span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>tabId<span style="color: #339933;">,</span> changeInfo<span style="color: #339933;">,</span> tab<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>changeInfo.<span style="color: #000066;">status</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">&quot;complete&quot;</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>bingTabs<span style="color: #009900;">&#91;</span>tabId<span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> undefined <span style="color: #339933;">&amp;&amp;</span> bingTabs<span style="color: #009900;">&#91;</span>tabId<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">bing</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>currentTab <span style="color: #339933;">!=</span> tabId <span style="color: #339933;">&amp;&amp;</span> bingTabs<span style="color: #009900;">&#91;</span>tabId<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">repeat</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
						bingTabs<span style="color: #009900;">&#91;</span>tabId<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">playing</span> <span style="color: #339933;">=</span> play<span style="color: #009900;">&#40;</span>bingTabs<span style="color: #009900;">&#91;</span>tabId<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">sound</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">true</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;">else</span> <span style="color: #009900;">&#123;</span>
						bingTabs<span style="color: #009900;">&#91;</span>tabId<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">playing</span> <span style="color: #339933;">=</span> play<span style="color: #009900;">&#40;</span>bingTabs<span style="color: #009900;">&#91;</span>tabId<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">sound</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #009900;">&#125;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	chrome.<span style="color: #660066;">tabs</span>.<span style="color: #660066;">getSelected</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>tab<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		currentTab <span style="color: #339933;">=</span> tab.<span style="color: #660066;">id</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	chrome.<span style="color: #660066;">tabs</span>.<span style="color: #660066;">onSelectionChanged</span>.<span style="color: #660066;">addListener</span><span style="color: #009900;">&#40;</span>
		<span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>tabId<span style="color: #339933;">,</span> selectInfo<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			currentTab <span style="color: #339933;">=</span> tabId<span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #000066;">stop</span><span style="color: #009900;">&#40;</span>bingTabs<span style="color: #009900;">&#91;</span>tabId<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">playing</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>
&nbsp;
&nbsp;
	<span style="color: #003366; font-weight: bold;">var</span> bingTabs <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">function</span> bing<span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		sound <span style="color: #339933;">=</span> bingTabs<span style="color: #009900;">&#91;</span>id<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">sound</span><span style="color: #339933;">;</span>
		play<span style="color: #009900;">&#40;</span>sound<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">function</span> play<span style="color: #009900;">&#40;</span>sound<span style="color: #339933;">,</span> repeat<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #003366; font-weight: bold;">var</span> audio <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Audio<span style="color: #009900;">&#40;</span>sound <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;.mp3&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>repeat<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			audio.<span style="color: #660066;">loop</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		audio.<span style="color: #660066;">play</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">return</span> audio<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">function</span> <span style="color: #000066;">stop</span><span style="color: #009900;">&#40;</span>sound<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		sound.<span style="color: #660066;">pause</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">&gt;</span></pre></div></div>

<p>Not a very long script is it?  It’s entirely JavaScript too!</p>
<p>What this does, is make use of the Chrome extension API to listen for tab updated events.  When they occur it looks to see if that specific tab is set to bing.  If so, it bings by using the HTML 5 audio API to play an MP3 file.</p>
<p>Going back to the popup.html, when you check the checkbox to make the tab bing, the checkbox’s onChange event calls the toggleBing() function.  This toggleBing() function simply calls the background page and tells it to make that tab bing when done loading.</p>
<p>What I really think is cool about Chrome extensions are how quickly I got up to speed. It literally only took about half an hour and I was off to the races.  The <a href="http://code.google.com/chrome/extensions/" target="_blank">Chrome extensions documentation</a> is terrific to!  And once I had a working version I was able to quickly and easily make changes to add additional features.  You do have to click reload in the extensions tab, but that beats the pants off reloading the entire browser with each change.</p>
<p>Additionally, with Firefox, it was really very difficult to publish the extension to <a href="http://addons.mozilla.com" target="_blank">addons.mozilla.com</a>.  For Chrome it was as simple as uploading my extension’s folder to <a href="https://chrome.google.com/extensions/?hl=en" target="_blank">Google’s Chrome extensions website</a>.</p>
<p>The biggest gripe I have, though, is that Chrome&#8217;s simplicity is also a little limiting.  I can’t completely change any feature within the browser.  But, in all honesty, I think it’s a good tradeoff for a much nicer user experience.</p>
<p>If you&#8217;re interested you can <a href="https://chrome.google.com/extensions/detail/abnhnhddmbpkckplkkalnjjheboojbml?hl=en" target="_blank">download my Tab Bing! Chrome extension here</a>.</p>
<p>I figure that next I’ll make my Tab Bing! extension make the tab’s icon blink when a tab is loaded!  What extensions would you create if you had the time and know-how?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.alagad.com/2010/08/11/google-chrome-extensions-are-crazy-easy/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>A Handy Way To Convert US Time Zones</title>
		<link>http://blog.alagad.com/2010/08/10/a-handy-way-to-convert-us-time-zones/</link>
		<comments>http://blog.alagad.com/2010/08/10/a-handy-way-to-convert-us-time-zones/#comments</comments>
		<pubDate>Tue, 10 Aug 2010 21:09:27 +0000</pubDate>
		<dc:creator>Doug Hughes</dc:creator>
				<category><![CDATA[Home]]></category>
		<category><![CDATA[Off Topic]]></category>

		<guid isPermaLink="false">http://blog.alagad.com/?p=1791</guid>
		<description><![CDATA[Today’s blog entry is a bit off my typical subjects on this blog.  But, as someone who works from home for clients across the US, I often have to figure out what, for example, 9am Eastern Time is in ...]]></description>
			<content:encoded><![CDATA[<p><span style="font-size: 13.3333px;">Today’s blog entry is a bit off my typical subjects on this blog.  But, as someone who works from home for clients across the US, I often have to figure out what, for example, 9am Eastern Time is in Pacific Time.</span></p>
<p><span style="font-size: 13.3333px;">As the title suggests, I have a – ahem – <em>handy</em> way to figure this out.  What I do is use my knuckles.  Specifically, there are four knuckles on each of your hand (excluding your thumb).  There are also four time zones in the US.   So, if you need to convert from one time zone or another, you simply choose the knuckle corresponding to the time zone and count up to the right and down to the left.  Here’s an image that helps demonstrate the concept:</span></p>
<p><span style="font-size: 13.3333px;"><a href="http://blog.alagad.com/wp-content/uploads/2010/08/hand.jpg"><img title="hand" src="http://blog.alagad.com/wp-content/uploads/2010/08/hand.jpg" alt="" width="474" height="404" /></a></span></p>
<p><span style="font-size: 13.3333px;">The idea is that if someone asks you to attend a meeting at 3pm Pacific Time and you’re in Central Time, you simply start at the Pacific knuckle and count up to Central.  Thus, 3pm Pacific is 5pm Central.  And, vice versa.  If someone in Eastern Time suggests a 3pm meeting and you’re in Mountain Time, you start with the right-most knuckle and count down to find out that 3pm Eastern is 1pm Mountain.</span></p>
<p><span style="font-size: 13.3333px;">For those of you who are naturals at figuring out time zone differences this may be a little less than useful.  For everyone else, I hope you enjoy!</span></p>
<p><span style="font-size: 13.3333px;">And, while I’m on it, this idea came to me from a similar trick I use to figure out the number of days in each month.</span></p>
<p><span style="font-size: 13.3333px;">What you do is start from your left-most knuckle and count months to the right.  In this case you count both the knuckles and the space between the knuckles.  So the left most knuckle is January, the first space is February, the second knuckle is March, etc.  (The last space and knuckle on your right hand isn’t used.)  Here’s an illustration:</span></p>
<p><a href="http://blog.alagad.com/wp-content/uploads/2010/08/hand.jpg"></a><a href="http://blog.alagad.com/wp-content/uploads/2010/08/hands.jpg"><img class="size-full wp-image-1793 alignnone" title="hands" src="http://blog.alagad.com/wp-content/uploads/2010/08/hands.jpg" alt="" width="600" height="306" /></a></p>
<p><span style="font-size: 13.3333px;">Any knuckle-month has 31 days and any space-month has 30 days.  The only exception is February, which usually has 28 unless you’re in a leap year and it has 29.</span></p>
<p><span style="font-size: 13.3333px;">What do you think?  Do you use any hand-based mnemonics?</span></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.alagad.com/2010/08/10/a-handy-way-to-convert-us-time-zones/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
