<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>Posts about Programming</title>
    <link>http://wiki.futuretoby.com/tag/programming</link>
    <language>en-us</language>
    <item>
      <title>Node Knockout 2011 and Twends</title>
      <description>This past weekend I participated in the &amp;nbsp;&lt;a href="http://nodeknockout.com/"&gt;Node Knockout&lt;/a&gt;&amp;nbsp;- a programming competition where teams of 1 - 4 members build something using&amp;nbsp;&lt;a href="http://nodejs.org/"&gt;node.js&lt;/a&gt;&amp;nbsp;in 48 hours.&amp;nbsp;I was very fortunate to have worked with&amp;nbsp;&lt;a href="http://twitter.com/#!/robfaraj"&gt;@robfaraj&lt;/a&gt;&amp;nbsp;on this, it was a fun couple of days! The end result is what we call&amp;nbsp;&lt;s&gt;&lt;a href="http://cubespace.nko2.nodeknockout.com/"&gt;Twends&lt;/a&gt;&lt;/s&gt;&amp;nbsp;Twends: new location is now&amp;nbsp;&lt;a href="http://twends.us"&gt;twends.us&lt;/a&gt;. Twends is a real-time Twitter trend visualization...app. It looks like this&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;&lt;img title="Twends" alt="Twends" src="https://lh4.googleusercontent.com/-FYvHuvGFjdM/TlxSDd765JI/AAAAAAAAR00/mZeQg0h5R9o/s800/twends.jpg"&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;First, you either select a trending topic or type in a term of your own, then you will see this word visualization based on a series of packed circles. The larger the circle and the redder it is, the more frequently the word is being said at the moment. All the while, birds are fly across the screen. Each bird on the screen represents a tweet that's been written, now...ish. Just sit back, relax and watch the pretty circles changing shape and the birds flying across your screen. By reading the words you can often learn interesting things. For example, I learned while reading Twends that Justin Beiber fans are called beliebers, while Taylor Swift fans are called swifies.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;Oh! And here's a video of it in action&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;&lt;iframe src="http://www.screenr.com/embed/pSWs" width="650" height="396" frameborder="0"&gt;&lt;/iframe&gt;&lt;br&gt;&lt;/div&gt;&lt;h2&gt;The Tech&lt;/h2&gt;&lt;div&gt;Twends was built using client-side Javascript with the help of some great libraries and the&amp;nbsp;&lt;a href="https://dev.twitter.com/docs/api"&gt;Twitter REST API&lt;/a&gt;.&amp;nbsp;&lt;a href="http://mbostock.github.com/d3/" style="color: rgb(136, 136, 136); "&gt;d3.js&lt;/a&gt;&amp;nbsp;is without a doubt the&amp;nbsp;most valuable library(MVL). We used it to layout the circles as well as animate them from their old positions to the new positions each time new data comes in. We also used&amp;nbsp;&lt;a href="http://html5boilerplate.com/"&gt;HTML5 Boilerplate&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="http://jquery.com/"&gt;jQuery&lt;/a&gt;. On the server side, we used&amp;nbsp;&lt;a href="http://expressjs.com/"&gt;express&lt;/a&gt;&amp;nbsp;and the&amp;nbsp;&lt;a href="http://jade-lang.com/"&gt;jade&lt;/a&gt;&amp;nbsp;templating language.&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;Graphics is done using SVG, which d3.js works very well with - although is independent of.&amp;nbsp;IE8 and below do no support SVG so Twends do not work there.&amp;nbsp;Twends could have worked on IE9 but it doesn't. IE9 supports SVG, so that was not the problem. The problem was that IE9 was blocking the JSONP requests I was making to the Twitter API due to&amp;nbsp;&lt;a href="https://dev.twitter.com/discussions/1232"&gt;this problem&lt;/a&gt;, of which the blame is half on Microsoft and half on Twitter. So, if you go to the site with IE, it will greet you with a friendly(?) message and prompt you to install Google Chrome Frame, yea!&lt;/div&gt;&lt;h2&gt;The Aftermath&lt;/h2&gt;&lt;div&gt;&lt;s&gt;The competition is still being judged at the moment, so I don't know what's the aftermath just yet. I guess I'll update this part of the post another time.&lt;/s&gt;&lt;/div&gt;&lt;div&gt;&lt;s&gt;&lt;br&gt;&lt;/s&gt;&lt;/div&gt;&lt;div&gt;Node knockout came to an end and the&amp;nbsp;&lt;a href="http://nodeknockout.com/"&gt;winners&lt;/a&gt;&amp;nbsp;were victorious! Congrats to them. I am a little disappointed/surprised that one of my favorite entries:&amp;nbsp;&lt;a href="http://kibu.nko2.nodeknockout.com/"&gt;Pitchography&lt;/a&gt;&amp;nbsp;didn't win anything, here's a demo of their&amp;nbsp;&lt;a href="http://www.youtube.com/watch?v=a4gy1s1RzS8"&gt;awesome presentation tool&lt;/a&gt;. As for Twends, well we were decidedly better than half of the entries out there :) We also presented it at the&amp;nbsp;&lt;a href="http://www.meetup.com/AtlantaJavaScript/"&gt;Atlanta Javascript Users Group&lt;/a&gt;&amp;nbsp;and got some good feedback. I've made the source code&amp;nbsp;&lt;a href="https://github.com/airportyh/twends"&gt;public on github&lt;/a&gt;&amp;nbsp;as well.&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;Node Knockout was a great experience. The organizers did a superb job of allowing the contestants to focus on writing code rather than dealing with setting up servers or administrative stuff. I enjoyed everything from the planning stages where we threw around random ideas, to the actually coding and then to the showing it off to people and seeing their reactions and comments. If you love code, then I highly recommend that you try a hackathon like this one.&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;</description>
      <pubDate>Mon, 29 Aug 2011 22:19:07 +0000</pubDate>
      <guid>http://wiki.futuretoby.com/Node_Knockout_2011_and_Twends</guid>
      <author>toby ho</author>
      <link>http://wiki.futuretoby.com/Node_Knockout_2011_and_Twends</link>
    </item>
    <item>
      <title>My JSConf Talk in Video</title>
      <description>The awesome folks behind JSConf just released a&amp;nbsp;&lt;a href="http://blip.tv/jsconf"&gt;whole bunch of great talks in video form&lt;/a&gt;&amp;nbsp;from the Portland event. Great chance to catch up on the talks whether you were there or not! They even put mine up there, which since this is my website, I am obliged to embed here. Wow I sound so very Chinese.&lt;div&gt;&lt;br&gt;&lt;div&gt;&lt;div class="embed" style="width: 550px; height: 393px;"&gt;&lt;span class="embed_indicator"&gt;Embedded Content&lt;/span&gt;&lt;iframe src="http://blip.tv/play/g_Mngs6pEwI.html" width="550" height="393" frameborder="0" allowfullscreen=""&gt;&lt;/iframe&gt;&lt;embed type="application/x-shockwave-flash" src="http://a.blip.tv/api.swf#g_Mngs6pEwI" style="display:none"&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</description>
      <pubDate>Fri, 19 Aug 2011 15:51:16 +0000</pubDate>
      <guid>http://wiki.futuretoby.com/My_JSConf_Talk_in_Video</guid>
      <author>toby ho</author>
      <link>http://wiki.futuretoby.com/My_JSConf_Talk_in_Video</link>
    </item>
    <item>
      <title>Book Review: Python Testing Cookbook</title>
      <description>This is the second of 2 Python book reviews. The book is Python Test Cookbook.&amp;nbsp;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;This book is a very complete overview of all aspects of testing with Python. It starts out with simple unit tests, then moves on to nose, BDD, Doctest, acceptance testing, coverage, continuous integration, and smoke tests and load tests. The last chapter of the book gives you a number of advices for starting out with testing.&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;h2&gt;The Good&lt;/h2&gt;&lt;div&gt;I enjoyed this book in that it gave me a birds-eye view of all the tools and techniques that are there for Python, many of which I didn't know about before. I also learn new things about things that I had already used before. Lastly, I liked the last chapter in which the author gives us his heart-felt experiences with testing. Although I don't agree with everything he says(running your tests once a day is way too few), there is a lot of good advice there as well as good stories.&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;h2&gt;The Bad&lt;/h2&gt;&lt;div&gt;One thing that I don't like about this book is that it's too code heavy. Pages and pages of code are print onto the page with only interleaving explanations. I mostly skimmed those parts because reading code line-by-line like that is just too boring. Code is simply not meant to be read in a linear fashion. When you read code, you jump between different files rapidly in order to fill the in missing context as you try to gain an understanding of the code. An even better aid in reading code is the ability to execute the code and instrument it with print statements or stop it with the debugger and inspect the program state. So, in summary, code-heavy books just doesn't make sense. Perhaps instead of writing this as a book, we should just point the readers at a code repository?&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;The second problem is that not enough was done to motivate each technique that was used. The author didn't properly motivate why one should write unit tests at all. Or why use a given technique listed in the book. Only cursory introduction is given for each technique or tool, and then it was straight to the code. We dwelled too much time on the how and not on the why, which makes this book very unfriendly to beginners.&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;h2&gt;Summing Up&lt;/h2&gt;&lt;div&gt;Overall, I would not recommend this book to beginners or people who are looking for an introduction to testing. I am on the fence about recommending it at all, but it might be helpful for people who are already familiar with test driven development but just haven't been doing it with Python.&lt;/div&gt;</description>
      <pubDate>Tue, 02 Aug 2011 12:47:37 +0000</pubDate>
      <guid>http://wiki.futuretoby.com/Book_Review%3A_Python_Testing_Cookbook</guid>
      <author>toby ho</author>
      <link>http://wiki.futuretoby.com/Book_Review%3A_Python_Testing_Cookbook</link>
    </item>
    <item>
      <title>Book Review: Python 3 Web Development - Beginners Guide</title>
      <description>&lt;i&gt;I just finished reading Python 3 Web Development - Beginners Guide by Michel Anders and here is my book review.&lt;/i&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;Michel Anders is no doubt a brilliant programmer. He has managed to go through HTML, Javascript, jQuery, jQuery plugins(both using and writing), jQuery UI, CSS selectors, CSS 3, Python, CherryPy, SQL and SQLite, unit testing, writing your own ORM, and Python meta-classes&amp;nbsp;all in one book! Which is the problem with this book. I doubt any one who qualifies as a beginner will be able to get any further than chapter 2. I believe the author made the mistake of not putting in enough thought about his audience when writing. But, before making my final remarks, I'll give it proper treatment by commenting on each of the chapters.&lt;/div&gt;&lt;h2&gt;Chapter 1&lt;br&gt;&lt;/h2&gt;&lt;div&gt;Chapter 1 explained the authors reasons for choosing the tools that he did, and &lt;i&gt;boy&lt;/i&gt; were there a lot of choices to be made. Here were the choices:&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;&lt;ul&gt;&lt;li&gt;Web framework: CherryPy&lt;/li&gt;&lt;li&gt;Language: Python 3&lt;/li&gt;&lt;li&gt;Javascript Library: jQuery and jQuery UI&lt;/li&gt;&lt;li&gt;Database: SQLLite&lt;/li&gt;&lt;li&gt;ORM: None. He's rolling his own&lt;/li&gt;&lt;li&gt;Revision Control: svn&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;There are a lot of high level talk about the rationale of each choice and why he made them. It was a bit strange that he put the choice of using Python &lt;i&gt;after&lt;/i&gt; the choice of using CherryPy. The first chapter is quite intimidating for beginners - there is really lots to consider when building a web app. He admits it too, but he puts in a lot of encouraging words to encourage the reader to stay focused.&lt;/div&gt;&lt;h2&gt;Chapter 2&lt;/h2&gt;&lt;div&gt;Chapter 2 went through the exercise of building a web-based spreadsheet application, a la Google Docs. The goal is ambitious, especially for a "hello world" program. I wondered how he was going to pull it off.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;The Author covered CherryPy, jQuery/CSS selectors, a jQuery plugin called jEditable, wrote his own jQuery plugin that builds a spreadsheet which uses jEditable, CSS 3 and HTML all in this chapter. The amount of Javascript in this chapter really surprised me because in the who-is-this-book-for section, it says "introductory level knowledge of JavaScript might be useful, but is not strictly necessary". He simply tried to cram too many things in, explaining each technology only cursorily as he encounters them.&amp;nbsp;&lt;i&gt;I am pretty sure that he lost almost all readers in his audience with this chapter&lt;/i&gt;.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;h2&gt;The Rest of the Chapters&lt;/h2&gt;&lt;div&gt;Since we've already lost almost all readers I will place less emphasis on chapters 3-10. Basically, it is more of the same: trying to cram too much information into his readers' minds too quickly. These chapters whirl-wind tour the following:&lt;/div&gt;&lt;div&gt;&lt;ul&gt;&lt;li&gt;Writing an authentication handler, and then later authorization within CherryPy&lt;/li&gt;&lt;li&gt;Using the file system as storage&lt;/li&gt;&lt;li&gt;Using SQLite to replace the file system as as storage&lt;/li&gt;&lt;li&gt;Using SQL directly to manipulate and query the database&lt;/li&gt;&lt;li&gt;Ajax and lots more of jQuery and jQuery UI&lt;/li&gt;&lt;li&gt;Unit testing in Python&lt;/li&gt;&lt;li&gt;Building a hand-rolled ORM, and then improving it using meta-classes, where the phrase "make your head explode" was used&lt;/li&gt;&lt;li&gt;Adding a CRUD interface to the system for his CRM, and then refining the CRM.&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;The further you get in the book, the larger blocks of code were put on the page, and the author just tries to talk through what is going on. I skimmed most of these chapters because when you are explaining code that is so dense, it is easier to read the code itself - which I often resorted to - than to read the prose.&lt;/div&gt;&lt;/div&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;div&gt;Unfortunately, I cannot recommend this book. Reading from the book title, the audience is a Python programmer, perhaps beginner to intermediate, who is beginning in building web applications. This book will send this programmer away crying. I think perhaps a more fitting title for this book is "A Coding Cowboy's Journey In Web Development with Python 3".&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;/div&gt;</description>
      <pubDate>Thu, 21 Jul 2011 23:54:14 +0000</pubDate>
      <guid>http://wiki.futuretoby.com/Book_Review%3A_Python_3_Web_Development_-_Beginners_Guide</guid>
      <author>toby ho</author>
      <link>http://wiki.futuretoby.com/Book_Review%3A_Python_3_Web_Development_-_Beginners_Guide</link>
    </item>
    <item>
      <title>Python Book Reviews Forthcoming</title>
      <description>The kind folks at&amp;nbsp;&lt;a href="http://www.PacktPub.com"&gt;PacktPub&lt;/a&gt;&amp;nbsp;are letting me review a couple of Python books. Hooray! They are&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;&lt;ol&gt;&lt;li&gt;&lt;span class="Apple-style-span" style="font-family: Calibri; line-height: normal; word-spacing: 0px; font-size: medium; border-collapse: collapse; "&gt;&lt;a href="http://www.packtpub.com/python-3-web-development-beginners-guide/book" target="_blank" style="color: rgb(34, 34, 34); "&gt;Python 3 Web Development Beginner's Guide&lt;/a&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="Apple-style-span" style="font-family: Calibri; line-height: normal; word-spacing: 0px; font-size: medium; border-collapse: collapse; "&gt;&lt;a href="http://www.packtpub.com/python-testing-cookbook/book" target="_blank" style="color: rgb(34, 34, 34); "&gt;Python Testing Cookbook&lt;/a&gt;&lt;/span&gt;&lt;br&gt;&lt;/li&gt;&lt;/ol&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;Look for my reviews of them in the near future.&lt;/div&gt;</description>
      <pubDate>Fri, 15 Jul 2011 10:38:09 +0000</pubDate>
      <guid>http://wiki.futuretoby.com/Python_Book_Reviews_Forthcoming</guid>
      <author>toby ho</author>
      <link>http://wiki.futuretoby.com/Python_Book_Reviews_Forthcoming</link>
    </item>
    <item>
      <title>The Javascript Stacktrace Blog Post</title>
      <description>For the past week or so I did some research on how best to include scripts in &lt;a href="http://tuttijs.com"&gt;Tutti&lt;/a&gt;'s sandbox environment&amp;nbsp;and still get the best stacktraces possible. I got sucked in deeper and deeper and it just got uglier and uglier. This post will attempt to summarize all the knowledge that I've uncovered.&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;h2&gt;What's a Stacktrace?&lt;br&gt;&lt;/h2&gt;&lt;div&gt;When I say stacktrace, I mean it in the context an exception being thrown in your code, and getting the information about where exactly in your code the exception was thrown. This is what a exception might look like&lt;/div&gt;&lt;pre&gt;&lt;span class="Apple-style-span" style="border-collapse: collapse; font-family: Monaco, monospace; font-size: 13px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; line-height: normal; white-space: normal; word-spacing: 0px; "&gt;Error: Buck stops here.&lt;br&gt;at failInlined (http://localhost:8000/error_object/:16:11)&lt;br&gt;at catchError (http://localhost:8000/util.js:77:26)&lt;br&gt;at http://localhost:8000/error_object/:49:1&lt;/span&gt;&lt;br&gt;&lt;/pre&gt;&lt;div&gt;First, there is an error message. Then, the stacktrace. The stacktrace basically&amp;nbsp;represents&amp;nbsp;the state of the program's&amp;nbsp;&lt;a href="http://en.wikipedia.org/wiki/Call_stack"&gt;call stack&lt;/a&gt;&amp;nbsp;at the point when the exception was thrown. The stacktrace also contains the location(file URL and line number) of each call in the stack, which is extremely useful for debugging.&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;h2&gt;So What's the Problem?&lt;/h2&gt;&lt;div&gt;The problem, is that not all browsers give you informative stacktraces. Not only that, different browsers give you the information in different ways.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;Most browsers today give you the stacktrace information in the Error object that was thrown. In Firefox, Chrome and Opera, for example, the Error object contains a &lt;i&gt;stack&lt;/i&gt; property which is a string representation of the stacktrace, much like the example shown above.&lt;/div&gt;&lt;pre&gt;// Get stacktrace on Firefox, Chrome and Opera&lt;/pre&gt;&lt;pre&gt;try{&lt;/pre&gt;&lt;pre&gt;   throw new Error('Buck stops here')&lt;/pre&gt;&lt;pre&gt;}catch(e){&lt;/pre&gt;&lt;pre&gt;   console.log(e.stack) // Yea!&lt;/pre&gt;&lt;pre&gt;}&lt;/pre&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;In Safari, however, the stack property is non-existent: it does not give you the full stacktrace. Instead it gives you the location for the top stack frame only. This is gotten from the properties &lt;i&gt;sourceURL&lt;/i&gt; and &lt;i&gt;line&lt;/i&gt;.&lt;/div&gt;&lt;pre&gt;// Get 1-level stacktrace on Safari&lt;/pre&gt;&lt;pre&gt;try{&lt;/pre&gt;&lt;pre&gt;  throw new Error('Buck stops here')&lt;/pre&gt;&lt;pre&gt;}catch(e){&lt;/pre&gt;&lt;pre&gt;  console.log(e.sourceURL + ': ' + e.line) // Meh&lt;/pre&gt;&lt;pre&gt;}&lt;/pre&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;On IE, you are out of luck. There is no stacktrace information available on the Error object.&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;h2&gt;Going Deeper&lt;/h2&gt;&lt;div&gt;Javascript can be executed in various different ways/techniques, and not all of them yield good stacktraces. My next objective was to see what the stacktraces look like for the different techniques&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;h3&gt;Technique 1: Script Tag Includes&lt;/h3&gt;&lt;div&gt;The script tag include is probably the most common way to execute Javascript on a webpage.&lt;/div&gt;&lt;pre&gt;&amp;lt;script src="myscript.js"&amp;gt;&amp;lt;/script&amp;gt;&lt;/pre&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;h3&gt;Technique 2: Inlined Script Tag&lt;/h3&gt;&lt;div&gt;Alternatively you can inlined Javascript code inside of the script tag.&lt;/div&gt;&lt;pre&gt;&amp;lt;script&amp;gt;&lt;/pre&gt;&lt;pre&gt;console.log('Hello world')&lt;/pre&gt;&lt;pre&gt;&amp;lt;/script&amp;gt;&lt;/pre&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;h3&gt;Technique 3: Dynamically Inserted Script Tag&lt;/h3&gt;&lt;div&gt;You can also create a script element dynamically in Javascript and load some Javascript into it.&lt;/div&gt;&lt;pre&gt;var script = document.createElement('script')&lt;/pre&gt;&lt;pre&gt;if (&amp;lt;IE sucks and you are it&amp;gt;)&lt;/pre&gt;&lt;pre&gt;  script.text = jsCode&lt;/pre&gt;&lt;pre&gt;else&lt;/pre&gt;&lt;pre&gt;  script.appendChild(document.createTextNode(jsCode))&lt;/pre&gt;&lt;pre&gt;document.body.appendChild(script)&lt;/pre&gt;&lt;pre&gt;document.body.removeChild(script)&lt;/pre&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;h3&gt;Technique 4: Eval&lt;/h3&gt;&lt;div&gt;Use eval to execute the Javascript in Javascript. You probably want to&amp;nbsp;&lt;a href="http://perfectionkills.com/global-eval-what-are-the-options/"&gt;global eval&lt;/a&gt;&amp;nbsp;it.&lt;/div&gt;&lt;pre&gt;// This code for global eval stolen from jQuery 1.6.1&lt;/pre&gt;&lt;pre&gt;(window.execScript || function(jsCode) {
	window["eval"].call(window, jsCode);
} )(data);&lt;br&gt;&lt;/pre&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;h3&gt;Technique 5: Data URL in the Script Tag&lt;br&gt;&lt;/h3&gt;&lt;div&gt;Using a data URL in a script tag is...I am not sure if anyone actually does this, and I am not entirely sure it's useful, but what the heck.&lt;/div&gt;&lt;pre&gt;&amp;lt;script url="data:application/javascript,console.log('hello%20world')"&amp;gt;&amp;lt;/script&amp;gt;&lt;/pre&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;h3&gt;Summary: Stacktrace Information From Error Object&lt;/h3&gt;&lt;div&gt;Long story short, I tested the stacktrace output for each of these five techniques in different browsers. I summarized the results in this here table (that's right, geek out!)&lt;/div&gt;&lt;div&gt;&lt;style&gt;
table#support,
#definitions
{
    font-family: Helvetica, "sans serif";
}
table#support{
    width: 100%;
    border-collapse: collapse;
}
table#support th,
table#support td{
    border: 1px solid #aaa;
    text-align: center;
}

