<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><atom:link rel="hub" href="http://tumblr.superfeedr.com/" xmlns:atom="http://www.w3.org/2005/Atom"/><description>Comments on programming, web development, and computers by Titus Stone.</description><title>url::encode</title><generator>Tumblr (3.0; @urlencode)</generator><link>http://urlencode.tumblr.com/</link><item><title>Immutable Arrays in Javascript</title><description>&lt;p&gt;Most instance methods of javascript&amp;#8217;s array perform mutations on the array.  Because objects are assigned by reference, this creates some odd situations&amp;#8230;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;var a = [1, 2, 3];&lt;/em&gt;&lt;br/&gt;&lt;em&gt;var b = a;&lt;/em&gt;&lt;br/&gt;&lt;em&gt;b.push(4);&lt;/em&gt;&lt;br/&gt;&lt;em&gt;// a == [1, 2, 3, 4]; &lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;When taking on functional programming practices, one of the first things is dealing with the mutation-based implementation of array methods.  Fortunately it&amp;#8217;s possible to implement immutable methods along side the mutable methods and use those instead.&lt;/p&gt;
&lt;p&gt;First up is a way to create a fresh array.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Array.prototype.clone = function() { return this.slice(0); };&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;It turns out clone-like functionality is built into the language, however it&amp;#8217;s not labeled as such.  &lt;em&gt;Slice&lt;/em&gt; returns a &lt;strong&gt;new array&lt;/strong&gt; from the given dimensions.  That means if we slice an array starting at 0 then we&amp;#8217;ll always end up with a new copy of that array.  Nice.&lt;/p&gt;
&lt;p&gt;Using clone we can then implement immutable alternatives to methods.  It&amp;#8217;s worth nothing that these so-called immutable alternatives really use mutation internally to achieve the results.  However, the end effect from &amp;#8220;outside&amp;#8221; the method is that they work like immutable methods.&lt;/p&gt;
&lt;p&gt;Many javascript array methods have a return value of the array&amp;#8217;s new length.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;var a = [1, 2, 3].push(4);&lt;/em&gt;&lt;br/&gt;&lt;em&gt;// a == 4 &lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;However in most cases what we really want is the new array being returned.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Array.prototype.ipush = function(x) {&lt;/em&gt;&lt;br/&gt;&lt;em&gt;    var a = this.clone();&lt;/em&gt;&lt;br/&gt;&lt;em&gt;    a.push(x);&lt;/em&gt;&lt;br/&gt;&lt;em&gt;    return a;&lt;/em&gt;&lt;br/&gt;&lt;em&gt;};&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Using this syntax things work in immutable ways like we&amp;#8217;d expect.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;var a = [1, 2, 3];&lt;/em&gt;&lt;br/&gt;&lt;em&gt;var b = a.ipush(4);&lt;/em&gt;&lt;br/&gt;&lt;em&gt;// a == [1, 2, 3];&lt;/em&gt;&lt;br/&gt;&lt;em&gt;// b == [1, 2, 3, 4];&lt;/em&gt; &lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;It turns out this pattern of cloning an array, calling a mutable method, then returning the new array is how all of these functions would work, so it&amp;#8217;s possible to simplify this a bit.&lt;/p&gt;
&lt;p&gt;All javascript functions include two functions, &lt;em&gt;call&lt;/em&gt; and &lt;em&gt;apply&lt;/em&gt;, which can be used to invoke that function.  In particular, &lt;em&gt;apply&lt;/em&gt; takes two things, the &amp;#8220;context&amp;#8221; of what &amp;#8220;this&amp;#8221; should be and an array of arguments to invoke a function with.&lt;/p&gt;
&lt;p&gt;For example:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;function doStuff(x, y) { alert(x + &amp;#8221; and &amp;#8221; + y + &amp;#8220;!&amp;#8221;); }&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;// These are equivalent:&lt;/em&gt;&lt;br/&gt;&lt;em&gt;doStuff.apply(this, [&amp;#8216;foo&amp;#8217;, &amp;#8216;bar&amp;#8217;]); &lt;/em&gt;&lt;br/&gt;&lt;em&gt;doStuff(&amp;#8216;foo&amp;#8217;, &amp;#8216;bar&amp;#8217;);&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Why would that ever matter?  Well in this case we want to implement array methods as immutable but we don&amp;#8217;t necessarily always know how many arguments each method takes.  We can circumvent this by turning the magical keyword &lt;em&gt;arguments&lt;/em&gt; into an array, then using &lt;em&gt;apply&lt;/em&gt; to invoke that function.&lt;/p&gt;
&lt;p&gt;Putting that all together, here&amp;#8217;s a way to implement immutable versions of array methods in one swoop:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;[&amp;#8216;push&amp;#8217;, &amp;#8216;unshift&amp;#8217;, &amp;#8216;reverse&amp;#8217;, &amp;#8216;splice&amp;#8217;].forEach(function(x){&lt;/em&gt;&lt;br/&gt;&lt;em&gt;     Array.prototype[&amp;#8216;i&amp;#8217;+x] = function() {&lt;/em&gt;&lt;br/&gt;&lt;em&gt;         var na = this.clone()&lt;/em&gt;&lt;br/&gt;&lt;em&gt;           , args = Array.prototype.slice.call(arguments, 0);&lt;/em&gt;&lt;br/&gt;&lt;em&gt;         na[x].apply(na, args);&lt;/em&gt;&lt;br/&gt;&lt;em&gt;         return na;&lt;/em&gt;&lt;br/&gt;&lt;em&gt;     }&lt;/em&gt;&lt;br/&gt;&lt;em&gt; });&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Tada.  We can now use these by simply prefixing &amp;#8220;i&amp;#8221; in front of each to get the immutable version.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;var a = [1, 2, 3];&lt;/em&gt;&lt;br/&gt;&lt;em&gt;var b = a.iunshift(4, 5, 6);&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;// a == [1, 2, 3];&lt;/em&gt;&lt;br/&gt;&lt;em&gt;// b == [4, 5, 6, 1, 2, 3];&lt;/em&gt; &lt;/p&gt;
&lt;/blockquote&gt;</description><link>http://urlencode.tumblr.com/post/18114395984</link><guid>http://urlencode.tumblr.com/post/18114395984</guid><pubDate>Wed, 22 Feb 2012 21:31:00 -0700</pubDate><category>javascript</category><category>arrays</category><category>functional-programming</category></item><item><title>Programming Puzzle: String Length</title><description>&lt;p&gt;&lt;strong&gt;Determine the length of a string without using any built-in &amp;#8220;.length&amp;#8221; or length getting functions.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Typical to true-engineering form, my first idea was overly complicated.  I had reasoned that I could write a recursive loop to progressively build up a 2nd string, then compare them to see if the lengths matched.  The problem there of course is that in order to do the comparison I have to use .length. #fail&lt;/p&gt;
&lt;p&gt;After chuckling at myself for such an obvious oversight I realized there was a simpler solution.  A string could be treated as an array, and the first character could simply be shifted off recursively and the length determined that way.  A simpler implementation would be instead of converting the string to an array, simply using .substr(1).&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;function getStrLen (s) {&lt;/em&gt;&lt;br/&gt;&lt;em&gt;     var loop = function(acc, s) {&lt;/em&gt;&lt;br/&gt;&lt;em&gt;         if (s === &amp;#8220;&amp;#8221;) { return acc; }&lt;/em&gt;&lt;br/&gt;&lt;em&gt;         return loop(acc + 1, s.substr(1));&lt;/em&gt;&lt;br/&gt;&lt;em&gt;     };&lt;/em&gt;&lt;br/&gt;&lt;em&gt;     return loop(0, s);&lt;/em&gt;&lt;br/&gt;&lt;em&gt; }&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Now that I&amp;#8217;ve gotten used to tail recursion, it seems that I&amp;#8217;m seeing uses for it &lt;em&gt;everywhere&lt;/em&gt;.  I hope that&amp;#8217;s a good thing&amp;#8230;&lt;/p&gt;</description><link>http://urlencode.tumblr.com/post/18057688010</link><guid>http://urlencode.tumblr.com/post/18057688010</guid><pubDate>Tue, 21 Feb 2012 22:27:00 -0700</pubDate><category>javascript</category><category>puzzle</category></item><item><title>FizzBuzz in F#</title><description>&lt;p&gt;If you&amp;#8217;re not familiar with what FizzBuzz is, check out &lt;a href="http://www.codinghorror.com/blog/2007/02/why-cant-programmers-program.html"&gt;this blog post by Jeff Atwood (Coding Horror)&lt;/a&gt;.  FizzBuzz is sort of that bare-minimum-entry-level-bar that when you can clear you know you&amp;#8217;ve at least understood the basic grammar of a language.  Typically I find in learning languages what takes the most time is really learning the standard library and built in functions.&lt;/p&gt;
&lt;p&gt;F# has proven to be no exception to this and even though it has the entire .NET framework library behind it, there were some quirky things there to trip me up.  A great example is the &lt;em&gt;printfn&lt;/em&gt; function.&lt;/p&gt;
&lt;p&gt;Consider the following, which, though it seems like a trivial bit of code is actually wrong:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;let x = &amp;#8220;Hello World&amp;#8221;&lt;/em&gt;&lt;br/&gt;&lt;em&gt;printfn x&lt;/em&gt; &lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Running the above will thrown an exception&amp;#8230;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;The type &amp;#8216;string&amp;#8217; is not compatible with the type &amp;#8216;Printf.TextWriterFormat&amp;lt;&amp;#8217;a&amp;gt;&amp;#8217;&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Really?  A &lt;em&gt;string&lt;/em&gt; can&amp;#8217;t be printed out?  There&amp;#8217;s a &lt;a href="http://stackoverflow.com/questions/2162081/type-of-printfn-in-f-static-vs-dynamic-string"&gt;question on StackOverflow&lt;/a&gt; which summarizes why this happens, but the short version is that &lt;em&gt;printfn&lt;/em&gt; expects input to be of type TextWriterFormat&amp;lt;T&amp;gt;.  Right.&lt;/p&gt;
&lt;p&gt;So the fix for the code above would be:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;let x = &amp;#8220;Hello World&amp;#8221;&lt;/em&gt;&lt;br/&gt;&lt;em&gt;printfn &amp;#8220;%s&amp;#8221; x&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;I&amp;#8217;ve been trying to write FizzBuzz in F# now for a week and while I probably have had it correct for a while, the printfn issue has been throwing me off this whole time.&lt;/p&gt;
&lt;p&gt;In any case, here is FizzBuzz in F# (where the side effect of printing has been isolated to outside of the function):&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;let fizzbuzz n =&lt;/em&gt;&lt;br/&gt;&lt;em&gt;     match n with&lt;/em&gt;&lt;br/&gt;&lt;em&gt;     | n when n % 15 = 0 -&amp;gt; &amp;#8220;FizzBuzz&amp;#8221;&lt;/em&gt;&lt;br/&gt;&lt;em&gt;     | n when n % 5 = 0  -&amp;gt; &amp;#8220;Buzz&amp;#8221;&lt;/em&gt;&lt;br/&gt;&lt;em&gt;     | n when n % 3 = 0  -&amp;gt; &amp;#8220;Fizz&amp;#8221;&lt;/em&gt;&lt;br/&gt;&lt;em&gt;     | _                 -&amp;gt; n.ToString() &lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;[1 .. 100] |&amp;gt; Seq.iter(fun x -&amp;gt; printfn &amp;#8220;%s&amp;#8221; (fizzbuzz x))&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;</description><link>http://urlencode.tumblr.com/post/17823500186</link><guid>http://urlencode.tumblr.com/post/17823500186</guid><pubDate>Sat, 18 Feb 2012 08:23:51 -0700</pubDate><category>f</category><category>fizzbuzz</category></item><item><title>Appending to a List in F#</title><description>&lt;p&gt;One thing about functional languages which sounds somewhat simple at first but turns out to be more complex is immutable values.  Variables (or &amp;#8220;values&amp;#8221; as they&amp;#8217;re called in F#) can&amp;#8217;t be changed once they&amp;#8217;ve been initialized.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;let x = 2&lt;/em&gt;&lt;br/&gt;&lt;em&gt;// This isn&amp;#8217;t allowed:&lt;/em&gt;&lt;br/&gt;&lt;em&gt;x = x + 3 &lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Values in F# can be thought of as an equivalent to C#&amp;#8217;s &lt;em&gt;readonly&lt;/em&gt; accessor.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;int readonly x = 2;&lt;/em&gt;&lt;br/&gt;&lt;em&gt;// This isn&amp;#8217;t allowed:&lt;/em&gt;&lt;br/&gt;&lt;em&gt;x += 3;&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The reasons for this are beyond the scope of this blog post.  However, while the idea seems simple it contains a few &amp;#8220;gotchas&amp;#8221;.&lt;/p&gt;
&lt;p&gt;One such of these is appending to a list.  In C# this is quite a common task:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;List&amp;lt;string&amp;gt; names = new List&amp;lt;string&amp;gt;();&lt;/em&gt;&lt;br/&gt;&lt;em&gt;names.Add(&amp;#8220;Bob&amp;#8221;);&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;There is no such thing in F#.  Instead there is the cons operator, ::, the syntax of which is:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;element :: list&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The result from the above is that cons returns a &lt;strong&gt;new &lt;/strong&gt;list, with the element on the left being the first item of that new list and every item which was in list following it.  (Sidenote, the &lt;a href="http://msdn.microsoft.com/en-us/library/dd233228.aspx"&gt;F# documentation&lt;/a&gt; actually has this incorrect.  It&amp;#8217;s not appended.  Too bad it&amp;#8217;s not a wiki.)&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;let x = [1; 2; 3;]&lt;/em&gt;&lt;br/&gt;&lt;em&gt;let y = 0 :: x&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;val y&amp;#160;: int list = [0; 1; 2; 3;]&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Cons is a much better performer.  The code doesn&amp;#8217;t have to iterate over all the list items just to add the new one.  To illustrate why this is relevant let us suppose we needed the append functionality and we were going to implement it ourself.&lt;/p&gt;
&lt;p&gt;We could start by reversing the list, then using cons to add what we want to be the last item to the beginning.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;let a = [1 .. 3]&lt;/em&gt;&lt;br/&gt;&lt;em&gt;let b = 4 :: List.rev a&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;val b&amp;#160;: int list = [4; 3; 2; 1;]&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;This gets us halfway, because even though our data is sequenced correctly, the list is in the wrong order.  We can fix that by once again reversing b into our final list.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;let a = [1 .. 3]&lt;/em&gt;&lt;br/&gt;&lt;em&gt;let b = 4 :: List.rev a&lt;/em&gt;&lt;br/&gt;&lt;em&gt;let c = List.rev b &lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;val c&amp;#160;: int list [1; 2; 3; 4;]&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;At this point it should be obvious why there is no append operator.  Internally the language would be doing this.  You might say, &amp;#8220;but it needs to get done, so why not just have a language construct for it?&amp;#8221;&lt;/p&gt;
&lt;p&gt;Let&amp;#8217;s say we refactored the above code into a function for re-use.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;let append elem list = List.rev (elem :: List.rev list)&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Great, now let&amp;#8217;s use it in some code.  Let&amp;#8217;s say we&amp;#8217;re using tail recursion and an accumulator to make a list of CSS vendor/webkit prefixes.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;let webkitify props =&lt;/em&gt;&lt;br/&gt;&lt;em&gt;    let rec loop list acc =&lt;/em&gt;&lt;br/&gt;&lt;em&gt;        match list with&lt;/em&gt;&lt;br/&gt;&lt;em&gt;        | head :: tail -&amp;gt; loop tail (append (&amp;#8220;-webkit-&amp;#8221; + head) acc)&lt;/em&gt;&lt;br/&gt;&lt;em&gt;        | [] -&amp;gt; acc&lt;/em&gt;&lt;br/&gt;&lt;em&gt;    loop props []&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;let props = [&amp;#8220;border-radius&amp;#8221;; &amp;#8220;box-shadow&amp;#8221;;]&lt;/em&gt;&lt;br/&gt;&lt;em&gt;let prefixed = webkitify props&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Making use of the &lt;em&gt;append&lt;/em&gt; function now, how many times is List.rev being called?  Within &lt;em&gt;append&lt;/em&gt; it&amp;#8217;s called twice which means that our simple function to prefix CSS properties with -webkit- calls List.rev twice for every item of the list (n * 2).&lt;/p&gt;
&lt;p&gt;That&amp;#8217;s &lt;em&gt;really&lt;/em&gt; inefficient.  This is likely a big reason there isn&amp;#8217;t an append operator.  Instead a very small change could be made to the function.  First, instead of appending items to the accumulator, the cons operator could be used:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;let webkitify props =&lt;/em&gt;&lt;br/&gt;&lt;em&gt;    let rec loop list acc =&lt;/em&gt;&lt;br/&gt;&lt;em&gt;        match list with&lt;/em&gt;&lt;br/&gt;&lt;em&gt;        | head :: tail -&amp;gt; loop tail (&lt;strong&gt;(&amp;#8220;-webkit-&amp;#8221; + head) :: acc&lt;/strong&gt;)&lt;/em&gt;&lt;br/&gt;&lt;em&gt;        | [] -&amp;gt; acc&lt;/em&gt;&lt;br/&gt;&lt;em&gt;    loop props []&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;let props = [&amp;#8220;border-radius&amp;#8221;; &amp;#8220;box-shadow&amp;#8221;;]&lt;/em&gt;&lt;br/&gt;&lt;em&gt;let prefixed = webkitify props&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Then, once the loop has run out of items to recurse through the final result (the accumulator) can be reversed &lt;strong&gt;&lt;em&gt;once&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;let webkitify props =&lt;/em&gt;&lt;br/&gt;&lt;em&gt;    let rec loop list acc =&lt;/em&gt;&lt;br/&gt;&lt;em&gt;        match list with&lt;/em&gt;&lt;br/&gt;&lt;em&gt;        | head :: tail -&amp;gt; loop tail (&lt;strong&gt;(&amp;#8220;-webkit-&amp;#8221; + head) :: acc&lt;/strong&gt;)&lt;/em&gt;&lt;br/&gt;&lt;em&gt;        | [] -&amp;gt; &lt;strong&gt;List.rev&lt;/strong&gt; acc&lt;/em&gt;&lt;br/&gt;&lt;em&gt;    loop props []&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;let props = [&amp;#8220;border-radius&amp;#8221;; &amp;#8220;box-shadow&amp;#8221;;]&lt;/em&gt;&lt;br/&gt;&lt;em&gt;let prefixed = webkitify props&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;And there you have it: Why you don&amp;#8217;t need an list append function.&lt;/p&gt;
&lt;p&gt;Just for clarity, the above code is just for illustration purposes.  If you really wanted to add -webkit- to a list of props you&amp;#8217;d use List.map, which composes a new list based on a function that is applied to every list item.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;List.map (fun x -&amp;gt; &amp;#8220;-webkit-&amp;#8221; + x) props&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;</description><link>http://urlencode.tumblr.com/post/17701442686</link><guid>http://urlencode.tumblr.com/post/17701442686</guid><pubDate>Wed, 15 Feb 2012 23:11:00 -0700</pubDate><category>F</category><category>functional-programming</category></item><item><title>F# is a Trip (or What is Function Currying)</title><description>&lt;p&gt;For developers that have been living in javaland, javascriptland, or C#land for any lengthy period of time, the first encounter with a very &lt;em&gt;functional&lt;/em&gt; language, it&amp;#8217;s definitely weird.  F# is Microsoft&amp;#8217;s latest language addition to their .NET kingdom.  It&amp;#8217;s a functional/object oriented hybrid language which leans more towards the functional side and finds it&amp;#8217;s roots in &lt;a href="http://en.wikipedia.org/wiki/OCaml"&gt;OCaml&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Quite frankly, it has some of the coolest features you&amp;#8217;ll find on .NET at the moment, which head and shoulders above the rest of the .NET languages is the interpreter.  Further, the integration of the interpreter with Visual Studio reminds me of a Paul Graham quote from &lt;em&gt;Hackers and Painters&lt;/em&gt;, (paraphrased) &amp;#8220;programming languages should be for programmers to sketch in&amp;#8221;.&lt;/p&gt;
&lt;p&gt;It works like this:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Highlight code you&amp;#8217;d like to execute&lt;br/&gt;Press Alt+Enter&lt;br/&gt;The code runs and the result appears in a console below the code, directly in Visual Studio &lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;As it turns out the interactive console is also great for &lt;strong&gt;language exploration&lt;/strong&gt;.  The syntax of F# is a bit more minimal than you&amp;#8217;d expect coming from C#.  Functions are defined just like values using an = where parameters aren&amp;#8217;t wrapped in parenthesis.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;let increment x = x + 1&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Running that in the interpreter returns&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;val increment&amp;#160;: int -&amp;gt; int&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Two really important things are in that line.  First, F# inferred the type.  No where in the code is &lt;em&gt;int&lt;/em&gt; specified as the type.  F# is a strongly typed language, but it will infer the type.&lt;/p&gt;
&lt;p&gt;The second important thing is that F# returned to us the type signature of the function.  This type signature business is reminiscent of languages like Scala and Haskell.  &lt;em&gt;int -&amp;gt; int&lt;/em&gt; &amp;#8212; It basically means one integer is inputted and one integer is outputted.&lt;/p&gt;
&lt;p&gt;But things get more interesting.  The &lt;em&gt;increment&lt;/em&gt; function could be given a more broad usage.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;let add x y = x + y&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Interpreting the new function &lt;em&gt;add&lt;/em&gt; returns&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;val add&amp;#160;: int -&amp;gt; int -&amp;gt; int&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;That is not what one would expect.  The way the function is written is the average developer would expect a type signature of&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;val add&amp;#160;: int, int -&amp;gt; int&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;But that&amp;#8217;s not what F# is returning.  Reading the type signature, it appears that F# is interpreting the &lt;em&gt;add&lt;/em&gt; function as &lt;strong&gt;two&lt;/strong&gt; functions which it turns out is the case.  If the lack of ()&amp;#8217;s on the functions was odd at first, then this is part of the reason why.  For each parameter on a function, behind the scenes F# makes a new function that returns a function.  (It&amp;#8217;s not called a &amp;#8220;functional language&amp;#8221; for nothin&amp;#8217;)&lt;/p&gt;
&lt;p&gt;Why does all of this matter however?  Is it just compiler trickery or is there any use for this?  Because F# is internally creating a function for each additional parameter past the first one, if only &lt;em&gt;some&lt;/em&gt; of the arguments were to be passed into &lt;em&gt;add&lt;/em&gt;, what would be returned would not be a result, but another function.&lt;/p&gt;
&lt;p&gt;Consider&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;let add x y = x + y&lt;/em&gt;&lt;br/&gt;&lt;em&gt;let increment = add 1&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&amp;gt; val increment&amp;#160;: (int -&amp;gt; int)&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;let a = increment 2&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&amp;gt; val a&amp;#160;: int = 3&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The type signature for &lt;em&gt;increment&lt;/em&gt; is int -&amp;gt; int!  Increment is a partially applied function.  It executions &lt;em&gt;some&lt;/em&gt; of the parameters of &lt;em&gt;add&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;This is function currying.&lt;/p&gt;
&lt;p&gt;It&amp;#8217;s a trip.&lt;/p&gt;</description><link>http://urlencode.tumblr.com/post/17422669907</link><guid>http://urlencode.tumblr.com/post/17422669907</guid><pubDate>Sat, 11 Feb 2012 06:15:00 -0700</pubDate><category>F</category><category>functional-programming</category></item><item><title>LINQ is List Comprehensions in Disguise</title><description>&lt;p&gt;I had a stunning realization last night.  LINQ is nothing more  than Microsoft&amp;#8217;s implementation of Haskell  list comprehensions (a  language I greatly admire).  It&amp;#8217;s not obvious this is what LINQ is,  because Microsoft chose to change the keywords to be more SQL-like.&lt;/p&gt;
&lt;p&gt;In Python or ECMAScript 6, a list comprehension can be written like so:&lt;/p&gt;
&lt;blockquote&gt;&lt;em&gt;[x for x in set (if condition)]&lt;/em&gt;&lt;/blockquote&gt;
&lt;p&gt;Say  for example you had a list of numbers and you wanted to find the value  of them squared.  You could write something verbose like&amp;#8230;&lt;/p&gt;
&lt;blockquote&gt;&lt;em&gt;public List&amp;lt;int&amp;gt; Square(List&amp;lt;int&amp;gt; input)&lt;br/&gt;&lt;/em&gt;&lt;em&gt;{&lt;br/&gt;&lt;/em&gt;&lt;em&gt;    List&amp;lt;int&amp;gt; result = new List&amp;lt;int&amp;gt;();&lt;br/&gt;&lt;/em&gt;&lt;em&gt;    foreach (int i in input)&lt;br/&gt;&lt;/em&gt;&lt;em&gt;        result.Add(i * i);&lt;br/&gt;&lt;/em&gt;&lt;em&gt;    return result;&lt;br/&gt;&lt;/em&gt;&lt;em&gt;}&lt;/em&gt; &lt;/blockquote&gt;
&lt;p&gt;List comprehensions would allow that to be written in a much more succinct way&amp;#8230;&lt;/p&gt;
&lt;blockquote&gt;&lt;em&gt;[x * x for x in list]&lt;/em&gt;&lt;/blockquote&gt;
&lt;p&gt;That&amp;#8217;s much  shorter and easier to tell the intent of what&amp;#8217;s happening.  With a  list comprehension, it&amp;#8217;s also possible to add a conditional in there  too.  For example, let&amp;#8217;s say we only wanted to find the squared value  where &lt;em&gt;x&lt;/em&gt; was even.&lt;/p&gt;
&lt;blockquote&gt;&lt;em&gt;[x * x for x in list if x % 2 == 0]&lt;/em&gt;&lt;/blockquote&gt;
&lt;p&gt;It turns out, this is what LINQ is.  Microsoft made a few changes however:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;The  first phrase in a list comprehension is typically the function to map  against.  Microsoft moved this to the end of the statement and called it  &amp;#8220;select&amp;#8221;&lt;/li&gt;
&lt;li&gt;The &amp;#8220;for&amp;#8221; was renamed &amp;#8220;from&amp;#8221;&lt;/li&gt;
&lt;li&gt;&amp;#8220;if&amp;#8221; was renamed to &amp;#8220;where&amp;#8221;&lt;/li&gt;
&lt;/ul&gt;&lt;p&gt;So we can take that exact list comprehension from a dynamic/functional language&amp;#8230;&lt;/p&gt;
&lt;blockquote&gt;&lt;em&gt;[x * x for x in list if x % 2 == 0]&lt;/em&gt;&lt;/blockquote&gt;
&lt;p&gt;And re-write it in LINQ&amp;#8230;&lt;/p&gt;
&lt;blockquote&gt;&lt;em&gt;from x in list where x % 2 == 0 select x * x&lt;/em&gt;&lt;/blockquote&gt;
&lt;p&gt;Do you see it?  It&amp;#8217;s the &lt;strong&gt;exact same thing&lt;/strong&gt;, though perhaps slightly more verbose.  LINQ == List Comprehensions.&lt;/p&gt;
&lt;p&gt;When we talk about LINQtoSQL then, what we&amp;#8217;re really talking about  is &amp;#8220;List Comprehensions to SQL&amp;#8221; which on the surface seems like a really  interesting idea (implementation aside).  LINQtoSQL is basically, given  a data set, can a programmer succinctly express a list comprehension  concept against it, with that concept being rendered into SQL.&lt;/p&gt;
&lt;p&gt;Under the covers LINQ&amp;#8217;s &lt;em&gt;select&lt;/em&gt; is really just the functional Map.  Likewise LINQ&amp;#8217;s &lt;em&gt;aggregate&lt;/em&gt; is  really just Reduce.  Using both of these it&amp;#8217;s possible to write very  functional code, strongly typed, with list comprehensions, &lt;em&gt;in C#&lt;/em&gt;.   The odd part is that all of these excellent pieces were hidden under  the covers of what looked to be a simple SQL-injected-into-C# project.   It&amp;#8217;s not.  It&amp;#8217;s much more than that.&lt;/p&gt;</description><link>http://urlencode.tumblr.com/post/17355926033</link><guid>http://urlencode.tumblr.com/post/17355926033</guid><pubDate>Thu, 09 Feb 2012 20:45:00 -0700</pubDate><category>linq</category><category>c</category><category>haskell</category></item><item><title>Using a Custom Fork on Github with npm/Package.json</title><description>&lt;p&gt;I just learned a really neat trick.  Have you ever had this situation come up:&lt;/p&gt;
&lt;p&gt;You forked a public repo on github of an npm module and made some fixes or changes, but now you want to be able to use your fork in another project, perhaps even on Heroku?&lt;/p&gt;
&lt;p&gt;Here&amp;#8217;s how it&amp;#8217;s done&amp;#8230;&lt;/p&gt;
&lt;p&gt;In the package.json file, replace the version of the npm module with the HTTP address of it&amp;#8217;s github tarball.&lt;/p&gt;
&lt;pre&gt;// Change this:
    ...
    "dependencies": {
       "stylus": "&amp;gt;=0.1.0"
    }

// To this:
    ...
    "dependencies": {
        "stylus": "http://github.com/tstone/stylus/tarball/master"
    }
&lt;/pre&gt;
&lt;p&gt;That&amp;#8217;s it.  Pretty slick huh?&lt;/p&gt;</description><link>http://urlencode.tumblr.com/post/17028783064</link><guid>http://urlencode.tumblr.com/post/17028783064</guid><pubDate>Sat, 04 Feb 2012 06:58:45 -0700</pubDate><category>github</category><category>npm</category><category>heroku</category></item><item><title>In Defense of Vendor-Specific CSS Prefixes</title><description>&lt;p&gt;&lt;a href="http://sitepoint.com"&gt;Sitepoint.com&lt;/a&gt; has been asking recently, &amp;#8220;Should CSS vendor prefixes be abolished?&amp;#8221;  The poll has been running on their front page for the past few days and as of the writing of this post 51% of respondents have said &amp;#8220;Yes&amp;#8221; versus 22% &amp;#8220;No&amp;#8221;.&lt;/p&gt;
&lt;p&gt;I&amp;#8217;m kind of surprised actually.  Likely the majority of respondents are web developers who would rather have the simplicity of typing in a single CSS declaration than 3 or 4 different ones (one for webkit, one for moz, one for IE8, and one for IE&amp;lt;8).  For however tempting of a world that would be with all CSS implementations unified I don&amp;#8217;t think it&amp;#8217;s going to happen.  Furthermore, if there was anything to learn from XHTML isn&amp;#8217;t that theoretical standards don&amp;#8217;t always translate into real world improvements.&lt;/p&gt;
&lt;p&gt;An advantage of vendor-specific CSS prefixes is that it allows an HTML rendering engine vendor to experiment with a style implementation &lt;em&gt;without breaking the implementations other browsers provide&lt;/em&gt;.  Roll back the clock 8 years and this was a pretty big deal.&lt;/p&gt;
&lt;p&gt;Consider, for example, HTML Engine &amp;#8220;A&amp;#8221; decides to implement an experimental CSS prefix &amp;#8220;tween-animation&amp;#8221;.  It allows a developer to implement simple tween animations using CSS&amp;#8230;&lt;/p&gt;
&lt;pre class="brush: css"&gt;.heading { position: absolute; tween-animation: 10px, 10px, 50px, 50px; }&lt;br/&gt;&lt;br/&gt;&lt;/pre&gt;
&lt;p&gt;Mind you this is all hypothetical.  So engine &amp;#8220;A&amp;#8221; implements this and you start using it on your site.  Then later HTML Engine &amp;#8220;B&amp;#8221; also decides to do an implementation, but they decide to implement it differently.  Now what?  Your .heading tween-animation which works in Engine &amp;#8220;A&amp;#8221; now does weird stuff in Engine &amp;#8220;B&amp;#8221; except you have &lt;em&gt;no way to specify that it&amp;#8217;s only for Engine &amp;#8220;A&amp;#8221;&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;Bam.  That&amp;#8217;s where vendor prefixes come in.  Not only does it allow for new CSS experimentations but it does so in a way that won&amp;#8217;t break in the future.&lt;/p&gt;
&lt;p&gt;There are many other good reasons to maintain vendor-specific CSS prefixes.  The &lt;a href="http://blogs.sitepoint.com/2010/11/12/abolish-css-vendor-prefixes/"&gt;discussion happening on the Sitepoint blog&lt;/a&gt; is a good place to start if you&amp;#8217;re interested in more.&lt;/p&gt;</description><link>http://urlencode.tumblr.com/post/1627236901</link><guid>http://urlencode.tumblr.com/post/1627236901</guid><pubDate>Sat, 20 Nov 2010 08:56:00 -0700</pubDate></item><item><title>Converting PNG Images into HTML</title><description>&lt;p&gt;A while back I wrote a short python script to take any PNG image file and convert it into pure HTML.  Yes, pure HTML.&lt;/p&gt;
&lt;p&gt;This actually started as an office joke with the query of how do we put the company logo into emails for people who don&amp;#8217;t have images enabled.  It was a natural downward progression of jokes that eventually lead to converting the image into HTML.  Aaaaaand as any dynamic language programmer in a Microsoft shop I knew I could probably whip up something in an hour or so.&lt;/p&gt;
&lt;p&gt;My first few attempts didn&amp;#8217;t work too well because I actually generated too much HTML.  It seems that after about 2.75MB of HTML, browsers tend to choke and die when rendering it.  So after the first initial hour of getting it to work, the remaining time was spent on compressing the HTML into a manageable portion for the browser.&lt;/p&gt;
&lt;p&gt;The script uses &amp;lt;b&amp;gt; tags to represent rows and &amp;lt;a&amp;gt; tags to represent individual pixels (chosen because they&amp;#8217;re short).&lt;/p&gt;
&lt;p&gt;The script is smart enough to figure out that if two &amp;#8220;pixels&amp;#8221; next to each other are the same color, instead of adding a new &amp;lt;a&amp;gt; tag, it can simply increase the width of the &amp;lt;a&amp;gt; tag to the left.&lt;/p&gt;
&lt;p&gt;Here&amp;#8217;s a rendered sample of the output (using my wedding photo of all things) and you can see the reproduction is very faithful to the original.  The script itself is included below.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://gyazo.com/99a904282edb7cc2607e178b08087f66.png"/&gt;&lt;/p&gt;
&lt;script src="https://gist.github.com/705023.js?file=imgtohtml.py"&gt;&lt;/script&gt;</description><link>http://urlencode.tumblr.com/post/1609764435</link><guid>http://urlencode.tumblr.com/post/1609764435</guid><pubDate>Thu, 18 Nov 2010 07:26:51 -0700</pubDate></item><item><title>Non-Intrusive Javascript Hovers by Convention</title><description>&lt;p&gt;As I&amp;#8217;ve been learning &lt;a href="http://rubyonrails.org/"&gt;Rails&lt;/a&gt; lately, the value of &lt;a href="http://www.google.com/url?sa=t&amp;amp;source=web&amp;amp;cd=1&amp;amp;sqi=2&amp;amp;ved=0CBYQFjAA&amp;amp;url=http%3A%2F%2Fen.wikipedia.org%2Fwiki%2FConvention_over_configuration&amp;amp;ei=LRbfTOOnN8Oclgfc36SdAw&amp;amp;usg=AFQjCNEanUn1HhJxMPMNNPZjHdKHtkDOaQ"&gt;convention-over-configuration&lt;/a&gt; has been becoming more apparent to me.  Here&amp;#8217;s a quick example of how you can use this principle to speed up common tasks in web development.&lt;/p&gt;
&lt;p&gt;For demonstration, let&amp;#8217;s use a really common task:  Making mouse over hover effects.  I&amp;#8217;ll be using &lt;a href="http://jquery.com"&gt;jQuery &lt;/a&gt;but you can use the JS framework of your choice.&lt;/p&gt;
&lt;h5&gt;The Simple Way&lt;/h5&gt;
&lt;p&gt;Each time we want an element to have a hover effect, we need the following code:&lt;/p&gt;
&lt;pre class="brush: css"&gt;/* CSS */
button { font-weight: normal; color: #000; }
button.hover { font-weight: bold; color: #333; }
&lt;/pre&gt;
&lt;pre class="brush: html"&gt;&amp;lt;!-- HTML + Javascript --&amp;gt;
&amp;lt;button id="mybutton"&amp;gt;Click Me!&amp;lt;/button&amp;gt;
&amp;lt;script&amp;gt;
    $('#mybutton').hover( function() {
        $(this).addClass('hover');
    }, function() {
        $(this).removeClass('hover');
    });
&amp;lt;/script&amp;gt;
&lt;/pre&gt;
&lt;p&gt;Sure, that&amp;#8217;s easy enough, but it&amp;#8217;s cumbersome to implement all of that every time, it&amp;#8217;s ugly to have javascript scattered all over your page, and it probably isn&amp;#8217;t resource-efficient if the user has to download that script (however small) every page view.&lt;/p&gt;
&lt;h5&gt;Improving it with a plugin&lt;/h5&gt;
&lt;p&gt;The first thing we could do to reduce effort would be to re-factor our code into a plugin so that it&amp;#8217;s reusable by a single call&amp;#8230;.&lt;/p&gt;
&lt;pre class="brush: js"&gt;$.fn.hoverClass = function(cssClass) {
  $(this).each(function() {
    $(this).hover( function() { $(this).addClass(cssClass); }, function() { $(this).removeClass(cssClass); } );
  });
  return this;
};
&lt;/pre&gt;
&lt;p&gt;This gives us much shorter code when implementing a hover behavior&amp;#8230;&lt;/p&gt;
&lt;pre class="brush: html"&gt;&amp;lt;button id="mybutton"&amp;gt;Click Me!&amp;lt;/button&amp;gt;
&amp;lt;script&amp;gt;
    $('#mybutton').hoverClass('hover');
&amp;lt;/script&amp;gt;
&lt;/pre&gt;
&lt;h5&gt;Introducing a convention&lt;/h5&gt;
&lt;p&gt;So we&amp;#8217;re doing better but we can introduce our first convention-over-configuration here. We can agree with ouselves that &amp;#8220;hover&amp;#8221; will be the default name of the hover class.  This is a good start.  Our hover behavior implementation is getting smaller&amp;#8230;&lt;/p&gt;
&lt;pre class="brush: html"&gt;&amp;lt;button id="mybutton"&amp;gt;Click Me!&amp;lt;/button&amp;gt;
&amp;lt;script&amp;gt;
    $('#mybutton').hoverClass();
&amp;lt;/script&amp;gt;
&lt;/pre&gt;
&lt;p&gt;&amp;#8230;but we&amp;#8217;re still being rather redundant: every time we want to implement the hover behavior we need to call our hoverClass method.  What would be better is if we could simply annotate which elements recieved the behavior.  If we introduce a 2nd convention this can be possible.&lt;/p&gt;
&lt;h5&gt;Annotating elements through markup&lt;/h5&gt;
&lt;p&gt;There are a handful of ways to annotate tags for certain things.  A popular route is to use CSS classes. This is a perfectly plausible route, but I think I&amp;#8217;m going to make use of the new HTML5 data attributes instead. There is an advantage to using them instead which I&amp;#8217;ll show you in a second.&lt;/p&gt;
&lt;p&gt;So let&amp;#8217;s develop a convention for marking tags as the ones we want to have the hover behavior on.  The simplest would be to add an attribute to the tag:  data-hover.&lt;/p&gt;
&lt;pre class="brush: html"&gt;&amp;lt;button id="mybutton" data-hover=""&amp;gt;Click Me!&amp;lt;/button&amp;gt;
&lt;/pre&gt;
&lt;p&gt;With jQuery we can easily find every tag that has this attribute by using wildcard and empty attribute selector &amp;#8220;*[data-hover]&amp;#8221;. Since we&amp;#8217;ve created this convention now, we can activate the plugin to all those elements on DOM ready&amp;#8230;&lt;/p&gt;
&lt;pre class="brush: js"&gt;$.fn.hoverClass = function(cssClass) {
  $(this).each(function() {
    $(this).hover( function() { $(this).addClass(cssClass); }, function() { $(this).removeClass(cssClass); } );
  });
  return this;
};

// On DOM Ready...
$(function(){
  $('*[data-hover]').hoverClass();
});
&lt;/pre&gt;
&lt;p&gt;And with that we&amp;#8217;ve removed the need to have a &amp;lt;script&amp;gt; tag following every element on our page that needs this behavior.  But &lt;em&gt;still&lt;/em&gt; we can improve upon this.  Occasionally we&amp;#8217;ll run into situations where we don&amp;#8217;t want to use the .hover class  to implement the effect but something else.  Here&amp;#8217;s where using HTML5 data attributes vs. CSS class names comes to play.&lt;/p&gt;
&lt;h5&gt;Breaking out of the convention&lt;/h5&gt;
&lt;p&gt;In the data-hover=&amp;#8221;&amp;#8221; attribute we can optionally specify a value.  Using jQuery we can check if that value is available and use that as the hover class instead of &amp;#8216;hover&amp;#8217;&lt;/p&gt;
&lt;pre class="brush: js"&gt;$.fn.hoverClass = function(cssClass) {
  $(this).each(function() {
    $(this).hover( function() { $(this).addClass(cssClass); }, function() { $(this).removeClass(cssClass); } );
  });
  return this;
};

// On DOM Ready...
$(function(){
  $('*[data-hover]').each(function() {
    var hc = $(this).data('hover') || 'hover';
    hoverClass(hc);
  });
});
&lt;/pre&gt;
&lt;p&gt;With this setup you have the choice to take the default or specify a custom hover class&amp;#8230;&lt;/p&gt;
&lt;pre class="brush: html"&gt;&amp;lt;button id="mybutton" data-hover=""&amp;gt;Click Me!&amp;lt;/button&amp;gt; &amp;lt;!-- Take the defaults --&amp;gt;
&amp;lt;button id="mybutton" data-hover="custom-hover"&amp;gt;Click Me!&amp;lt;/button&amp;gt; &amp;lt;!-- Use this class instead --&amp;gt;
&lt;/pre&gt;
&lt;h5&gt;Wrapping up loose ends&lt;/h5&gt;
&lt;p&gt;If you&amp;#8217;ve done a lot of javascript development you may have noticed a shortcoming in the way we&amp;#8217;re approaching this. Our handle little convention runs once on DOM load and never again.  This means if we create new DOM elements after page load or if we have content that&amp;#8217;s loaded through AJAX which contains these data-hover marked elements they won&amp;#8217;t having .hoverClass applied to them.&lt;/p&gt;
&lt;p&gt;There&amp;#8217;s three ways that we can go about fixing this.&lt;/p&gt;
&lt;p&gt;The first is to just call $.hoverClass on any new elements we make.  But the issue here is how do we know which elements to call it on? There&amp;#8217;s a better way&amp;#8230;&lt;/p&gt;
&lt;p&gt;The second way to handle this would be to re-factor our DOM ready code into its own jQuery plugin which we can call at any time.&lt;/p&gt;
&lt;pre class="brush: js"&gt;$.fn.hoverClass = function(cssClass) {
  $(this).each(function() {
    $(this).hover( function() { $(this).addClass(cssClass); }, function() { $(this).removeClass(cssClass); } );
  });
  return this;
};

$.fn.autoHoverClass = function() {
  $('*[data-hover]').each(function() {
    var hc = $(this).data('hover') || 'hover';
    hoverClass(hc);
  });
};

// On DOM Ready...
$(function(){
  $.autoHoverClass();
});
&lt;/pre&gt;
&lt;p&gt;This is a decent route as we retain all &amp;#8220;auto&amp;#8221; functionality but with the ability to refresh the automatic functionalty after we&amp;#8217;ve  changed some page content.  Still yet, jQuery 1.4 provides us with another way&amp;#8230;&lt;/p&gt;
&lt;p&gt;jQuery 1.4 introduced the .live method which I previous mentioned in a blog post.  The .live method is a replacement for .bind  with the exception that it will bind events for all current and &lt;em&gt;future&lt;/em&gt; elements.  It&amp;#8217;s a bit dizzying to imagine how this works  internally, but given a jQuery wrapped set we can make sure the event handler is always &amp;#8220;hooked up&amp;#8221;.&lt;/p&gt;
&lt;p&gt;To do this though requires us to re-factor our code a bit.  For one our code is written to call .each &lt;em&gt;then&lt;/em&gt; to call the event binders.  This is a problem because .each isn&amp;#8217;t updated &amp;#8220;live&amp;#8221;.  The solution is to move the event binding code so that it&amp;#8217;s on the wrapped set then to evaluate the value of data-hover within the event handling code.&lt;/p&gt;
&lt;pre class="brush: js"&gt;$('*[data-hover]').live('mouseover', function() {
  $(this).addClass($(this).data('hover') || 'hover');
});
$('*[data-hover]').live('mouseout', function() {
  $(this).removeClass($(this).data('hover') || 'hover');
});
&lt;/pre&gt;
&lt;p&gt;For simplicity I dropped the jQuery plugin syntax to be clear about exactly what&amp;#8217;s going on.  I&amp;#8217;ve tested doing it this way, and while it does work it can cause noticable browser lag ad whenever new DOM elements are added or removed.  For this particular use-case  I don&amp;#8217;t feel the performance impact warrents what we&amp;#8217;re using it for, but know it is an option.&lt;/p&gt;
&lt;h5&gt;Final code&lt;/h5&gt;
&lt;p&gt;So our final code that we ended up with for hover behavior by convention is&amp;#8230;.&lt;/p&gt;
&lt;pre class="brush: js"&gt;// separate-js-file.js
$.fn.hoverClass = function(cssClass) {
  $(this).each(function() {
    $(this).hover( function() { $(this).addClass(cssClass); }, function() { $(this).removeClass(cssClass); } );
  });
  return this;
};

$.fn.autoHoverClass = function() {
  $('*[data-hover]').each(function() {
    var hc = $(this).data('hover') || 'hover';
    hoverClass(hc);
  });
};

// On DOM Ready...
$(function(){
  $.autoHoverClass();
});
&lt;/pre&gt;
&lt;pre class="brush: html"&gt;&amp;lt;!-- In your markup --&amp;gt;
&amp;lt;button id="mybutton" data-hover=""&amp;gt;Click Me!&amp;lt;/button&amp;gt;
&lt;/pre&gt;</description><link>http://urlencode.tumblr.com/post/1596361686</link><guid>http://urlencode.tumblr.com/post/1596361686</guid><pubDate>Tue, 16 Nov 2010 19:48:00 -0700</pubDate></item><item><title>Why Writing a Webapp Reminds me of Playing a RPG</title><description>&lt;p&gt;I&amp;#8217;m sure you&amp;#8217;ve played an RPG of some sort&amp;#8230; Diablo, Torchlight, Titan&amp;#8217;s Quest, City of Heroes, World of Warcraft, Pirates of the Burning Sea, Aion, Eve Online, Dark Age of Camelot, Age of Conan, etc.  These all invariably involve the same pattern of gameplay.&lt;/p&gt;

&lt;p&gt;You design a character &amp;#8212; it&amp;#8217;s gender, appearance, skin tone, and of course role/class.  You enter the world, simple and weak, using the same basic skills to accomplish every task.  As you grown in experience you begin to use more tools to accomplish the same tasks.  In the &amp;#8220;middle&amp;#8221; portion of this experience, between when you first created the character and the maximum level is probably the highlight of playing:  You&amp;#8217;re progressing at a very notable pace, you frequently receive gear upgrades and new skills, and the sense of accomplishment is very high.  As you start to near level cap the &amp;#8220;newness&amp;#8221; begins to wear off: you only receive more powerful versions of the spells you already had.  There isn&amp;#8217;t anything new, just bigger numbers.  Hitting level cap the sense of accomplishment trails off very fast.  The only progression left is to try to acquire more and more esoteric pieces of gear/upgrades.  The time between those upgrades becomes farther and farther apart as more time investment is required to attain them.&lt;/p&gt;

&lt;p&gt;I see a lot of similarities with writing a webapp.  You start off designing your technology stack &amp;#8212; it&amp;#8217;s web server, server framework, client framework, and of course language.  You write your first few lines of code, simple and weak, using the same basic patterns that you read in the &amp;#8220;Getting Started in X Web Framework&amp;#8221; tutorial.  As you grow in expirience, reading more Stack Overflow answers you begin to use more refined tools to accomplish the same tasks in ways you&amp;#8217;d label &amp;#8220;better architected&amp;#8221; or &amp;#8220;more scalable&amp;#8221;.  In the &amp;#8220;middle&amp;#8221; portion of this new webapp when you hit Minimum Viable Product is probably the highlight of the webapp:  You&amp;#8217;re progressing at a very notable pace, you frequently add new features and upgrades to existing ones, and the sense of accomplishment is very high.  As you start to near completion where all of the features have been implemented the &amp;#8220;newness&amp;#8221; begins to wear off:  You&amp;#8217;re only refining existing features now, making small slight changes and tweaks here and there.    The only progression left begins to render very small changes.  A 0.5% improvement here, a 0.75% iimprovement there.  The time between &amp;#8220;upgrades&amp;#8221; becomes farther and father apart as more people begin to use your webapp and you risk upsetting people&amp;#8217;s workflow by changing too much.  The excitement and passion is slowly draining.&lt;/p&gt;

&lt;p&gt;At this point what happens?  Well in an RPG you&amp;#8217;d either re-roll a new character or switch to another game. In webapp development you&amp;#8217;d either &amp;#8220;re-roll&amp;#8221; the projects by re-writing huge portions of it in the latest language or framework.  Or you&amp;#8217;d switch to another &amp;#8220;game&amp;#8221; (a different project).&lt;/p&gt;
&lt;p&gt;I think this is somewhat of a problem but I&amp;#8217;m not sure what the fix is.  Is there a way to keep excitement, newness, and a sense of accomplishment on a well establish project?  If so how?&lt;/p&gt;</description><link>http://urlencode.tumblr.com/post/1508748352</link><guid>http://urlencode.tumblr.com/post/1508748352</guid><pubDate>Sun, 07 Nov 2010 12:54:44 -0700</pubDate></item><item><title>Blekko &amp; Google: A Quick Study in Color Contrast</title><description>&lt;p&gt;&lt;a href="http://blekko.com/"&gt;Blekko&lt;/a&gt; recently launched with much &lt;a href="http://www.marksonland.com/2010/11/blekkos_launch_rocked_10_thoug.html"&gt;fanfare&lt;/a&gt;.  There hasn&amp;#8217;t been much change in the search engine world recently so I imagine a flood of early adopters will give them a steady flow of traffic for sometime.  Being a techy and web developer myself I &lt;em&gt;&lt;strong&gt;of course&lt;/strong&gt;&lt;/em&gt; wanted to hop on the bandwagon early on.&lt;/p&gt;
&lt;p&gt;However within just the first day I began to feel like Blekko was &amp;#8220;harder&amp;#8221; to use.  That sounds silly right &amp;#8212; it looks and works almost identical to Google.  I couldn&amp;#8217;t quite put my finger on it but the search results page felt undecipherable if I was just scanning it.  With Blekko search results I felt forced to read each result individually.&lt;/p&gt;
&lt;p&gt;So curious I compared Google and Blekko side by side.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://lh3.ggpht.com/_epp24QszXwI/TNCrKoT0xhI/AAAAAAAAALc/Jx5EsSHjRB0/s1024/blekko-google.jpg" width="1024"/&gt;&lt;/p&gt;
&lt;p&gt;They look almost identical: Blekko is red, Google is blue.  How hard can it be?&lt;/p&gt;
&lt;p&gt;But after further use what I began to notice was that I had a harder time scanning the &lt;em&gt;titles&lt;/em&gt; of the search results.  Apparently over the years I&amp;#8217;ve developed a habit of just scanning the titles and completely skipping the summary, unless of course the title is of interest.&lt;/p&gt;
&lt;p&gt;When it comes to Blekko, this is how it feels to me&amp;#8230;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://lh3.ggpht.com/_epp24QszXwI/TNCrKgjcF0I/AAAAAAAAALg/rXzwHs6Fox4/s1024/blekko-google-see.jpg" width="1024"/&gt;&lt;/p&gt;
&lt;p&gt;The interesting thing is that I think this is simply an issue of the contrast relationship between the title and the tools/links under it.&lt;/p&gt;
&lt;p&gt;Here&amp;#8217;s an example of what I mean.  If everything was to remain constant except the links below the title, the ability to scan the result titles becomes increasingly easier.&lt;/p&gt;
&lt;p&gt;Try scanning these two and quickly reading just the titles.  Which is more comfortable on your eyes?&lt;/p&gt;
&lt;p&gt;&lt;img src="http://lh5.ggpht.com/_epp24QszXwI/TNCvU5K9poI/AAAAAAAAALs/J-b94sasnpU/blekko-befafter.jpg"/&gt;&lt;/p&gt;</description><link>http://urlencode.tumblr.com/post/1466081980</link><guid>http://urlencode.tumblr.com/post/1466081980</guid><pubDate>Tue, 02 Nov 2010 18:34:00 -0600</pubDate></item><item><title>Is the Golden Age of Django Over? [Opinion]</title><description>&lt;p&gt;To me Django was &lt;em&gt;&lt;strong&gt;revolutionary&lt;/strong&gt;&lt;/em&gt;.  Sure there were many more frameworks who came before it, but for those of us who didn&amp;#8217;t care for the scaffolding-command-line-driven style Ruby On Rails offered, Django was a breath of fresh air to the otherwise tedious task of web development.  Django had so much going for it&amp;#8230;&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;Tons of features&lt;/li&gt;
&lt;li&gt;Built on python&lt;/li&gt;
&lt;li&gt;A positive and helpful community&lt;/li&gt;
&lt;li&gt;Good documentation&lt;/li&gt;
&lt;li&gt;Very easy-to-use ORM&lt;/li&gt;
&lt;li&gt;and so on&lt;/li&gt;
&lt;/ul&gt;&lt;p&gt;I spent about a year and a half learning and using Django, enough so to earn the &lt;a href="http://stackoverflow.com/badges/362/django?userid=111375"&gt;Django Badge&lt;/a&gt; and be in the &lt;a href="http://stackoverflow.com/tags/django/topusers"&gt;top 20 answerers&lt;/a&gt; for the django tag on &lt;a href="http://www.stackoverflow.com"&gt;StackOverflow&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Aside from the general technical benefits that Django brought to many, it was personally quite revolutionary for me.  A brief bit of history here if you would entertain me.&lt;/p&gt;
&lt;p&gt;A few years ago I was in an interesting point in my career where I really needed to start seriously pursuing if I wanted to be a web developer/user interface guy or if I wanted to be a graphic designer/marketer.  My web development career had initially kicked off with classic ASP and various ill designed apps which naturally led to .NET and C#.  However my day job was largely design and marketing.&lt;/p&gt;
&lt;p&gt;Those were the days web development was weary work.  Some still used HTML tables because CSS layouts were slightly broken in a handful of browsers.  AJAX was just starting to become buzz-y and the phrase &amp;#8220;web two point oh&amp;#8221; was being incubated in journalists minds.&lt;/p&gt;
&lt;p&gt;I had found that the majority of my web development tasks were concentrated on boilerplate and infrastructure.  I considered a future in such monotony wasn&amp;#8217;t looking enjoyable and was questioning my web development role.&lt;/p&gt;
&lt;p&gt;Unknowing to myself I had actually created a mini-web framework very similar to Django in C# for .NET.  I had all the things you&amp;#8217;d expect: a templating engine, an HTML forms engine, and a data layer that abstracted a decent portion of the underlying SQL away.  I spent most of my time trying to keep this up and it really slowed real progress on the website I was working on.&lt;/p&gt;
&lt;p&gt;Humorously, it was actually the announcement of ASP.NET MVC that lead me to Django.  You see after learning the general principals of MVC I realized something I should have already known:  The entire internet was trying to deal with these same issues.  I&amp;#8217;m sure it surprised others too.  It&amp;#8217;s a lesson you don&amp;#8217;t learn in school.  Shortly there after that I set out to find a language which provided a vast array of libraries that I could use to free up development time to actually focus on domain problems and not supporting thousands of lines of libraries.&lt;/p&gt;
&lt;p&gt;This lead me to Python &amp;#8212; And who was the knock-out web framework for Python at the time?  None other than Django.  Some called it &amp;#8220;Python&amp;#8217;s answer to Rails&amp;#8221;.  This was back before Django and pink ponies were synonymous.&lt;/p&gt;
&lt;p&gt;I learned Django in 2 days (went through every chapter in the &lt;a href="http://djangobook.com"&gt;Django Book&lt;/a&gt;) and was just totally blown away.  For the next year and a half everything I did web-related was in Django, including a rather large website and a handful of Django &lt;a href="http://github.com/tstone/django-uploadify"&gt;reusable apps&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;In a sense Django was my training wheels to thinking about web development in an abstract, separated, and well defined way.  Django didn&amp;#8217;t just team me MVC &amp;#8212; it got me thinking about how websites are architected.  Once I realized there was an entire ecosystem of web application frameworks I was like a kid in a candy story; &lt;a href="http://pylonshq.com/"&gt;Pylons&lt;/a&gt;, &lt;a href="http://werkzeug.pocoo.org/"&gt;Werkzeug&lt;/a&gt;, &lt;a href="http://www.sinatrarb.com/"&gt;Sinatra&lt;/a&gt;, &lt;a href="http://merbivore.com/"&gt;Merb&lt;/a&gt;, &lt;a href="http://www.gadgetopia.com/post/6886"&gt;Seaside&lt;/a&gt;, &lt;a href="http://liftweb.net/"&gt;Lift&lt;/a&gt;, &lt;a href="http://flask.pocoo.org/#"&gt;Flask&lt;/a&gt;, and most recently &lt;a href="http://www.tornadoweb.org/"&gt;Tornado&lt;/a&gt;.  I wanted to learn them &lt;em&gt;all&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;In my eyes Django was revolutionary, but it wasn&amp;#8217;t without it&amp;#8217;s issues &amp;#8212; most of which I could happily overlook.  It seems though that in the wake of Django&amp;#8217;s success literally hundreds of web app frameworks, many written in Python, have followed offering potential developers a certain take on how web development should be done.&lt;/p&gt;
&lt;p&gt;Receiving a slight bit of internet buzz recently, &lt;a href="http://stackoverflow.com/questions/2665313/python-framework-for-small-website/2665345#2665345"&gt;Alex Martelli recently recommended Flask&lt;/a&gt; (based on Werkzeug) over Django for personal projects.&lt;/p&gt;
&lt;p&gt;Today it seems there is such a choice of frameworks that it&amp;#8217;s highly unlikely that one would not find something they like which is specialized to their development style or project.  However in the jungle of choice I&amp;#8217;m wondering [out loud] if Django is being left behind as the large-one-size-fits-all that no one feels fits them like more specialized frameworks do.&lt;/p&gt;
&lt;p&gt;In some sense we knew it was coming; no technology lasts forever.  In another sense it seems like Django&amp;#8217;s time in the spotlight was too short lived.  Was it that Django included so much (batteries included) and the web changes so fast that it can&amp;#8217;t keep up?  Is it that Django&amp;#8217;s broad focus lends itself only to projects that fit it specifically?  Is it that the technical innovation of &amp;#8220;competing&amp;#8221; frameworks give developers enough of an edge for them to switch?  Is it just that developers have an insatiable appetite to use the latest and greatest, even if the previous worked just fine?&lt;/p&gt;
&lt;p&gt;Is the Golden Age of Django over?&lt;/p&gt;</description><link>http://urlencode.tumblr.com/post/1457773229</link><guid>http://urlencode.tumblr.com/post/1457773229</guid><pubDate>Mon, 01 Nov 2010 19:54:00 -0600</pubDate></item><item><title>Why Using the AJAX Spinny Wheel Is Bad [Opinion]</title><description>&lt;p&gt;Alright that was a tricky title just to get you to read the first line.&lt;/p&gt;
&lt;p&gt;Twelves years ago when I made my first website on AOL&amp;#8217;s &amp;#8220;MyPlace&amp;#8221; I copied some javascript I found out there on the internet somewhere to try and make a hover effect for my &amp;#8220;personal webpage&amp;#8221;.&lt;/p&gt;
&lt;p&gt;Why?  Because it &lt;em&gt;looked cool&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;A few years later I was implementing DHTML page transitions.&lt;/p&gt;
&lt;p&gt;Why?  Because it &lt;em&gt;looked cool&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;A few months ago I was sticking that stupid AJAX spinny wheel on everything.&lt;/p&gt;
&lt;p&gt;Why?  Because it &lt;em&gt;looked cool&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;Just like javascript hover effects and DHTML page transitions maybe it&amp;#8217;s time to stop and think about what we&amp;#8217;re doing with AJAX.  To be fair the actual AJAX spinny wheel itself isn&amp;#8217;t bad in and of itself.  Giving visual feedback to the user to indicate something is happening is always a good choice.&lt;/p&gt;
&lt;p&gt;However I&amp;#8217;ve started to notice that whenever I find myself reaching for the AJAX spinny wheel I need to really take a long and hard look at what I&amp;#8217;m doing.  In the majority of cases the AJAX spinny wheel indicates that I am &lt;strong&gt;&lt;em&gt;replicating browser functionality&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Unless there is really a specific benefit that can be gained by doing this it almost always ends up bad.  In the past few months I&amp;#8217;ve actually had a couple of projects I was working on where the interface had been written in AJAX and I ended up un-ajaxifying the UI because not only did the AJAX UI not add value but it was restrictive and removed default browser functionality.&lt;/p&gt;
&lt;p&gt;AJAX often brings problems like&amp;#8230;&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;Non-standard interfaces and interface elements&lt;/li&gt;
&lt;li&gt;Reduced browser default functionality* (history, back/forward buttons, etc.)&lt;/li&gt;
&lt;li&gt;Unnecessary lag via animation effects often implemented to display AJAX content changes&lt;/li&gt;
&lt;li&gt;Reduced SEO*&lt;/li&gt;
&lt;/ul&gt;&lt;p&gt;&lt;em&gt;* - Yes I know there are efforts on these fronts to improve this, but still.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The fact still remains that the majority of times end users would rather have a predictable, usable, and effective website experience than to have a glittery, effects-filled one&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;It&amp;#8217;s sad.  I know.  I just re-read that to myself and it was more sad the second time.  Being half designer this pains me even more.&lt;/p&gt;
&lt;p&gt;Eric Ries (on the topics of A/B testing websites) says it well: &amp;#8220;&lt;em&gt;&amp;#8230;this led us to confront the disappointing reality that sometimes customers actually prefer an uglier design to a pretty one&amp;#8230;&lt;/em&gt;&amp;#8221;&lt;br/&gt;[&lt;a href="http://www.startuplessonslearned.com/2008/09/one-line-split-test-or-how-to-ab-all.html"&gt;The one line split-test, or how to A/B all the time, Sep 15, 2008&lt;/a&gt;].&lt;/p&gt;
&lt;p&gt;The next time you reach for the AJAX spinny wheel ask if you&amp;#8217;re really adding efficiency to your webapp or if you&amp;#8217;re just sprinkling unnecessary glitter.&lt;/p&gt;</description><link>http://urlencode.tumblr.com/post/1428511300</link><guid>http://urlencode.tumblr.com/post/1428511300</guid><pubDate>Thu, 28 Oct 2010 20:52:07 -0600</pubDate><category>ajax</category><category>webapp</category><category>development</category><category>stufftothinkabout</category></item><item><title>3 Cool Jquery Tricks I've Been Using Lately</title><description>&lt;p&gt;Everyone loves jQuery.  Ok maybe not everyone, but at least a huge portion of the internet.  It&amp;#8217;s likely because jQuery implements the DOM very similar to how it should have been implemented in the first place (but we won&amp;#8217;t beat that dead LiveScript horse anymore).&lt;/p&gt;
&lt;p&gt;Anyways, here are some cool tricks that I&amp;#8217;ve learned, used, or been using lately&amp;#8230;&lt;/p&gt;
&lt;h2&gt;1. Use .live for binding events on elements not yet created&lt;/h2&gt;
&lt;p&gt;It&amp;#8217;s common to write jQuery code that creates new DOM elements or shuffles them around.  What&amp;#8217;s not cool is to try to wire-up events up to those new or shuffled elements, especially when you don&amp;#8217;t know if they&amp;#8217;ve previously had event handlers attached to them.  I often found myself doing things like this&amp;#8230;&lt;/p&gt;
&lt;pre class="brush: jscript"&gt;var bindTagEvents = function(tag) {
    $(tag).unbind().click(function(){
       // foo 
    });
}

// ...

span = $('&lt;span&gt;').attr('title','My New Span');
$('body').append(span);
bindTagEvents(span);
&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;Note the &lt;em&gt;&lt;strong&gt;unbind()&lt;/strong&gt;&lt;/em&gt; before the &lt;em&gt;&lt;strong&gt;click()&lt;/strong&gt;&lt;/em&gt;.  Yeah it works, but jQuery provides the .live function which works for all elements current and &lt;em&gt;future&lt;/em&gt;.  This means even if we were to create that new span tag and append it to the &amp;lt;body&amp;gt; tag, the .live function would still apply it.  Using .live, we can shorten the example above down to&amp;#8230;&lt;/p&gt;
&lt;pre class="brush: jscript"&gt;$('body &amp;gt; span').live('click', function() {
    // foo
});

// ...

span = $('&lt;span&gt;').attr('title','My New Span');
$('body').append(span);
&lt;/span&gt;&lt;/pre&gt;
&lt;h2&gt;2. Draw attention to newly created elements using the highlight effect&lt;/h2&gt;
&lt;p&gt;Again it&amp;#8217;s common to create new elements in our jQuery scripts but one thing to be concerned with is how it will feel to the user.  Often times the addition of new content is subtle enough that users won&amp;#8217;t notice, even if we the developers do.&lt;/p&gt;
&lt;p&gt;JQuery UI provides an effect known as &amp;#8220;Highlight&amp;#8221; which when fired causes the element to briefly pulse in a yellow &amp;#8220;highlighter&amp;#8221; color, hopefully drawing attention to it.&lt;/p&gt;
&lt;p&gt;Implementing it is ridiculously easy:&lt;/p&gt;
&lt;pre class="brush: jscript"&gt;$(tag).effect('highlight', {}, 1500);
&lt;/pre&gt;
&lt;p&gt;The 3rd argument is the length &amp;#8212; in milliseconds &amp;#8212; that the yellow highlight color should fade out with.  It sounds like an obnoxious effect but it provides a subtle visual cue for users that a new element has been created.&lt;/p&gt;
&lt;h2&gt;3. jQuery Includes an Auto-Complete Feature&lt;/h2&gt;
&lt;p&gt;No kidding.  Like the highlight effect mentioned above, this feature requires the jquery-ui library, not just jquery ala-carte.  To be fair, there are many autocomplete implementations that have more features, but if jquery-ui is already included on your page why add another dependency (unless of course you really need that killer feature).&lt;/p&gt;
&lt;p&gt;Autocomplete takes a couple of properties and handles most of the plumbing of what it takes to make an autocomplete/autosuggest system.  When activated on an input:text, the only thing it really needs is a datasource.&lt;/p&gt;
&lt;pre class="brush: jscript"&gt;// Any array will do...
$('input').autocomplete({
    source: ['batman', 'robin', 'joker', 'catwoman', 'dr. freeze', 'penguin']
});

// Or URL of a custom page that returns an array in JSON format...
$('input').autocomplete({
    source: 'yoursite.com/api/autocomplete'
});

// Or a callback (to implement basic caching perhaps)...
var $autoCompleteCache = {};
$('input').autocomplete({
    source: function(query, addOptions) {
        if ($autoCompleteCache.hasOwnProperty(query)) {
            addOptions($autoCompleteCache[query]);
            return;
        }
        else {
            $.getJSON(
                'yoursite.com/api/autocomplete',
                function(data) {
                    $autoCompleteCache[query] = data;
                    addOptions(data);
                }
            )
        }
    }
});&lt;/pre&gt;</description><link>http://urlencode.tumblr.com/post/1121365653</link><guid>http://urlencode.tumblr.com/post/1121365653</guid><pubDate>Tue, 14 Sep 2010 10:00:00 -0600</pubDate><category>jquery</category><category>javascript</category></item><item><title>Bookmarks Are Dead</title><description>&lt;p&gt;At least to me.  I noticed the other day that I almost &lt;em&gt;never&lt;/em&gt; use bookmarks anymore.  A year or two ago I was a bookmark junky, having 500+ easily.  So what changed?  In reflecting upon it, I think there are a few reasons for this&amp;#8230;&lt;/p&gt;
&lt;ol&gt;&lt;li&gt;I switched to using Chrome whenever I&amp;#8217;m not doing web development (Firebug is just too awesome to give up).  The way Chrome is designed the bookmarks aren&amp;#8217;t exactly a prime, in-your-face feature which are easily accessible &amp;#8212; at least not in the way Firefox and Internet Explorer implement it. &lt;/li&gt;
&lt;li&gt;I use Twitter much more than I did in past years.  A lot (and by lot I&amp;#8217;d say 50% at least) of the &lt;strong&gt;new&lt;/strong&gt; sites I visit are from links seen on Twitter.  I follow people who tweet about topics I&amp;#8217;m interested in (&lt;a href="http://twitter.com/smashingmag"&gt;@smashingmag&lt;/a&gt;, &lt;a href="http://twitter.com/sixrevisions"&gt;@sixrevisions&lt;/a&gt;, &lt;a href="http://twitter.com/ActiveState"&gt;@activestate&lt;/a&gt;, &lt;a href="http://twitter.com/cssbeauty"&gt;@cssbeauty&lt;/a&gt;, &lt;a href="http://twitter.com/usejquery"&gt;@usejquery&lt;/a&gt;) and thus click a lot of links that are posted.&lt;/li&gt;
&lt;li&gt;Instead of &amp;#8220;surfing the web&amp;#8221; looking for new sites, as was all the rage in the 90&amp;#8217;s, I tend to frequent the same sites, often times which serve in some part as content aggregation &amp;#8212; and I already know their address.  Why do I need to bookmark it?&lt;/li&gt;
&lt;li&gt;Chrome Pinned Tabs &amp;#8212; Sites I &lt;em&gt;really&lt;/em&gt; frequent have a permanent Chrome tab to keep them open.&lt;/li&gt;
&lt;li&gt;Chrome Address Bar &amp;#8212; Why waste the time to find a bookmark when you can just type something relatively close to what you want into the address bar and get instant results?&lt;/li&gt;
&lt;/ol&gt;&lt;p&gt;&lt;em&gt;(Why are 3 of the 5 related to Chrome?  Google conspiracy theories ignite&amp;#8230;)&lt;/em&gt;&lt;/p&gt;</description><link>http://urlencode.tumblr.com/post/1119305152</link><guid>http://urlencode.tumblr.com/post/1119305152</guid><pubDate>Mon, 13 Sep 2010 22:40:00 -0600</pubDate><category>google</category><category>random</category></item><item><title>5 Reasons to Consider Tornado for AppEngine (Python)</title><description>&lt;p&gt;As I&amp;#8217;ve begun to become better acquainted with &lt;a href="http://code.google.com/appengine/"&gt;Google&amp;#8217;s AppEngine platform&lt;/a&gt;, I&amp;#8217;ve hit a few points where the python-based &lt;a href="http://code.google.com/appengine/docs/python/.../usingwebapp.html"&gt;&amp;#8220;webapp&amp;#8221; framework&lt;/a&gt; is less than desirable.&lt;/p&gt;
&lt;p&gt;While I have a background in &lt;a href="http://www.django.com"&gt;Django&lt;/a&gt;, I didn&amp;#8217;t feel as if it was a fit for AppEngine due to it&amp;#8217;s heavy data layer ties.  On the flip side, &lt;a href="http://www.tornadoweb.org/"&gt;Tornado&lt;/a&gt; (IMHO) is a lightweight alternative and prime candidate.&lt;/p&gt;
&lt;p&gt;Tornado, if you don&amp;#8217;t know, is the web framework that powers FriendFeed and was recently open sourced by Facebook.  It includes the basics you&amp;#8217;d expect: request handling, routing, templating; you know, the usual fare.  A scatter of MySQL utilities come bundled, but the framework leaves the data layer completely up to you (consequently it doesn&amp;#8217;t including features like an automatic administrative interface or data models-to-web forms).&lt;/p&gt;
&lt;h2&gt;1.  May the Source Be With You&lt;/h2&gt;
&lt;p&gt;Sure, webapp has &lt;a href="http://code.google.com/appengine/docs/python/gettingstarted/usingwebapp.html"&gt;online documentation&lt;/a&gt;, but sometimes it&amp;#8217;s easier to just &lt;a href="http://github.com/facebook/tornado/tree/master/tornado/"&gt;read the source&lt;/a&gt;.  Even better, in Tornado&amp;#8217;s case it&amp;#8217;s available via GitHub.&lt;/p&gt;
&lt;p&gt;Depending on your experience with python this might not &lt;em&gt;sound &lt;/em&gt;like a compelling reason but consider this: You will likely have the tornado source folder inside of your project&amp;#8217;s folder while developing (as it needs to be deployed to AppEngine with the rest of your python source files).  This means you can simply open up the Tornado source files in another tab in your editor for quick reference.&lt;/p&gt;
&lt;p&gt;Once you get used to doing this it greatly speeds up your development time when you need to reference something and it gets you much more acquainted with how the framework works.&lt;/p&gt;
&lt;h2&gt;2.  Simple Templating&lt;/h2&gt;
&lt;p&gt;There are quite a few good templating engines out there for python. The problem I have with many of them is that they typically are too complicated or unnatural in syntax or too restrictive for in form, particularly when it comes to creating re-usable sub-templates which manage their own logic and data independent of the main page (I&amp;#8217;m referring to what Django and other engines call &amp;#8220;template tags&amp;#8221;).&lt;/p&gt;
&lt;p&gt;Before I mention tags a few words about the Tornado template engine &amp;#8212; it&amp;#8217;s simple.  It uses the common {% %} format.  It lets you put real python in between the {% %}&amp;#8217;s   Sure, people say logic should be out of the template, however if it&amp;#8217;s logic that relates to display I disagree.  Tornado gives you the choice.  If you want it, use it.  If not, do it the hard way.  It&amp;#8217;s up to you.&lt;/p&gt;
&lt;p&gt;Behind the scenes Tornado compiles the templates to a python file to make them speedy when serving to viewers (this has the odd side effect of requiring you to restart the appengine dev server whenever you change the template).&lt;/p&gt;
&lt;p&gt;The one slip up is that if you, like me, are used to Django-style templates, you&amp;#8217;ll probably write things like &amp;#8220;{% endblock %}&amp;#8221; or &amp;#8220;{% endif %}&amp;#8221;.  Tornado simply uses &amp;#8220;{% end %}&amp;#8221; for everything.&lt;/p&gt;
&lt;h2&gt;3. Drop-Dead Easy Template Tags&lt;/h2&gt;
&lt;p&gt;So about template tags, Tornado refers to them as &amp;#8220;UI modules&amp;#8221;.  Defining a new module is dead simple&amp;#8230;&lt;/p&gt;
&lt;pre class="brush: python"&gt;class SchemePreviewSmall(BaseUIModule):
    def render(self, scheme, lang='python'):
        data = self.handler.data.get_something_cool(scheme)
        return self.render_string('modules/scheme-preview-small.html',
                                  scheme=data,
                                  lang=lang)
&lt;/pre&gt;
&lt;p&gt;In this example I&amp;#8217;m calling the method &lt;em&gt;get_something_cool&lt;/em&gt; which is actually a member of the calling RequestHandler (self.handler).  The return value is then used to generate the response by loading and rendering a template.  The nice thing here is that if I have a re-usable widget such as an ad, a login interface, whatever I can make it a module and re-use it throughout the site.&lt;/p&gt;
&lt;p&gt;Using this module in a template is as easy as&amp;#8230;&lt;/p&gt;
&lt;pre class="brush: python"&gt;{{ modules.SchemePreviewSmall(scheme) }}
&lt;/pre&gt;
&lt;h2&gt;4. Easy to follow documentation&lt;/h2&gt;
&lt;p&gt;Yes, if the source isn&amp;#8217;t you thing, there still is &lt;a href="http://www.tornadoweb.org/documentation"&gt;easy-to-follow documentation&lt;/a&gt;.  There&amp;#8217;s enough there to get you up and running in an evening and you&amp;#8217;ll learn a lot of cool tricks too.&lt;/p&gt;
&lt;h2&gt;5.  Minimal to Convert&lt;/h2&gt;
&lt;p&gt;Lastly, the webapp and Tornado syntax for request handlers are so similar, converting to Tornado from webapp requires minimal effort.&lt;/p&gt;
&lt;h3&gt;webapp Request Handler&lt;/h3&gt;
&lt;pre class="brush: python"&gt;class HelloWorld(webapp.RequestHandler):
    def get(self):
        self.write("Hello World")

&lt;/pre&gt;
&lt;h3&gt;Tornado Request Handler&lt;/h3&gt;
&lt;pre class="brush: python"&gt;class HelloWorld(tornado.web.RequestHandler):
    def get(self):
        self.write("Hello World")

&lt;/pre&gt;
&lt;p&gt;There are, of course, a few other differences.  For example, fetching the value of a querystring. Webapp uses &lt;em&gt;self.request.get()&lt;/em&gt; while Tornado instead does &lt;em&gt;self.get_argument()&lt;/em&gt;.  The differences are minor and easily done with Find and Replace.&lt;/p&gt;</description><link>http://urlencode.tumblr.com/post/1095299258</link><guid>http://urlencode.tumblr.com/post/1095299258</guid><pubDate>Thu, 09 Sep 2010 21:42:00 -0600</pubDate><category>python</category><category>webapp</category><category>appengine</category><category>tornado</category></item><item><title>Restoring Browser Functions to Clickable DIVs Without Javascript</title><description>&lt;p&gt;Occasionally the situation comes up in web development where you have a highly styled tag such as &lt;br/&gt;&amp;lt;div&amp;gt; or &amp;lt;li&amp;gt; that you want to make clickable.  This often happens when you have a list of items in which you want to make the entire item clickble instead of just the title for example.  The standard fare for doing so is to set { cursor: pointer; } with CSS then to bind the .click event to the tag (in jQuery as so)&amp;#8230;.&lt;/p&gt;
&lt;pre class="brush: jscript"&gt;$('#myDivTag').click(function() {
    // your code here
});
&lt;/pre&gt;
&lt;p&gt;Don&amp;#8217;t get me wrong &amp;#8212; this does work.  However, in doing this what you loose is the standard functionality that most viewers are used to; things like middle clicking to open in a new tab, right-click to copy URL address, and so on.  There is also the lag between when the page renders visibly to the user but the javascript hasn&amp;#8217;t downloaded and $(document).ready hasn&amp;#8217;t yet fired.  In this case the tag will not be clickable but the mouse cursor will indicate that it should be.&lt;/p&gt;
&lt;p&gt;&lt;br/&gt;I&amp;#8217;ve been dealing with this more so lately and there are a couple of ways to solve this problem.&lt;br/&gt;&lt;br/&gt;The first is to wrap the &amp;lt;div&amp;gt; (or li or whatever else) tag in an anchor tag &amp;lt;a&amp;gt; and set that anchor tag to { display: block; }.&lt;/p&gt;
&lt;pre class="brush: xml"&gt;&amp;lt;style type="text/css"&amp;gt;
	#myDivWrapper { display: block; }
	#myDiv {  }
&amp;lt;/style&amp;gt;

&amp;lt;a id="myDivWrapper"&amp;gt;
	&amp;lt;div id="myDiv"&amp;gt;
	       ... content ...
	&amp;lt;/div&amp;gt;
&amp;lt;/a&amp;gt;
&lt;/pre&gt;
&lt;p&gt;By wrapping the div tag in an anchor you&amp;#8217;ve restored the default functionality viewers are used to with a clickable item.  This works in most browsers but for the most part things like &amp;lt;div&amp;gt; and &amp;lt;li&amp;gt; are not allowed inside of an anchor tag per HTML language specifications.  In a sense in doing something like this you are rolling the dice that the next version of IE9 strict mode won&amp;#8217;t render when it hits this.&lt;/p&gt;
&lt;p&gt;It also feels kind of  weird, because all of the styling that was on #myDiv, things like height, width, float, etc., now need to be applied to the anchor tag instead.  And no one likes wrappers. They just clutter things up.&lt;br/&gt;&lt;br/&gt;The 2nd way to solve this problem which I&amp;#8217;ve started using lately is to have an absolutely positioned anchor overlay the area of the div.  Consider the following&amp;#8230;&lt;/p&gt;
&lt;pre class="brush: xml"&gt;&amp;lt;style type="text/css"&amp;gt;
    #myDiv { position: relative; }
    a.clickable-overlay {
        position: absolute;
        top: 0;
        left: 0;
        height: 100%;
        width: 100%;
        z-index: 1;
        display: block;
        background-color: transparent;
    }
&amp;lt;/style&amp;gt;

&amp;lt;div id="myDiv"&amp;gt;
    ... content ...
    &amp;lt;a class="clickable-overlay" href="#wherever"&amp;gt;&amp;lt;/a&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/pre&gt;
&lt;p&gt;Here&amp;#8217;s what&amp;#8217;s happening:  At the end of the &amp;lt;div&amp;gt; (or li or whatever) we&amp;#8217;re adding an anchor tag.  The parent div is set to { position: relative }, and the anchor tag to { position: absolute; }.  If you&amp;#8217;re not familiar with position absolute you&amp;#8217;re missing out.  The way it is designed to work is that any element positioned absolutely is done so in relation to it&amp;#8217;s parent (or any parent&amp;#8217;s parent) that is positioned either relatively or absolutely.  What this means is that in setting our &amp;lt;div&amp;gt; tag to position: relative the anchor tag with position absolute will be positioned relative to the div.  Top 0 and left 0 will be the top left of the div,  and height 100%, width 100% will cause the anchor to fill out the area of the div.&lt;/p&gt;
&lt;p&gt;The result is that we are left with a transparent anchor tag that completely overlays the area of the div, providing the default clickable behavior users expect.  The last CSS trick to making this work is to set z-index to 1, forcing the browser to always render the anchor tag &lt;em&gt;over&lt;/em&gt; whatever content is in the div.&lt;br/&gt;&lt;br/&gt;The positives to this method are that 1. we restore the expected clickable behavior without javascript (meaning it also works as soon as that markup is rendered and not when $(document).ready is fired) and 2. we&amp;#8217;re using correct HTML syntax.&lt;br/&gt;&lt;br/&gt;I should point out there is a downside to this method, in that because the anchor overlays the div, the contents of the div are no longer selectable or clickable.  Depending on your application this may be negligible.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://blogger.googleusercontent.com/tracker/3762802375429612564-1183817246464595974?l=urlencode.blogspot.com" height="1" width="1"/&gt;&lt;/p&gt;</description><link>http://urlencode.tumblr.com/post/1020777977</link><guid>http://urlencode.tumblr.com/post/1020777977</guid><pubDate>Fri, 20 Aug 2010 10:44:00 -0600</pubDate><category>css</category><category>html</category><category>jquery</category></item><item><title>Top 10 Programming T-Shirts That Don't Make Sense</title><description>&lt;p&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-size: x-large;"&gt;mind.location = unknown&lt;/span&gt;&lt;/b&gt;&lt;br/&gt;&lt;a href="http://www.zazzle.com/javascript_mind_tshirt-235892961444457742"&gt;&lt;a href="http://www.zazzle.com/javascript_mind_tshirt-235892961444457742"&gt;http://www.zazzle.com/javascript_mind_tshirt-235892961444457742&lt;/a&gt;&lt;/a&gt;&lt;br/&gt;I wonder what the value of the variable unknown is?&lt;br/&gt;&lt;br/&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-size: x-large;"&gt;import_soul&lt;/span&gt;&lt;/b&gt;&lt;br/&gt;&lt;a href="http://www.zazzle.com/import_soul_tshirt-235715645595867505"&gt;&lt;a href="http://www.zazzle.com/import_soul_tshirt-235715645595867505"&gt;http://www.zazzle.com/import_soul_tshirt-235715645595867505&lt;/a&gt;&lt;/a&gt;&lt;br/&gt;&lt;/p&gt;&lt;div&gt;What is import_soul?  It&amp;#8217;s written as a keyword.  If it were a function it should be import_soul(), however the keywords for this shirt include &amp;#8220;python&amp;#8221; which makes me thinking they &lt;i&gt;meant&lt;/i&gt; &lt;b&gt;&lt;i&gt;import soul&lt;/i&gt;&lt;/b&gt;.&lt;/div&gt;&lt;div&gt;&lt;br/&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-size: x-large;"&gt;Function Check_Drunk()&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;a href="http://www.zazzle.com/function_check_drunk_tshirt-235954739548677347"&gt;&lt;a href="http://www.zazzle.com/function_check_drunk_tshirt-235954739548677347"&gt;http://www.zazzle.com/function_check_drunk_tshirt-235954739548677347&lt;/a&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;Where do I begin with this one&amp;#8230; drink is treated as a global variable but never declared globally.  Then there&amp;#8217;s the awesome conditional if &amp;#8220;bra = true&amp;#8221; which will always return true because a single = is assignment not evaluation.  Lastly, none of the functions are ever called, they&amp;#8217;re just declarations of.&lt;/div&gt;&lt;div&gt;&lt;br/&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-size: x-large;"&gt;Programmers Cool Club&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;a href="http://www.zazzle.com/cool_programmers_club_tshirt-235068746346060145"&gt;&lt;a href="http://www.zazzle.com/cool_programmers_club_tshirt-235068746346060145"&gt;http://www.zazzle.com/cool_programmers_club_tshirt-235068746346060145&lt;/a&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;No comment needed.&lt;/div&gt;&lt;div&gt;&lt;br/&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-size: x-large;"&gt;.ninja { color: black; }&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;a href="http://www.zazzle.com/css_ninja_style_class_tshirt-235091799113607617"&gt;&lt;a href="http://www.zazzle.com/css_ninja_style_class_tshirt-235091799113607617"&gt;http://www.zazzle.com/css_ninja_style_class_tshirt-235091799113607617&lt;/a&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;This one&amp;#8217;s amusing and almost worth getting, but the behavior of &lt;i&gt;visibility: hidden;&lt;/i&gt; is such that it keeps screen space allocated for the element and simply does not render it.  I personally believe a true ninja would &lt;i&gt;{ display: none; }&lt;/i&gt;.&lt;/div&gt;&lt;div&gt;&lt;br/&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-size: x-large;"&gt;&lt;b&gt;Geek Power&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;a href="http://www.zazzle.com/geek_power_tshirt-235232870665206831"&gt;&lt;a href="http://www.zazzle.com/geek_power_tshirt-235232870665206831"&gt;http://www.zazzle.com/geek_power_tshirt-235232870665206831&lt;/a&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;No geek would ever intentionally rip the cord to their keyboard like that&lt;/div&gt;&lt;div&gt;&lt;br/&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-size: x-large;"&gt;Computers are Only Human&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;a href="http://www.zazzle.com/computers_are_only_human_tshirt-235670270460766159"&gt;&lt;a href="http://www.zazzle.com/computers_are_only_human_tshirt-235670270460766159"&gt;http://www.zazzle.com/computers_are_only_human_tshirt-235670270460766159&lt;/a&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;Apparently I didn&amp;#8217;t get that memo.&lt;/div&gt;&lt;div&gt;&lt;br/&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-size: x-large;"&gt;&lt;b&gt;SELECT TOP 25&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;a href="http://www.zazzle.com/the_best_sql_query_ever_tshirt-235031072069340726"&gt;&lt;a href="http://www.zazzle.com/the_best_sql_query_ever_tshirt-235031072069340726"&gt;http://www.zazzle.com/the_best_sql_query_ever_tshirt-235031072069340726&lt;/a&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;Aside from using the vendor-specific &amp;#8220;TOP 25&amp;#8221; (MS SQL), the comment at the bottom brings to light the poor execution of this SQL:  It should be sorted DESCENDING&lt;/div&gt;&lt;div&gt;&lt;br/&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-size: x-large;"&gt;Do You Speak Code&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;a href="http://www.zazzle.com/do_you_speak_code_tshirt-235290525576102199"&gt;&lt;a href="http://www.zazzle.com/do_you_speak_code_tshirt-235290525576102199"&gt;http://www.zazzle.com/do_you_speak_code_tshirt-235290525576102199&lt;/a&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br/&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-size: x-large;"&gt;There&amp;#8217;s No Crying in Programming&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;a href="http://www.zazzle.com/no_crying_in_programming_card-137314447034339159"&gt;&lt;a href="http://www.zazzle.com/no_crying_in_programming_card-137314447034339159"&gt;http://www.zazzle.com/no_crying_in_programming_card-137314447034339159&lt;/a&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width="1" height="1" src="https://blogger.googleusercontent.com/tracker/3762802375429612564-8065588934929862505?l=urlencode.blogspot.com" alt=""/&gt;&lt;/div&gt;</description><link>http://urlencode.tumblr.com/post/1020777912</link><guid>http://urlencode.tumblr.com/post/1020777912</guid><pubDate>Thu, 12 Aug 2010 21:27:00 -0600</pubDate><category>random</category></item><item><title>Python Templating For the Web (Random Ideas)</title><description>&lt;p&gt;Well it&amp;#8217;s past midnight and I&amp;#8217;m musing about web templating in Python for Tornado or AppEngine.   The thing about most Python templating engines that I notice is&amp;#8230;&lt;br/&gt;&lt;br/&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;There&amp;#8217;s kind of an obsession with being agnostic about everything.  You can render JSON and XML and whatever else you want with our engine!  When is someone just going to make a really awesome templating engine &lt;i&gt;for the web&lt;/i&gt; and not try to be everything to everyone?&lt;br/&gt;&lt;/li&gt;&lt;li&gt;The value in a template engine to me is how easy it is to allow the template to include logic that&amp;#8217;s independent of the controller that&amp;#8217;s generating it.  For example, you might want a server-side ad manager on every page, but you don&amp;#8217;t necessarily want to put the code for that in every controller.  Solution?  Some engines call it modules, some call it template tags, but whatever the name there is some type of logic that&amp;#8217;s independent of the controller.  The problem is that most of these pieces of independent logic are needlessly complicated.  (side note: Django has gotten a bit better about this since I first used it two years ago).&lt;br/&gt;&lt;/li&gt;&lt;li&gt;Maybe some better support for lazy-loaded values which are available for all templates&amp;#8230; things like static URL, etc.&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;So it&amp;#8217;s late and I&amp;#8217;m thinking, what if there was a template engine, and I mean one specifically for the web, which represented an HTML document more so as a Python class.  Every root element or element with an ID is a property of the document.  Tags can interact with each other&amp;#8230; Maybe this is turning out to be too much of a DOM implementation in Python.  Maybe this is a bad idea.  Or maybe I should try coding up a prototype just to see what it&amp;#8217;s like.&lt;/div&gt;&lt;div&gt;&lt;br/&gt;&lt;/div&gt;&lt;div&gt;But it&amp;#8217;s not quite a DOM.  The DOM is concerned with specific structure, where as we&amp;#8217;re only concerned with a loose abstract structure.  It doesn&amp;#8217;t matter of the area where scripts are printed too is in the  or right above , what&amp;#8217;s important is that there is a scripts area which sub-modules can access.&lt;/div&gt;&lt;div&gt;&lt;br/&gt;&lt;/div&gt;&lt;div&gt;Instead of {% extends &amp;#8220;some_html_file.html %}, it could be {% extends templates.master %} where templates.master is a python module.&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;(15 minutes later)&amp;#8230; you know it kind of sounds like I&amp;#8217;m trying to re-invent ASP.NET WebForms&amp;#8230;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width="1" height="1" src="https://blogger.googleusercontent.com/tracker/3762802375429612564-6740000498734877368?l=urlencode.blogspot.com" alt=""/&gt;&lt;/div&gt;</description><link>http://urlencode.tumblr.com/post/1020777837</link><guid>http://urlencode.tumblr.com/post/1020777837</guid><pubDate>Sat, 07 Aug 2010 00:20:00 -0600</pubDate><category>template</category><category>web-frameworks</category></item></channel></rss>
