<?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>true false maybe</title>
	<atom:link href="http://truefalsemaybe.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://truefalsemaybe.com</link>
	<description>tom longson's blog on software, design, and user experience</description>
	<lastBuildDate>Mon, 21 Jun 2010 21:57:36 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>JavaScript Book Recommendations</title>
		<link>http://truefalsemaybe.com/2010/06/javascript-book-recommendations/</link>
		<comments>http://truefalsemaybe.com/2010/06/javascript-book-recommendations/#comments</comments>
		<pubDate>Tue, 08 Jun 2010 22:00:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://truefalsemaybe.com/?p=150</guid>
		<description><![CDATA[I've been expanding my library recently, and I wanted to share a list of some advanced JavaScript books I've picked up:

JavaScript: The Good Parts by Papa Crock
High Performance Web Sites by Steve Souders
Even Faster Web Sites by Steve Souders
High Performance JavaScript by Nicholas C. Zakas
Professional JavaScript for Web Developers by Nicholas C. Zakas
Pro Javascript Techniques [...]]]></description>
			<content:encoded><![CDATA[<p>I've been expanding my library recently, and I wanted to share a list of some advanced JavaScript books I've picked up:</p>
<ul>
<li><a href="http://www.amazon.com/JavaScript-Good-Parts-Douglas-Crockford/dp/0596517742/ref=sr_1_1?ie=UTF8&amp;s=books&amp;qid=1276033931&amp;sr=1-1">JavaScript: The Good Parts</a> by Papa Crock</li>
<li><a href="http://www.amazon.com/High-Performance-Web-Sites-Essential/dp/0596529309">High Performance Web Sites</a> by Steve Souders</li>
<li><a href="http://www.amazon.com/Even-Faster-Web-Sites-Performance/dp/0596522304/ref=sr_1_1?ie=UTF8&amp;s=books&amp;qid=1276033969&amp;sr=1-1">Even Faster Web Sites</a> by Steve Souders</li>
<li><a href="http://www.amazon.com/Performance-JavaScript-Faster-Application-Interfaces/dp/059680279X/ref=sr_1_1?ie=UTF8&amp;s=books&amp;qid=1276034070&amp;sr=1-1">High Performance JavaScript</a> by Nicholas C. Zakas</li>
<li><a href="http://www.amazon.com/Professional-JavaScript-Developers-Wrox-Programmer/dp/047022780X/">Professional JavaScript for Web Developers</a> by Nicholas C. Zakas</li>
<li><a href="http://www.amazon.com/Pro-JavaScript-Techniques-John-Resig/dp/1590597273/ref=sr_1_1?ie=UTF8&amp;s=books&amp;qid=1276034136&amp;sr=1-1-spell">Pro Javascript Techniques</a> by John Resig</li>
<li><a href="http://www.manning.com/resig/">Secrets of the JavaScript Ninja</a> by John Resig</li>
</ul>
<p>If you're totally new, these probably aren't the best books to dive into, but I still recommend picking up JavaScript: The Good Parts. It's amazing reading, really gave me a much better understanding of the language, and incredibly dense.</p>
]]></content:encoded>
			<wfw:commentRss>http://truefalsemaybe.com/2010/06/javascript-book-recommendations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PubSub in jQuery with Custom Events</title>
		<link>http://truefalsemaybe.com/2010/04/pubsub-in-jquery-with-custom-events/</link>
		<comments>http://truefalsemaybe.com/2010/04/pubsub-in-jquery-with-custom-events/#comments</comments>
		<pubDate>Fri, 23 Apr 2010 21:08:52 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://truefalsemaybe.com/?p=135</guid>
		<description><![CDATA[Demo: PubSub in jQuery
Recently I did a post on Data Binding in JavaScript using the YUI3 Library as my base. h3 and MikeInVB wanted to see it in jQuery, so I rewrote it and it turns out is a great example of PubSub (publish / subscribe) for jQuery. 
For this example, we're using an object [...]]]></description>
			<content:encoded><![CDATA[<p>Demo: <a href="http://jsbin.com/pubsub-jquery/">PubSub in jQuery</a></p>
<p>Recently I did a post on Data Binding in JavaScript using the YUI3 Library as my base. h3 and MikeInVB wanted to see it in jQuery, so I rewrote it and it turns out is a great example of PubSub (publish / subscribe) for jQuery. </p>
<p>For this example, we're using an object named DB, which is short for DataBind. Basically it's an object with getters and setters.</p>
<pre class="javascript">&nbsp;
  <span style="color: #003366; font-weight: bold;">var</span> DB = <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>data<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
      <span style="color: #000066; font-weight: bold;">this</span>._d = <span style="color: #003366; font-weight: bold;">null</span>;
&nbsp;
      <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">set</span> = <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>data<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
           <span style="color: #000066; font-weight: bold;">this</span>._d = data;
      <span style="color: #66cc66;">&#125;</span>;
&nbsp;
      <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">get</span> = <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
          <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>._d;
      <span style="color: #66cc66;">&#125;</span>;
&nbsp;
      <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">set</span><span style="color: #66cc66;">&#40;</span>data<span style="color: #66cc66;">&#41;</span>;
  <span style="color: #66cc66;">&#125;</span>;
&nbsp;</pre>
<p>Really, this is just an abstracted way to store data. To create an instance of it, set it and get the value back, we would do something like:</p>
<pre class="javascript">&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> myData = <span style="color: #003366; font-weight: bold;">new</span> DB<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
myData.<span style="color: #006600;">set</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;We can't fight in here, this is a war room!&quot;</span><span style="color: #66cc66;">&#41;</span>;
console.<span style="color: #006600;">log</span><span style="color: #66cc66;">&#40;</span>myData.<span style="color: #006600;">get</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #66cc66;">&#41;</span> <span style="color: #009900; font-style: italic;">// &quot;We can't fight in here, this is a war room!&quot;</span>
&nbsp;</pre>
<p>But lets say, we want to subscribe to this data object, and be notified whenever it changes. Instead of polling it and checking to see if the value is the same as last time, we can use jQuery's custom events to trigger a custom event.</p>
<pre class="javascript">&nbsp;
  <span style="color: #003366; font-weight: bold;">var</span> DB = <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>data<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
      <span style="color: #000066; font-weight: bold;">this</span>._d = <span style="color: #003366; font-weight: bold;">null</span>;
&nbsp;
      <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">set</span> = <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>data<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
           <span style="color: #000066; font-weight: bold;">this</span>._d = data;
           <span style="color: #009900; font-style: italic;">// notify all subscribers when this function is used</span>
           $<span style="color: #66cc66;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">trigger</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;change&quot;</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #66cc66;">&#125;</span>;
&nbsp;
      <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">get</span> = <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
          <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>._d;
      <span style="color: #66cc66;">&#125;</span>;
&nbsp;
      <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">set</span><span style="color: #66cc66;">&#40;</span>data<span style="color: #66cc66;">&#41;</span>;
  <span style="color: #66cc66;">&#125;</span>;
&nbsp;</pre>
<p>Now, we can subscribe to it like this:</p>
<pre class="javascript">&nbsp;
$<span style="color: #66cc66;">&#40;</span>myData<span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">bind</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;change&quot;</span>, <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
     <span style="color: #000066;">alert</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;The data was changed!&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>Additionally, we can access that data in our handler: </p>
<pre class="javascript">&nbsp;
$<span style="color: #66cc66;">&#40;</span>myData<span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">bind</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;change&quot;</span>, <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
     <span style="color: #000066;">alert</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;My data was set to &quot;</span> + myData.<span style="color: #006600;">get</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>You can set up any number of subscribers to myData this way now, and they'll be triggered when that instance is set(). </p>
<p>If you want to further improve DB, you can add a function to make it easier to attach change events, jQuery style:</p>
<pre class="javascript">&nbsp;
  <span style="color: #003366; font-weight: bold;">var</span> DB = <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>data<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
      <span style="color: #000066; font-weight: bold;">this</span>._d = <span style="color: #003366; font-weight: bold;">null</span>;
&nbsp;
      <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">set</span> = <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>data<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
           <span style="color: #000066; font-weight: bold;">this</span>._d = data;
           <span style="color: #009900; font-style: italic;">// notify all subscribers when this function is used</span>
           $<span style="color: #66cc66;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">trigger</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;change&quot;</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #66cc66;">&#125;</span>;
&nbsp;
      <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">get</span> = <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
          <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>._d;
      <span style="color: #66cc66;">&#125;</span>;
&nbsp;
      <span style="color: #009900; font-style: italic;">// shortcut for functions trying to bind to the change custom event</span>
      <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">change</span> = <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>fn<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
          $<span style="color: #66cc66;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">bind</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;change&quot;</span>, fn<span style="color: #66cc66;">&#41;</span>;
      <span style="color: #66cc66;">&#125;</span>;
&nbsp;
      <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">set</span><span style="color: #66cc66;">&#40;</span>data<span style="color: #66cc66;">&#41;</span>;
  <span style="color: #66cc66;">&#125;</span>;
&nbsp;</pre>
<p>With our new shortcut, we can subscribe to it like this:</p>
<pre class="javascript">&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> alexSez = <span style="color: #003366; font-weight: bold;">new</span> DB<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
alexSez.<span style="color: #006600;">set</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;Initiative comes to thems that wait.&quot;</span><span style="color: #66cc66;">&#41;</span>;
alexSez.<span style="color: #006600;">change</span><span style="color: #66cc66;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    <span style="color: #000066;">alert</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;Alex says: '&quot;</span> + myData.<span style="color: #006600;">get</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> + <span style="color: #3366CC;">&quot;'&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
alexSex.<span style="color: #006600;">set</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;Welly, welly, welly, welly, welly, welly, well. To what do I owe the extreme pleasure of this surprising visit?&quot;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #009900; font-style: italic;">// an alert will come up that says &quot;Alex says: 'Welly, welly, welly, welly, welly, welly, well. To what do I owe the extreme pleasure of this surprising visit?'&quot;.</span>
&nbsp;</pre>
<p>In the same way, you can set up two input boxes to "share" the same value by subscribing to a shared instance of DB like this:</p>
<pre>&nbsp;
&lt;input type=&quot;text&quot; id=&quot;in1&quot;/&gt;
&lt;br/&gt;
&lt;input type=&quot;text&quot; id=&quot;in2&quot;/&gt;
&nbsp;</pre>
<pre class="javascript">&nbsp;
  <span style="color: #003366; font-weight: bold;">var</span> myData = <span style="color: #003366; font-weight: bold;">new</span> DB<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
  <span style="color: #003366; font-weight: bold;">var</span> inputs = $<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;#in1, #in2&quot;</span><span style="color: #66cc66;">&#41;</span>;
  myData.<span style="color: #006600;">change</span><span style="color: #66cc66;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
      inputs.<span style="color: #006600;">val</span><span style="color: #66cc66;">&#40;</span>myData.<span style="color: #006600;">get</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
  inputs.<span style="color: #006600;">bind</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;keyup&quot;</span>, <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>ev<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
      myData.<span style="color: #006600;">set</span><span style="color: #66cc66;">&#40;</span>$<span style="color: #66cc66;">&#40;</span>ev.<span style="color: #006600;">target</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">val</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>Ta da! </p>
<p>If you're still interested in PubSub for jQuery, I recommend checking out <a href="http://jamiethompson.co.uk/web/2008/06/17/publish-subscribe-with-jquery/">Jamie Thompson's</a> example using the $(document) namespace instead of specific object instances, or <a href="http://higginsforpresident.net/js/static/jq.pubsub.js">Peter Higgin's jQuery.pubsub</a>, which <a href="http://weblog.bocoup.com/publishsubscribe-with-jquery-custom-events">reportedly</a> is significantly faster, although doesn't allow object specific subscribing.</p>
<p>Demo: <a href="http://jsbin.com/pubsub-jquery/">PubSub in jQuery</a></p>
<p>What do you think? Would you do this differently? Leave a comment, I read them all!</p>
]]></content:encoded>
			<wfw:commentRss>http://truefalsemaybe.com/2010/04/pubsub-in-jquery-with-custom-events/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Data Binding in JavaScript</title>
		<link>http://truefalsemaybe.com/2010/04/data-binding-in-javascript/</link>
		<comments>http://truefalsemaybe.com/2010/04/data-binding-in-javascript/#comments</comments>
		<pubDate>Fri, 16 Apr 2010 00:32:13 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://truefalsemaybe.com/?p=128</guid>
		<description><![CDATA[See the demo here: Data Binding in JavaScript
Back when I was in Flex land one of the things that I found to be really neat was data binding... you could essentially have widgets that would update if the data updated automagically. I also wanted to take a stab at doing publishing and subscribing in YUI3, [...]]]></description>
			<content:encoded><![CDATA[<p>See the demo here: <a href="http://jsbin.com/utaku/6/">Data Binding in JavaScript</a></p>
<p>Back when I was in Flex land one of the things that I found to be really neat was data binding... you could essentially have widgets that would update if the data updated automagically. I also wanted to take a stab at doing publishing and subscribing in YUI3, so built this an object called DB, which stores data. It can do three things, it can set() data, it can get() data, and it's an EventTarget, so you can subscribe to it's change event:</p>
<pre class="javascript">&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> DB = <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>data<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">this</span>._d = <span style="color: #003366; font-weight: bold;">null</span>;
&nbsp;
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">publish</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;change&quot;</span>,<span style="color: #66cc66;">&#123;</span>emitFacade: <span style="color: #003366; font-weight: bold;">true</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
     <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">set</span> = <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>data<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
         <span style="color: #000066; font-weight: bold;">this</span>._d = data;
         <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">fire</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;change&quot;</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #66cc66;">&#125;</span>;
&nbsp;
      <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">get</span> = <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
          <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>._d;
      <span style="color: #66cc66;">&#125;</span>;
&nbsp;
      <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">set</span><span style="color: #66cc66;">&#40;</span>data<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>;
 Y.<span style="color: #006600;">augment</span><span style="color: #66cc66;">&#40;</span>DB, Y.<span style="color: #006600;">EventTarget</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>And to instantiate an instance of DB you just do <code>var myData = new DB();</code>, and then you can subscribe to it any number of times to be notified when the data has been updated. For example:</p>
<pre>&nbsp;
&lt;input type=&quot;text&quot; id=&quot;in1&quot;/&gt;
&lt;br/&gt;
&lt;input type=&quot;text&quot; id=&quot;in2&quot;/&gt;
&nbsp;</pre>
<pre class="javascript">&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> myData = <span style="color: #003366; font-weight: bold;">new</span> DB<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #003366; font-weight: bold;">var</span> inputs = Y.<span style="color: #006600;">all</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;#in1, #in2&quot;</span><span style="color: #66cc66;">&#41;</span>;
myData.<span style="color: #006600;">on</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;change&quot;</span>, <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    inputs.<span style="color: #006600;">each</span><span style="color: #66cc66;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>node<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        node.<span style="color: #006600;">set</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'value'</span>, myData.<span style="color: #006600;">get</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
inputs.<span style="color: #006600;">on</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;keyup&quot;</span>, <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>ev<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    myData.<span style="color: #006600;">set</span><span style="color: #66cc66;">&#40;</span>ev.<span style="color: #006600;">currentTarget</span>.<span style="color: #006600;">get</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'value'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>This code is pretty simple. In YUI3 it creates an instance of DB, which has it's own private data (unset initially), subscribes to the change event with a function that updates both text inputs on the page if myData gets set(), and then binds to the keyup event on the text inputs to call myData.set() whenever the contents of either text input has something typed into it. This results in a page where both inputs update whenever you type into either one. </p>
<p>See the demo here: <a href="http://jsbin.com/utaku/6/">Data Binding in JavaScript</a></p>
<p>Is this useful? Practical? UnJavaScripty? I don't know, but I'd love to hear what you think <img src='http://truefalsemaybe.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://truefalsemaybe.com/2010/04/data-binding-in-javascript/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Better JavaScript Templating</title>
		<link>http://truefalsemaybe.com/2010/04/121/</link>
		<comments>http://truefalsemaybe.com/2010/04/121/#comments</comments>
		<pubDate>Thu, 15 Apr 2010 23:51:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://truefalsemaybe.com/?p=121</guid>
		<description><![CDATA[I recently had to do some really heavy lifting with templates in JavaScript, and opted to use John Resig's "Micro-templating" within the Underscore.js Library. It's nice, you can write JavaScript within your templates to control your flow, like:
&#160;
It's been &#60;%= (new Date()).getTime() %&#62; milliseconds since the epoch.
&#160;
Which, if you're like me is great. You could [...]]]></description>
			<content:encoded><![CDATA[<p>I recently had to do some really heavy lifting with templates in JavaScript, and opted to use John Resig's "<a href="http://ejohn.org/blog/javascript-micro-templating/">Micro-templating</a>" within the <a href="http://documentcloud.github.com/underscore/">Underscore.js</a> Library. It's nice, you can write JavaScript within your templates to control your flow, like:</p>
<pre>&nbsp;
It's been &lt;%= (new Date()).getTime() %&gt; milliseconds since the epoch.
&nbsp;</pre>
<p>Which, if you're like me is great. You could use <a href="http://code.google.com/closure/templates/">Google Closure Templates</a>, which probably is faster, but then you  would have to precompile your templates, which is a pain. </p>
<p>The only problem I personally had with the Resig solution was that if you tried to call a variable that didn't exist within your data object, it would fail horrifically, so I modified it slightly to be slightly more forgiving:</p>
<pre class="javascript">&nbsp;
  <span style="color: #009900; font-style: italic;">// JavaScript templating a-la ERB, pilfered from John Resig's</span>
  <span style="color: #009900; font-style: italic;">// &quot;Secrets of the JavaScript Ninja&quot;, page 83.</span>
  <span style="color: #009900; font-style: italic;">// Single-quote fix from Rick Strahl's version.</span>
  _.<span style="color: #006600;">template</span> = <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>str, data<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> fn = <span style="color: #003366; font-weight: bold;">new</span> <span style="color: #003366; font-weight: bold;">Function</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'obj'</span>,
      <span style="color: #3366CC;">'var p=[],print=function(){p.push.apply(p,arguments);};'</span> +
      <span style="color: #3366CC;">'with(obj){p.push(<span style="color: #000099; font-weight: bold;">\'</span>'</span> +
      str.<span style="color: #006600;">replace</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066FF;">/<span style="color: #66cc66;">&#91;</span>\r\t\n<span style="color: #66cc66;">&#93;</span>/g</span>, <span style="color: #3366CC;">&quot; &quot;</span><span style="color: #66cc66;">&#41;</span>
         .<span style="color: #006600;">replace</span><span style="color: #66cc66;">&#40;</span>/<span style="color: #3366CC;">'(?=[^%]*%&amp;gt;)/g,&quot;<span style="color: #000099; font-weight: bold;">\t</span>&quot;)
         .split(&quot;'</span><span style="color: #3366CC;">&quot;).join(&quot;</span>\\<span style="color: #3366CC;">'&quot;)
         .split(&quot;<span style="color: #000099; font-weight: bold;">\t</span>&quot;).join(&quot;'</span><span style="color: #3366CC;">&quot;)
         .replace(//g, &quot;</span><span style="color: #3366CC;">',(typeof($1)!='</span>undefined<span style="color: #3366CC;">') ? $1:'</span><span style="color: #3366CC;">','</span><span style="color: #3366CC;">&quot;) // modified to allow undefined variables pass through
         .split(&quot;</span><span style="color: #3366CC;">&quot;).join(&quot;</span>p.<span style="color: #006600;">push</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'&quot;)
         + &quot;'</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #66cc66;">&#125;</span><span style="color: #000066; font-weight: bold;">return</span> p.<span style="color: #006600;">join</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">''</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #3366CC;">&quot;);
    return data ? fn(data) : fn;
  };
</span></pre>
<p>The 12th line where it says .replace(//g...) includes a test for the data that is being passed into the function that's being created to output just an empty string if the variable is undefined. </p>
]]></content:encoded>
			<wfw:commentRss>http://truefalsemaybe.com/2010/04/121/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DataTable in yer DataTable</title>
		<link>http://truefalsemaybe.com/2010/03/datatable-in-yer-datatable/</link>
		<comments>http://truefalsemaybe.com/2010/03/datatable-in-yer-datatable/#comments</comments>
		<pubDate>Sat, 20 Mar 2010 00:24:05 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[yahoo]]></category>
		<category><![CDATA[yui]]></category>
		<category><![CDATA[yuiblog]]></category>

		<guid isPermaLink="false">http://truefalsemaybe.com/2010/03/datatable-in-yer-datatable/</guid>
		<description><![CDATA[
This is in response to Daniel Barreiro's post on putting DataTables in DataTables:
http://www.yuiblog.com/blog/2010/03/17/using-nested-datatables-for-row-expansion/
Credit: my coworker Jason R. Smith.
]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-117" title="yodawg" src="http://truefalsemaybe.com/wp-content/uploads/2010/03/yodawg.jpg" alt="yodawg" width="595" height="576" /></p>
<p>This is in response to Daniel Barreiro's post on putting DataTables in DataTables:</p>
<p><a href="http://www.yuiblog.com/blog/2010/03/17/using-nested-datatables-for-row-expansion/">http://www.yuiblog.com/blog/2010/03/17/using-nested-datatables-for-row-expansion/</a></p>
<p>Credit: my coworker Jason R. Smith.</p>
]]></content:encoded>
			<wfw:commentRss>http://truefalsemaybe.com/2010/03/datatable-in-yer-datatable/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What is JSONPX?</title>
		<link>http://truefalsemaybe.com/2009/10/what-is-jsonpx/</link>
		<comments>http://truefalsemaybe.com/2009/10/what-is-jsonpx/#comments</comments>
		<pubDate>Wed, 28 Oct 2009 19:19:34 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[javascript jsonp jsonpx templating xml]]></category>

		<guid isPermaLink="false">http://truefalsemaybe.com/?p=112</guid>
		<description><![CDATA[I saw a message on twitter about something called JSONPX, and did some research to try to find out what it was. According to Wait till I come this is a new way to provide XML with a callback. Essentially this is a format to provide markup Yahoo's API with a callback and metadata describing [...]]]></description>
			<content:encoded><![CDATA[<p>I saw a message on twitter about something called JSONPX, and did some research to try to find out what it was. According to <a href="http://www.wait-till-i.com/2009/07/09/another-interesting-yql-feature-xml-with-callback-json-p-x/">Wait till I come</a> this is a new way to provide XML with a callback. Essentially this is a format to provide markup Yahoo's API with a callback and metadata describing the query.</p>
<p>Pretty slick, if you ask me. Normally I'd take the JSONP results and have a JavaScript templating engine like <a href="http://ejohn.org/blog/javascript-micro-templating/">John Resig's Micro-Templating</a>. If you use Yahoo's <a href="http://developer.yahoo.com/yql/guide/sorting.html">sanitize</a> function, you can even make the HTML safe to insert via innerHTML, even though <a href="http://erik.eae.net/archives/2005/04/08/18.13.31/">innerHTML is evil</a>.</p>
<p>As it gets easier to do HTML layout without markup hacks, I see this approach becoming more common. Get the markup you want, with the metadata you need.</p>
]]></content:encoded>
			<wfw:commentRss>http://truefalsemaybe.com/2009/10/what-is-jsonpx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Be Cool</title>
		<link>http://truefalsemaybe.com/2009/05/be-cool/</link>
		<comments>http://truefalsemaybe.com/2009/05/be-cool/#comments</comments>
		<pubDate>Mon, 04 May 2009 05:42:18 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://truefalsemaybe.com/2009/05/be-cool/</guid>
		<description><![CDATA[Andrew says to his kids "What's the rule?"

]]></description>
			<content:encoded><![CDATA[<p>Andrew says to his kids "What's the rule?"</p>
<p><img class="alignnone size-full wp-image-108" title="becool" src="http://truefalsemaybe.com/wp-content/uploads/2009/05/becool.jpg" alt="becool" width="600" height="450" /></p>
]]></content:encoded>
			<wfw:commentRss>http://truefalsemaybe.com/2009/05/be-cool/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Tagging with SQLAlchemy</title>
		<link>http://truefalsemaybe.com/2009/04/100/</link>
		<comments>http://truefalsemaybe.com/2009/04/100/#comments</comments>
		<pubDate>Wed, 08 Apr 2009 20:47:03 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://truefalsemaybe.com/?p=100</guid>
		<description><![CDATA[I wanted to use tags with SQLAlchemy, so I looked up previous examples and found Wayne's post on how he did it. I adapted his code into a single file example so you can see better how it works. For any given page, there can be any number of tags .appended to it. For any [...]]]></description>
			<content:encoded><![CDATA[<p>I wanted to use tags with SQLAlchemy, so I looked up previous examples and found Wayne's post on how he did it. I adapted his code into a single file example so you can see better how it works. For any given page, there can be any number of tags .appended to it. For any given tag, you can .append it to any number of pages.</p>
<p>For example:</p>
<pre class="python">page = Page<span style="color: black;">&#40;</span>u<span style="color: #483d8b;">&quot;Example Page&quot;</span><span style="color: black;">&#41;</span>
page.<span style="color: black;">append</span><span style="color: black;">&#40;</span>Tag<span style="color: black;">&#40;</span>u<span style="color: #483d8b;">&quot;examples&quot;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></pre>
<pre class="python"><span style="color: #ff7700;font-weight:bold;">from</span> sqlalchemy <span style="color: #ff7700;font-weight:bold;">import</span> *
<span style="color: #ff7700;font-weight:bold;">from</span> sqlalchemy.<span style="color: black;">orm</span> <span style="color: #ff7700;font-weight:bold;">import</span> *
engine = create_engine<span style="color: black;">&#40;</span><span style="color: #483d8b;">'sqlite://'</span><span style="color: black;">&#41;</span>
metadata = MetaData<span style="color: black;">&#40;</span>engine<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">#engine.echo =True </span>
&nbsp;
page_table = Table<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;page&quot;</span>, metadata,
    Column<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;id&quot;</span>, Integer, Sequence<span style="color: black;">&#40;</span><span style="color: #483d8b;">'page_seq_id'</span>, optional=<span style="color: #008000;">True</span><span style="color: black;">&#41;</span>, primary_key=<span style="color: #008000;">True</span><span style="color: black;">&#41;</span>,
    Column<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;name&quot;</span>, Unicode<span style="color: black;">&#40;</span><span style="color: #ff4500;">100</span><span style="color: black;">&#41;</span>, nullable=<span style="color: #008000;">False</span><span style="color: black;">&#41;</span>,
<span style="color: black;">&#41;</span>
&nbsp;
tag_table = Table<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;tag&quot;</span>, metadata,
    Column<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;id&quot;</span>, Integer, Sequence<span style="color: black;">&#40;</span><span style="color: #483d8b;">'taq_seq_id'</span>, optional=<span style="color: #008000;">True</span><span style="color: black;">&#41;</span>, primary_key=<span style="color: #008000;">True</span><span style="color: black;">&#41;</span>,
    Column<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;name&quot;</span>, Unicode<span style="color: black;">&#40;</span><span style="color: #ff4500;">50</span><span style="color: black;">&#41;</span>, nullable=<span style="color: #008000;">False</span>, unique=<span style="color: #008000;">True</span><span style="color: black;">&#41;</span>,
<span style="color: black;">&#41;</span>
&nbsp;
pagetag_table = Table<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;pagetag&quot;</span>, metadata,
    Column<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;id&quot;</span>, Integer, Sequence<span style="color: black;">&#40;</span><span style="color: #483d8b;">'pagetag_seq_id'</span>, optional=<span style="color: #008000;">True</span><span style="color: black;">&#41;</span>, primary_key=<span style="color: #008000;">True</span><span style="color: black;">&#41;</span>,
    Column<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;pageid&quot;</span>, Integer, ForeignKey<span style="color: black;">&#40;</span><span style="color: #483d8b;">'page.id'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>,
    Column<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;tagid&quot;</span>, Integer, ForeignKey<span style="color: black;">&#40;</span><span style="color: #483d8b;">'tag.id'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>,
<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> Tag<span style="color: black;">&#40;</span><span style="color: #008000;">object</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, name<span style="color: black;">&#41;</span>:
        <span style="color: #008000;">self</span>.<span style="color: black;">name</span> = name
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__repr__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">&quot;Tag(<span style="color: #000099; font-weight: bold;">\&quot;</span>%s<span style="color: #000099; font-weight: bold;">\&quot;</span>)&quot;</span> % <span style="color: #008000;">self</span>.<span style="color: black;">name</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> Page<span style="color: black;">&#40;</span><span style="color: #008000;">object</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, name<span style="color: black;">&#41;</span>:
        <span style="color: #008000;">self</span>.<span style="color: black;">name</span> = name
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__repr__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">&quot;Page(<span style="color: #000099; font-weight: bold;">\&quot;</span>%s<span style="color: #000099; font-weight: bold;">\&quot;</span>)&quot;</span> % <span style="color: #008000;">self</span>.<span style="color: black;">name</span>
&nbsp;
mapper<span style="color: black;">&#40;</span>Tag, tag_table<span style="color: black;">&#41;</span>
mapper<span style="color: black;">&#40;</span>Page, page_table, properties = <span style="color: black;">&#123;</span>
    <span style="color: #483d8b;">'tags'</span>:relation<span style="color: black;">&#40;</span>Tag, secondary=pagetag_table, cascade=<span style="color: #483d8b;">&quot;all&quot;</span><span style="color: black;">&#41;</span>,
    <span style="color: #808080; font-style: italic;">#    'tags':relation(Tag, secondary=pagetag_table, cascade=&quot;all,delete-orphans&quot;),</span>
<span style="color: black;">&#125;</span><span style="color: black;">&#41;</span>
&nbsp;
metadata.<span style="color: black;">create_all</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
sess = create_session<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
page = Page<span style="color: black;">&#40;</span>u<span style="color: #483d8b;">&quot;Tags with SQLAlchemy Example&quot;</span><span style="color: black;">&#41;</span>
page2 = Page<span style="color: black;">&#40;</span>u<span style="color: #483d8b;">&quot;Hot New Video Game Consists Solely Of Shooting People Point-Blank In The Face&quot;</span><span style="color: black;">&#41;</span>
page3 = Page<span style="color: black;">&#40;</span>u<span style="color: #483d8b;">&quot;Congressman's War Hero Son Would Have Wanted Highway Bill Passed&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
tag = Tag<span style="color: black;">&#40;</span>u<span style="color: #483d8b;">&quot;examples&quot;</span><span style="color: black;">&#41;</span>
tag2 = Tag<span style="color: black;">&#40;</span>u<span style="color: #483d8b;">&quot;onion&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
page.<span style="color: black;">tags</span>.<span style="color: black;">append</span><span style="color: black;">&#40;</span>tag<span style="color: black;">&#41;</span>
page2.<span style="color: black;">tags</span>.<span style="color: black;">append</span><span style="color: black;">&#40;</span>tag2<span style="color: black;">&#41;</span>
page3.<span style="color: black;">tags</span>.<span style="color: black;">append</span><span style="color: black;">&#40;</span>tag2<span style="color: black;">&#41;</span>
&nbsp;
sess.<span style="color: black;">add</span><span style="color: black;">&#40;</span>page<span style="color: black;">&#41;</span>
sess.<span style="color: black;">add</span><span style="color: black;">&#40;</span>page2<span style="color: black;">&#41;</span>
sess.<span style="color: black;">add</span><span style="color: black;">&#40;</span>page3<span style="color: black;">&#41;</span>
sess.<span style="color: black;">flush</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
tag_q = sess.<span style="color: black;">query</span><span style="color: black;">&#40;</span>Tag<span style="color: black;">&#41;</span>
tags = tag_q.<span style="color: black;">all</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Number of tags:&quot;</span>, <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>tags<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># filter pages by tag(s)</span>
page_q = sess.<span style="color: black;">query</span><span style="color: black;">&#40;</span>Page<span style="color: black;">&#41;</span>
pages = page_q.<span style="color: black;">join</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'tags'</span><span style="color: black;">&#41;</span>.<span style="color: black;">filter_by</span><span style="color: black;">&#40;</span>name=u<span style="color: #483d8b;">&quot;tag&quot;</span><span style="color: black;">&#41;</span>.<span style="color: black;">all</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">print</span>
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;First Page&quot;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> page_q.<span style="color: black;">first</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> page_q.<span style="color: black;">first</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">tags</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">print</span>
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Second Page&quot;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> page_q.<span style="color: black;">all</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> page_q.<span style="color: black;">all</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>.<span style="color: black;">tags</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">print</span>
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Third Page&quot;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> page_q.<span style="color: black;">all</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> page_q.<span style="color: black;">all</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span>.<span style="color: black;">tags</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># delete-orphans does the work for us here...</span>
<span style="color: #808080; font-style: italic;">#sess.delete(pages[0]</span>
<span style="color: #808080; font-style: italic;">#sess.flush()</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">print</span>
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;All tags&quot;</span>
tags = tag_q.<span style="color: black;">all</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> tags, <span style="color: #483d8b;">&quot;Count:&quot;</span>, <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>tags<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">print</span>
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Tag cloud anyone?&quot;</span>
<span style="color: #808080; font-style: italic;"># see the source code linked below for a properly weighted tag cloud.</span>
tag_q = sess.<span style="color: black;">query</span><span style="color: black;">&#40;</span>func.<span style="color: black;">count</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;*&quot;</span><span style="color: black;">&#41;</span>.<span style="color: black;">label</span><span style="color: black;">&#40;</span>u<span style="color: #483d8b;">&quot;tagcount&quot;</span><span style="color: black;">&#41;</span>, Tag<span style="color: black;">&#41;</span>
tag_r = tag_q.<span style="color: #008000;">filter</span><span style="color: black;">&#40;</span>Tag.<span style="color: #008000;">id</span>==pagetag_table.<span style="color: black;">c</span>.<span style="color: black;">tagid</span><span style="color: black;">&#41;</span>.<span style="color: black;">group_by</span><span style="color: black;">&#40;</span>Tag.<span style="color: #008000;">id</span><span style="color: black;">&#41;</span>.<span style="color: black;">all</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #808080; font-style: italic;">#print tag_q</span>
<span style="color: #ff7700;font-weight:bold;">print</span> tag_r
&nbsp;
<span style="color: #808080; font-style: italic;"># what about pages with related tags?</span>
page_q = sess.<span style="color: black;">query</span><span style="color: black;">&#40;</span>Page<span style="color: black;">&#41;</span>
&nbsp;
taglist = <span style="color: black;">&#91;</span>u<span style="color: #483d8b;">&quot;tag1&quot;</span>, u<span style="color: #483d8b;">&quot;tag2&quot;</span><span style="color: black;">&#93;</span>
tagcount = <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>taglist<span style="color: black;">&#41;</span>
page_q.<span style="color: black;">join</span><span style="color: black;">&#40;</span>Page.<span style="color: black;">tags</span><span style="color: black;">&#41;</span>.<span style="color: #008000;">filter</span><span style="color: black;">&#40;</span>Tag.<span style="color: black;">name</span>.<span style="color: black;">in_</span><span style="color: black;">&#40;</span>taglist<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>.\
group_by<span style="color: black;">&#40;</span>Page.<span style="color: #008000;">id</span><span style="color: black;">&#41;</span>.<span style="color: black;">having</span><span style="color: black;">&#40;</span>func.<span style="color: black;">count</span><span style="color: black;">&#40;</span>Page.<span style="color: #008000;">id</span><span style="color: black;">&#41;</span> == tagcount<span style="color: black;">&#41;</span>.<span style="color: black;">all</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre>
<p>I know tag clouds are passe, but I still think from an information architecture perspective, tags still better than categories.</p>
]]></content:encoded>
			<wfw:commentRss>http://truefalsemaybe.com/2009/04/100/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Giving up Reddit for Lent</title>
		<link>http://truefalsemaybe.com/2009/02/giving-up-reddit-for-lent/</link>
		<comments>http://truefalsemaybe.com/2009/02/giving-up-reddit-for-lent/#comments</comments>
		<pubDate>Tue, 24 Feb 2009 18:05:46 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[productivity]]></category>

		<guid isPermaLink="false">http://truefalsemaybe.com/?p=95</guid>
		<description><![CDATA[I'm not religious but I like the idea of Lent because it fits into the idea of changing our habits, which is hard to do and potentially has dramatic long standing effects on how we live.
I for one love reading Reddit and sometimes Digg, but I find it to be somewhat a sinkhole. Sure it's [...]]]></description>
			<content:encoded><![CDATA[<p>I'm not religious but I like the idea of Lent because it fits into the idea of changing our habits, which is hard to do and potentially has dramatic long standing effects on how we live.</p>
<p>I for one love reading <a href="http://reddit.com">Reddit</a> and sometimes <a href="http://digg.com">Digg</a>, but I find it to be somewhat a sinkhole. Sure it's funny to read about how someone destroyed their finger with magnets or see a cute picture of a coyote on the BART, but from a learning perspective, I'd be better off spending my time on <a href="http://news.ycombinator.com/">hacker news</a>.</p>
<p>So to that end, I'm modifying my host file to give up reddit for lent. Who knows, maybe instead of removing the entry after lent, I'll add more instead.</p>
<p>Here's how you can do it too:<br />
<a href="http://www.allthingsmarked.com/2006/08/28/howto-block-websites-using-the-hosts-file/">Windows</a> | <a href="http://osxdaily.com/2007/03/19/block-access-to-specified-sites-by-modifying-etchosts/">OSX</a> | <a href="http://tugalinux.wordpress.com/2009/01/15/blocking-websites-using-the-hosts-file/">Linux</a></p>
]]></content:encoded>
			<wfw:commentRss>http://truefalsemaybe.com/2009/02/giving-up-reddit-for-lent/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>RIP Phild0g</title>
		<link>http://truefalsemaybe.com/2008/12/rip-phild0g/</link>
		<comments>http://truefalsemaybe.com/2008/12/rip-phild0g/#comments</comments>
		<pubDate>Tue, 16 Dec 2008 19:04:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[death]]></category>
		<category><![CDATA[djs]]></category>
		<category><![CDATA[phild0g]]></category>

		<guid isPermaLink="false">http://truefalsemaybe.com/?p=89</guid>
		<description><![CDATA[
I'm bummed out. My old friend, Phil passed away last monday and I missed the get together this last weekend because I've been off the social grid these past months. The above photo is probably the best picture I took in high school, and was used to create a flyer for the Rollcall parties I [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://truefalsemaybe.com/wp-content/uploads/2008/12/n510389663_1775344_2020.jpg"><img class="alignnone size-full wp-image-90" title="phild0g" src="http://truefalsemaybe.com/wp-content/uploads/2008/12/n510389663_1775344_2020.jpg" alt="" /></a></p>
<p>I'm bummed out. My old friend, Phil passed away last monday and I missed the get together this last weekend because I've been off the social grid these past months. The above photo is probably the best picture I took in high school, and was used to create a flyer for the Rollcall parties I helped (in a small part) to throw with Phild0g. This picture was taken in the desert, a home away from home for all of us.</p>
]]></content:encoded>
			<wfw:commentRss>http://truefalsemaybe.com/2008/12/rip-phild0g/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