#definitions dt, 
#definitions dd{
}
#definitions dt{
    float: left;
    clear: left;
    font-weight: bold;
}
#definitions dd{
    margin-left: 5em;
}
&lt;/style&gt;
&lt;table id="support"&gt;
    &lt;tbody&gt;&lt;tr&gt;
        &lt;th rowspan="2"&gt;Browser&lt;/th&gt;
        &lt;th colspan="4" title="Script tag with `src` URL attribute"&gt;Include&lt;/th&gt;
        &lt;th colspan="4" title="Inlined script tag"&gt;Inlined&lt;/th&gt;
        &lt;th colspan="4" title="Dynamically inserted inlined script tag"&gt;Dynamic&lt;/th&gt;
        &lt;th colspan="4" title="Global Eval'ed Javascript"&gt;Eval'ed&lt;/th&gt;
        &lt;th colspan="4" title="Script tag with `src` as a Data URL"&gt;Data URL&lt;/th&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;th title="Line Number"&gt;LN&lt;/th&gt;
        &lt;th title="Source File URL"&gt;SR&lt;/th&gt;
        &lt;th title="Stacktrace"&gt;ST&lt;/th&gt;
        &lt;th title="Call arguments in Stacktrace"&gt;AG&lt;/th&gt;
        &lt;th title="Line Number"&gt;LN&lt;/th&gt;
        &lt;th title="Source File URL"&gt;SR&lt;/th&gt;
        &lt;th title="Stacktrace"&gt;ST&lt;/th&gt;
        &lt;th title="Call arguments in Stacktrace"&gt;AG&lt;/th&gt;
        &lt;th title="Line Number"&gt;LN&lt;/th&gt;
        &lt;th title="Source File URL"&gt;SR&lt;/th&gt;
        &lt;th title="Stacktrace"&gt;ST&lt;/th&gt;
        &lt;th title="Call arguments in Stacktrace"&gt;AG&lt;/th&gt;
        &lt;th title="Line Number"&gt;LN&lt;/th&gt;
        &lt;th title="Source File URL"&gt;SR&lt;/th&gt;
        &lt;th title="Stacktrace"&gt;ST&lt;/th&gt;
        &lt;th title="Call arguments in Stacktrace"&gt;AG&lt;/th&gt;
        &lt;th title="Line Number"&gt;LN&lt;/th&gt;
        &lt;th title="Source File URL"&gt;SR&lt;/th&gt;
        &lt;th title="Stacktrace"&gt;ST&lt;/th&gt;
        &lt;th title="Call arguments in Stacktrace"&gt;AG&lt;/th&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;IE 6 - 8&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td colspan="4"&gt;Unsupported&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;IE 9&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;Safari 5&lt;/td&gt;
        &lt;td&gt;Y&lt;/td&gt;
        &lt;td&gt;Y&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td&gt;Y&lt;/td&gt;
        &lt;td&gt;Y&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td&gt;Y*&lt;/td&gt;
        &lt;td&gt;Y&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td&gt;Y&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td&gt;Y*&lt;/td&gt;
        &lt;td&gt;Y&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;Chrome 11&lt;/td&gt;
        &lt;td&gt;Y&lt;/td&gt;
        &lt;td&gt;Y&lt;/td&gt;
        &lt;td&gt;Y&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td&gt;Y&lt;/td&gt;
        &lt;td&gt;Y&lt;/td&gt;
        &lt;td&gt;Y&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td&gt;Y*&lt;/td&gt;
        &lt;td&gt;Y&lt;/td&gt;
        &lt;td&gt;Y&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td&gt;Y*&lt;/td&gt;
        &lt;td&gt;Y&lt;/td&gt;
        &lt;td&gt;Y&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td&gt;Y*&lt;/td&gt;
        &lt;td&gt;Y&lt;/td&gt;
        &lt;td&gt;Y&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;Firefox 3.6 - 4&lt;/td&gt;
        &lt;td&gt;Y&lt;/td&gt;
        &lt;td&gt;Y&lt;/td&gt;
        &lt;td&gt;Y&lt;/td&gt;
        &lt;td&gt;Y&lt;/td&gt;
        &lt;td&gt;Y&lt;/td&gt;
        &lt;td&gt;Y&lt;/td&gt;
        &lt;td&gt;Y&lt;/td&gt;
        &lt;td&gt;Y&lt;/td&gt;
        &lt;td&gt;Y*&lt;/td&gt;
        &lt;td&gt;Y&lt;/td&gt;
        &lt;td&gt;Y&lt;/td&gt;
        &lt;td&gt;Y&lt;/td&gt;
        &lt;td&gt;Y*&lt;/td&gt;
        &lt;td&gt;Y&lt;/td&gt;
        &lt;td&gt;Y&lt;/td&gt;
        &lt;td&gt;Y&lt;/td&gt;
        &lt;td&gt;Y*&lt;/td&gt;
        &lt;td&gt;Y&lt;/td&gt;
        &lt;td&gt;Y&lt;/td&gt;
        &lt;td&gt;Y&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;Opera 11&lt;/td&gt;
        &lt;td&gt;Y&lt;/td&gt;
        &lt;td&gt;Y&lt;/td&gt;
        &lt;td&gt;Y&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td&gt;Y*&lt;/td&gt;
        &lt;td&gt;Y&lt;/td&gt;
        &lt;td&gt;Y&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td&gt;Y*&lt;/td&gt;
        &lt;td&gt;Y&lt;/td&gt;
        &lt;td&gt;Y&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td&gt;Y&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td&gt;Y*&lt;/td&gt;
        &lt;td&gt;Y&lt;/td&gt;
        &lt;td&gt;Y&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
    &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;dl id="definitions"&gt;
    &lt;dt&gt;*&lt;/dt&gt;&lt;dd&gt;Line number may not be helpful&lt;/dd&gt;
    &lt;dt&gt;LN&lt;/dt&gt;&lt;dd&gt;Line numbers&lt;/dd&gt;
    &lt;dt&gt;SR&lt;/dt&gt;&lt;dd&gt;Source file URL&lt;/dd&gt;
    &lt;dt&gt;ST&lt;/dt&gt;&lt;dd&gt;Full stacktrace&lt;/dd&gt;
    &lt;dt&gt;AG&lt;/dt&gt;&lt;dd&gt;Call arguments in stacktrace&lt;/dd&gt;
    &lt;dt&gt;Include&lt;/dt&gt;&lt;dd&gt;Script tag with &lt;code&gt;src&lt;/code&gt; set to a Javasrcipt file URL&lt;/dd&gt;
    &lt;dt&gt;Inlined&lt;/dt&gt;&lt;dd&gt;Script tag with inlined Javascript&lt;/dd&gt;
    &lt;dt&gt;Dynamic&lt;/dt&gt;&lt;dd&gt;Dynamically inserted script tag with inlined Javascript&lt;/dd&gt;
    &lt;dt&gt;Eval'ed&lt;/dt&gt;&lt;dd&gt;Global eval'ed Javascript&lt;/dd&gt;
    &lt;dt&gt;Data URL&lt;/dt&gt;&lt;dd&gt;Script tag with &lt;code&gt;src&lt;/code&gt; set to a Data URL containing Javascript&lt;/dd&gt;&lt;/dl&gt;&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;A straightforward script tag include yields the best stacktrace information. As the asterisk(*) indicates, the dynamic script element, global eval, and data URL techniques can yield stacktraces with non-helpful line numbers. The data URL technique actually gives correct line numbers, it's just that all the newlines have been encoded and the entire source jammed onto a single line - so, I can't really say the line numbers are all that helpful. Strangly, Opera yields non-helpful line numbers even with the Javascript-inline-in-a-script tag technique.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;h2&gt;So That's it? No IE?&lt;/h2&gt;&lt;div&gt;There's no way to get stack information on IE, not unless you want to do the other thing, but you don't want to know about that.&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;What's that? You &lt;i&gt;do&lt;/i&gt; want to know? No you do not! Just forget I said anything.&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;Okay! I'll tell you, but you are going to regret it.&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;h3&gt;window.onerror&lt;br&gt;&lt;/h3&gt;&lt;div&gt;On IE - and as it happens on Firefox and Chrome as well - you can register an onerror handler on the window object, like so&lt;/div&gt;&lt;pre&gt;window.onerror = function(message, fileURL, lineNumber){&lt;/pre&gt;&lt;pre&gt;  log(message + ': ' + fileURL + ': ' + lineNumber)&lt;/pre&gt;&lt;pre&gt;}&lt;/pre&gt;&lt;div&gt;The handler will be called anytime a thrown exception is uncaught: propagates all the way to the bottom of the call stack with no catchers. Catching the exception will cause the handler not to be called, unless you rethrow it, but even then, there are other complications. When the handler is called, there is no error object, only the error message, file URL, and the line number.&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;h3&gt;Bad News: IE&lt;br&gt;&lt;/h3&gt;&lt;div&gt;Because of various IE bugs, the fileURL and line number passed into the &lt;i&gt;onerror&lt;/i&gt; handler isn't always accurate or helpful. After some research, I've isolated these bugs:&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;&lt;ul&gt;&lt;li&gt;In IE 7 and below, if an exception is thrown from within the code of an included script, &lt;i&gt;fileURL&lt;/i&gt;&amp;nbsp;will erroneously be set to the URL of the current HTML document even though the lineNumber will be set to the correct line number from within the script.&lt;/li&gt;&lt;li&gt;In IE 8 and below, if an exception is thrown using the throw statement, (i.e. &lt;i&gt;throw new Error()&lt;/i&gt; ) and is caught, and then re-thrown, and then propagates all the way up, the line number reported will be the the place it was re-thrown, rather than the place it was first thrown. This bug does not surface when the error is triggered otherwise, such as with type and reference errors.&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;IE 9 has both of these bugs fixed, even when it emulates older versions of the browser.&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;h2&gt;What Can You Throw&lt;/h2&gt;&lt;div&gt;The "throw" statement lets you throw just about any old value - even numbers and strings! But this is not recommended as you won't be able to get any line numbers or stacktraces if the value thrown isn't an object - except for in IE, where you &lt;i&gt;can&lt;/i&gt; get line numbers using &lt;i&gt;onerror&lt;/i&gt;. In IE, throwing anything other than a pre-defined error object(Error, TypeError, etc) will result in the loss of a meaningful message in both the caught error object and in the &lt;i&gt;onerror&lt;/i&gt; handler - where it will just say "Exception thrown and not caught".&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;So, the simplest recommendation here is to only throw the pre-defined &lt;i&gt;Error&lt;/i&gt; object when you want to explicitly throw an error using the "throw" statement.&lt;/div&gt;&lt;pre&gt;throw new Error('Buck stops here.')&lt;/pre&gt;&lt;div&gt;or better yet, don't use the throw statement at all(this avoids the second IE bug mentioned earlier).&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;h2&gt;The DIY Stacktrace&lt;/h2&gt;&lt;div&gt;The DIY stacktrace was pioneered by&amp;nbsp;&lt;a href="http://eriwen.com/javascript/js-stack-trace/"&gt;Eric Wendelin&lt;/a&gt;&amp;nbsp;among others. It first looks up argument.callee to get the current function being executed, then it walks the call stack by accessing the function's &lt;i&gt;caller&lt;/i&gt; attribute recursively. For example:&lt;/div&gt;&lt;pre&gt;&amp;gt; function f(){&lt;/pre&gt;&lt;pre&gt;    g()&lt;/pre&gt;&lt;pre&gt;  }&lt;/pre&gt;&lt;pre&gt;&amp;gt; function g(){&lt;/pre&gt;&lt;pre&gt;    h()&lt;/pre&gt;&lt;pre&gt;  }&lt;/pre&gt;&lt;pre&gt;&amp;gt; function h(){&lt;/pre&gt;&lt;pre&gt;    console.log(arguments.callee.caller.caller)&lt;/pre&gt;&lt;pre&gt;  }&lt;/pre&gt;&lt;pre&gt;&amp;gt; f()&lt;/pre&gt;&lt;pre&gt;function f(){&lt;/pre&gt;&lt;pre style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.2em; padding-right: 0.8em; padding-bottom: 0.2em; padding-left: 0.8em; font-family: monospace; font-size: 11px; background-color: rgb(238, 238, 238); "&gt;  g()&lt;/pre&gt;&lt;pre style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.2em; padding-right: 0.8em; padding-bottom: 0.2em; padding-left: 0.8em; font-family: monospace; font-size: 11px; background-color: rgb(238, 238, 238); "&gt;}&lt;/pre&gt;&lt;div&gt;In the example, we are able to access the function &lt;i&gt;f&lt;/i&gt; from with the body of &lt;i&gt;h&lt;/i&gt;'s execution by walking two levels up the call stack using the caller attribute.&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;h3&gt;Pros and Cons of the DIY Stacktrace&lt;br&gt;&lt;/h3&gt;&lt;div&gt;The advantage of the DIY stacktrace is that it will work in any browser.&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;The disadvantages are&lt;/div&gt;&lt;div&gt;&lt;ol&gt;&lt;li&gt;It will not get you file locations/line numbers.&lt;/li&gt;&lt;li&gt;It does not work with thrown errors - either implicitly or explicitly - because the building of the stacktrace needs to be explicited done as its own statement, say, &lt;i&gt;printStackTrace&lt;/i&gt;, for example. So, you cannot have a stacktrace &lt;i&gt;and&lt;/i&gt; an error thrown - &lt;i&gt;you cannot have your cake and eat it too&lt;/i&gt;.&lt;/li&gt;&lt;/ol&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;/div&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;div&gt;Sorry I don't have a better conclusion than: &lt;i&gt;It's a great big mess&lt;/i&gt;. However, with the knowledge covered here, I think it is possible to employ some sophisticated hackery to recover at least &lt;i&gt;some&lt;/i&gt; stacktrace info for each browser - the hardest case being IE. Such a technique - if made practical - would be useful for unit test frameworks and crash reporting.&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;h2&gt;References&lt;br&gt;&lt;/h2&gt;&lt;div&gt;&lt;ul&gt;&lt;li&gt;Eric Wendelin's&amp;nbsp;&lt;a href="http://eriwen.com/javascript/js-stack-trace/"&gt;Javascript Stacktrace&lt;/a&gt;&amp;nbsp;(&amp;nbsp;&lt;a href="https://github.com/eriwen/javascript-stacktrace"&gt;GitHub repo&lt;/a&gt;&amp;nbsp;)&lt;br&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://helephant.com/2007/05/12/diy-javascript-stack-trace/"&gt;DIY Stacktrace&lt;/a&gt;&amp;nbsp;-&amp;nbsp;Helen Emerson&lt;/li&gt;&lt;li&gt;&lt;a href="http://blog.yoursway.com/2009/07/3-painful-ways-to-obtain-stack-trace-in.html"&gt;3 painful ways to obtain a stacktrace&lt;/a&gt;&amp;nbsp;from Your Sway/CrashKit&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;</description>
      <pubDate>Wed, 08 Jun 2011 21:44:11 +0000</pubDate>
      <guid>http://wiki.futuretoby.com/The_Javascript_Stacktrace_Blog_Post</guid>
      <author>toby ho</author>
      <link>http://wiki.futuretoby.com/The_Javascript_Stacktrace_Blog_Post</link>
    </item>
    <item>
      <title>Try Traceur</title>
      <description>I screwed around with&amp;nbsp;&lt;a href="http://code.google.com/p/traceur-compiler/"&gt;Traceur&lt;/a&gt;&amp;nbsp;last night and this morning. Then I built this thing called&amp;nbsp;&lt;a href="http://trytraceur.tobyho.com/"&gt;Try Traceur&lt;/a&gt;&amp;nbsp;to make it easy for folk to screw around with it too. Try it! You know you want to.</description>
      <pubDate>Thu, 19 May 2011 15:12:51 +0000</pubDate>
      <guid>http://wiki.futuretoby.com/Try_Traceur</guid>
      <author>toby ho</author>
      <link>http://wiki.futuretoby.com/Try_Traceur</link>
    </item>
    <item>
      <title>JSConf Summary and My Codez</title>
      <description>JSConf 2011 Portland was truly amazing experience for me, personally. Not only did I meet some fantastic people in the community - some of whom I've long wanted to meet, I also got to show off&amp;nbsp;&lt;a href="http://tuttijs.com/"&gt;my stuff&lt;/a&gt;, and it didn't totally suck. Also, add to that, Portland is a fantastic city! I want to thank Chris Williams again for motivating me, and everybody involved for such a great event!&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;My talk was on&amp;nbsp;&lt;a href="http://tuttijs.com/"&gt;Tutti&lt;/a&gt;&amp;nbsp;and most of its time was occupied by demos, so rather than posting the slides I thought I would just post the&amp;nbsp;&lt;a href="https://github.com/airportyh/Tutti-JSConf-Code-Examples"&gt;example code&lt;/a&gt;&amp;nbsp;for the demos. I hope this is helpful to people!&lt;/div&gt;</description>
      <pubDate>Fri, 06 May 2011 22:25:03 +0000</pubDate>
      <guid>http://wiki.futuretoby.com/JSConf_Summary_and_My_Codez</guid>
      <author>toby ho</author>
      <link>http://wiki.futuretoby.com/JSConf_Summary_and_My_Codez</link>
    </item>
    <item>
      <title>Indent Your Code the Way You Want with Indentinator</title>
      <description>&lt;p&gt;Indentinator is a script that inspects and changes the indentation in
your source code. It is language-agnostic.&amp;nbsp;&lt;i&gt;"Indent your code the way you want."&lt;/i&gt;&lt;/p&gt;

&lt;h2&gt;Install&lt;/h2&gt;

&lt;p&gt;Assuming you have ruby and rubygem installed, you can&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;gem install Indentinator
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;to install it.&lt;/p&gt;

&lt;h2&gt;Usage &lt;/h2&gt;

&lt;pre&gt;&lt;code&gt;indentinator [-c INDENT_AMOUNT] &amp;lt;file&amp;gt; [&amp;lt;file2&amp;gt;...]
&lt;/code&gt;&lt;/pre&gt;

&lt;h2&gt;Examples&lt;br&gt;&lt;/h2&gt;

&lt;p&gt;Using &lt;code&gt;indentinator&lt;/code&gt; with a file argument will tell you what amount of indentation the file uses.&lt;/p&gt;

&lt;pre id="scroll_to_here"&gt;&lt;code&gt;$ indentinator lib/myapp.rb 
lib/myapp.rb uses 2 spaces.
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Using with the &lt;code&gt;-c&lt;/code&gt; option will convert the file to the desired indentation amount, and print the result to &lt;code&gt;stdout&lt;/code&gt;.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ indentinator -c 4 lib/myapp.rb
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The &lt;code&gt;-r&lt;/code&gt; option will overwrite the original file with the output.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ indentinator -rc 4 lib/myapp.rb
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Make sure you have the file backed up or source controlled first! I am not
responsible for any damages.&lt;/p&gt;

&lt;p&gt;If you want to read the input from &lt;code&gt;stdin&lt;/code&gt;, use the -i option&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ cat lib/myapp.rb | indentinator -ic 4
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;If you use a mixture of indentation sizes in your source file, indentinator may guess wrong, which will in turn affect the conversion output. To tell it
explicitly the original indentation amount for it to use during the conversion 
process use the &lt;code&gt;-a&lt;/code&gt; option&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ indentinator -a 4 -c lib/myapp.rb
&lt;/code&gt;&lt;/pre&gt;

&lt;h2&gt;Totally Use it Inside TextMate and Stuff&lt;/h2&gt;

&lt;p&gt;If you copied a snippet of code from the internets, and it uses a different
indentation then you, it will be helpful to use indentinator from within TextMate. To do this, follow these steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Go to &lt;code&gt;TextMate-&amp;gt;Preferences...-&amp;gt;Advanced-&amp;gt;Shell Variables&lt;/code&gt;, and make sure
the &lt;code&gt;PATH&lt;/code&gt; variable contains the location of the &lt;code&gt;indentinator&lt;/code&gt; executable.&lt;/li&gt;
&lt;li&gt;Paste the code snippet into TextMate, select that snippet and hit Command-Option-R. &lt;/li&gt;
&lt;li&gt;In the &lt;code&gt;Command:&lt;/code&gt; text field type in the indentinator command to use, for
example &lt;code&gt;indentinator -ic 2&lt;/code&gt;, which will take the selected text as input
(from &lt;code&gt;stdin&lt;/code&gt;) and output it with an indentation of 2 spaces.&lt;/li&gt;
&lt;li&gt;Click &lt;code&gt;Execute&lt;/code&gt;.&lt;/li&gt;&lt;/ol&gt;&lt;h2&gt;Codez&lt;/h2&gt;&lt;div&gt;&lt;a href="https://github.com/airportyh/Indentinator"&gt;Source code for Indentinator&lt;/a&gt;&amp;nbsp;is distributed on GitHub.&amp;nbsp;&lt;a href="https://github.com/airportyh/Indentinator/issues"&gt;Submit me an issue&lt;/a&gt;&amp;nbsp;if you have one, thanks ;)&lt;/div&gt;&lt;ul&gt;
&lt;/ul&gt;</description>
      <pubDate>Sat, 26 Mar 2011 22:58:15 +0000</pubDate>
      <guid>http://wiki.futuretoby.com/Indent_Your_Code_the_Way_You_Want_with_Indentinator</guid>
      <author>toby ho</author>
      <link>http://wiki.futuretoby.com/Indent_Your_Code_the_Way_You_Want_with_Indentinator</link>
    </item>
    <item>
      <title>String Difference in Ruby</title>
      <description>&lt;pre&gt;class String&lt;br&gt;&lt;/pre&gt;&lt;pre&gt;  def -(other)
    self.index(other) == 0 ? self[other.size..self.size] : nil
  end
end&lt;br&gt;&lt;/pre&gt;&lt;div&gt;This snippet gives the Ruby &lt;i&gt;String&lt;/i&gt; class a minus operator. Which works like&lt;/div&gt;&lt;pre&gt;&amp;gt; 'abcde' - 'abc'&lt;/pre&gt;&lt;pre&gt;=&amp;gt; "de"&lt;/pre&gt;&lt;pre&gt;&amp;gt; '    ' - '  '
=&amp;gt; "  "
&lt;/pre&gt;&lt;pre&gt;&amp;gt; 'abc' - 'de'
=&amp;gt; nil
&lt;/pre&gt;&lt;div&gt;Meh.&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;</description>
      <pubDate>Fri, 25 Mar 2011 23:28:53 +0000</pubDate>
      <guid>http://wiki.futuretoby.com/String_Difference_in_Ruby</guid>
      <author>toby ho</author>
      <link>http://wiki.futuretoby.com/String_Difference_in_Ruby</link>
    </item>
    <item>
      <title>Smart Parameter Checks in Python</title>
      <description>While I really enjoy using Michael Foord's&amp;nbsp;&lt;a href="http://www.voidspace.org.uk/python/mock/"&gt;Mock library&lt;/a&gt;, there is one thing missing and I thought would be a fun project to add - which is the subject of this post.&lt;h2&gt;Fun with Parameters&lt;/h2&gt;&lt;div&gt;Python has the most sophisticated function parameter calling mechanics I've ever seen. Given a function f&lt;/div&gt;&lt;div&gt;&lt;pre style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.2em; padding-right: 0.8em; padding-bottom: 0.2em; padding-left: 0.8em; font-family: monospace; font-size: 11px; background-color: rgb(238, 238, 238); "&gt;def f(a, b):&lt;/pre&gt;&lt;pre style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.2em; padding-right: 0.8em; padding-bottom: 0.2em; padding-left: 0.8em; font-family: monospace; font-size: 11px; background-color: rgb(238, 238, 238); "&gt;    return a + b&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;You can either call it like normal(positional parameters)&lt;/div&gt;&lt;pre&gt;f(1, 2)&lt;/pre&gt;&lt;div&gt;or by keyword parameter&lt;/div&gt;&lt;pre&gt;f(a=1, b=2)&lt;/pre&gt;&lt;div&gt;With keyword parameters, the position doesn't matter anymore, so the above call is equivalent to&lt;/div&gt;&lt;pre&gt;f(b=2, a=1)&lt;/pre&gt;&lt;div&gt;You can even mix positional and keyword parameters, as long as you put all the positionals first&lt;/div&gt;&lt;pre&gt;f(1, b=2)&lt;/pre&gt;&lt;div&gt;So, all the ways I've listed of calling the function f with the parameter a as 1 and b as 2 will have the same functional behavior, given what we know of the signature of the function. So, it would be logical that the mock library would consider&lt;/div&gt;&lt;pre&gt;f.assert_called_with(a=1, b=2)&lt;/pre&gt;&lt;div&gt;a passing assertion even though&amp;nbsp;in reality it was called as&lt;/div&gt;&lt;pre&gt;f(1, 2)&lt;/pre&gt;&lt;div&gt;but alas, it does not.&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;With that, it was my mission to make this happen!&lt;/div&gt;&lt;h2&gt;Proof-of-Concept&lt;/h2&gt;&lt;div&gt;First I created a prototype/proof-of-concept. See&amp;nbsp;&lt;a href="https://github.com/airportyh/smart_param_check.py"&gt;code here&lt;/a&gt;. Using&lt;/div&gt;&lt;pre&gt;&lt;font class="Apple-style-span" face="'Bitstream Vera Sans Mono', Courier, monospace" size="2"&gt;&lt;span class="Apple-style-span" style="line-height: 16px; word-spacing: 0px;"&gt;&lt;span class="Apple-style-span" style="font-size: 12px; line-height: 17px; "&gt;&lt;span class="n" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; "&gt;inspect&lt;/span&gt;&lt;span class="o" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; font-weight: bold; "&gt;.&lt;/span&gt;&lt;span class="n" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; "&gt;getargspec&lt;/span&gt;&lt;span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; "&gt;(&lt;/span&gt;&lt;span class="bp" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(153, 153, 153); "&gt;self&lt;/span&gt;&lt;span class="o" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; font-weight: bold; "&gt;.&lt;/span&gt;&lt;span class="n" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; "&gt;func&lt;/span&gt;&lt;span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; "&gt;)&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;/span&gt;&lt;/font&gt;&lt;/pre&gt;&lt;div&gt;I was able to get all the info about the signature of a function I needed. When a function call actually comes in, my callable receives them as&lt;/div&gt;&lt;pre&gt;&lt;span class="Apple-style-span" style="font-family: 'Bitstream Vera Sans Mono', Courier, monospace; font-size: 12px; line-height: 17px; word-spacing: 0px; "&gt;&lt;span class="k" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; font-weight: bold; "&gt;def&lt;/span&gt; &lt;span class="nf" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(153, 0, 0); font-weight: bold; "&gt;__call__&lt;/span&gt;&lt;span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; "&gt;(&lt;/span&gt;&lt;span class="bp" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(153, 153, 153); "&gt;self&lt;/span&gt;&lt;span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; "&gt;,&lt;/span&gt; &lt;span class="o" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; font-weight: bold; "&gt;*&lt;/span&gt;&lt;span class="n" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; "&gt;args&lt;/span&gt;&lt;span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; "&gt;,&lt;/span&gt; &lt;span class="o" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; font-weight: bold; "&gt;**&lt;/span&gt;&lt;span class="n" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; "&gt;kwds&lt;/span&gt;&lt;span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; "&gt;):&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;/pre&gt;&lt;div&gt;at which point, I resolve all the parameters with the parameter list in the function signature(I called this "combining" the args)&lt;/div&gt;&lt;div&gt;&lt;ol&gt;&lt;li&gt;First, by walking the actual positionals (the &lt;i&gt;args&lt;/i&gt; array coming in) and cross referencing them with the ones in the function signature. After this is done, we basically converted the positionals into named form - as a dict.&lt;/li&gt;&lt;li&gt;Then merge everything in &lt;i&gt;kwds&lt;/i&gt;&amp;nbsp;into the same dict. So we have one unified dict with all the actually parameters and keyed by parameter name.&lt;/li&gt;&lt;li&gt;If there are any left over from the variable position args, they are stored in an &lt;i&gt;extras&lt;/i&gt;&amp;nbsp;list.&lt;/li&gt;&lt;/ol&gt;&lt;div&gt;Now, with this information handy, we can actually do our own safe parameter checking, and we should! So when a call is made, I also check if all the required params have been provided, whether there are any unexpected params and so forth, and actually raise some TypeErrors like a real function if need be.&lt;/div&gt;&lt;/div&gt;&lt;div&gt;But the better part is what comes next - we can now implement the &lt;i&gt;assert_called_with&lt;/i&gt; with these new semantics. When a call to &lt;i&gt;assert_called_with&lt;/i&gt; is called, I "combine" the args coming into that call, and check if they match the previously made function call. It's that simple!&lt;/div&gt;&lt;h2&gt;Working in Python-Mock&lt;/h2&gt;&lt;div&gt;Well great. But we still can't use for the Mock library. So I did some more hacking on a&amp;nbsp;&lt;a href="http://code.google.com/r/airportyh-python-mock/source/browse/?r=smart-param-check"&gt;branch of Foord's code&lt;/a&gt;. Not sure it's the cleanest code, but it now works if you want to try it out&lt;/div&gt;&lt;pre&gt;&lt;span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; line-height: normal; white-space: normal; word-spacing: 0px; "&gt;&lt;tt id="checkoutcmd" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Lucida Console', monospace; font-size: 12px; "&gt;hg clone https://airportyh-python-mock.googlecode.com/hg/ airportyh-python-mock&lt;/tt&gt;&amp;nbsp;&lt;/span&gt;&lt;br&gt;&lt;/pre&gt;&lt;div&gt;The way you use it with the Mock library is through &lt;i&gt;mocksignature&lt;/i&gt;.&amp;nbsp;&lt;/div&gt;&lt;pre&gt;from mock import mocksignature&lt;/pre&gt;&lt;div&gt;&lt;i&gt;mocksignature&lt;/i&gt;&amp;nbsp;wraps a function that you pass it and uses the signature of that function as a guide. Given the function &lt;i&gt;f&lt;/i&gt;&amp;nbsp;that we had previously, you can do&lt;/div&gt;&lt;pre&gt;f = mocksignature(f)&lt;/pre&gt;&lt;div&gt;now call it&lt;/div&gt;&lt;pre&gt;f(1, 2)&lt;/pre&gt;&lt;div&gt;and then checking the associated mock with a different call style&lt;/div&gt;&lt;pre&gt;f.mock.assert_called_with(a=1, b=2)&lt;/pre&gt;&lt;div&gt;should now pass.&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;Cheers!&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;</description>
      <pubDate>Thu, 24 Mar 2011 22:27:29 +0000</pubDate>
      <guid>http://wiki.futuretoby.com/Smart_Parameter_Checks_in_Python</guid>
      <author>toby ho</author>
      <link>http://wiki.futuretoby.com/Smart_Parameter_Checks_in_Python</link>
    </item>
    <item>
      <title>Tuttiterm - Tutti for your Terminal</title>
      <description>I've created&amp;nbsp;&lt;a href="https://github.com/airportyh/tuttiterm"&gt;Tuttiterm&lt;/a&gt;&amp;nbsp;- which allows you to control browsers via&amp;nbsp;&lt;a href="http://tutti.tobyho.com"&gt;Tutti&lt;/a&gt;. See the project&amp;nbsp;&lt;a href="https://github.com/airportyh/tuttiterm"&gt;README&lt;/a&gt;. Here's a screenshot:&lt;div&gt;&lt;span class="Apple-style-span" style="border-collapse: collapse;"&gt;&lt;img title="Screenshot" alt="Screenshot" src="https://lh3.googleusercontent.com/_1m4jxPGXQAo/TXUF6UN4C4I/AAAAAAAARlk/Z2koe-4Nn-A/s800/Screen%20shot%202011-03-07%20at%2010.05.08%20AM.jpg"&gt;&lt;br&gt;&lt;/span&gt;&lt;/div&gt;</description>
      <pubDate>Fri, 04 Mar 2011 07:23:16 +0000</pubDate>
      <guid>http://wiki.futuretoby.com/Tuttiterm_-_Tutti_for_your_Terminal</guid>
      <author>toby ho</author>
      <link>http://wiki.futuretoby.com/Tuttiterm_-_Tutti_for_your_Terminal</link>
    </item>
  </channel>
</rss>
